Vikyath Ram has Published 138 Articles

Factory method to create Immutable Map in Java SE 9

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:01:01

213 Views

With Java 9, new factory methods are added to Map interface to create immutable instances. These factory methods are convenience factory methods to create a collection in less verbose and in concise way.Old way to create collectionsExampleimport java.util.Collections; import java.util.HashMap; import java.util.Map; public class Tester {    public static ... Read More

Externalizable Interface in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 13:49:30

1K+ Views

Externalization is used whenever we need to customize serialization mechanism. If a class implements an Externalizable interface then, object serialization will be done using writeExternal() method. Whereas at receiver's end when an Externalizable object is a reconstructed instance will be created using no argument constructor and then the readExternal() method ... Read More

Download webpage in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 13:16:19

3K+ Views

We can download a web page using its URL in Java. Following are the steps needed.Create URL object using url string.Download webpage in JavaCreate a BufferReader object using url.openStream() method.BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));Create a BufferWriter object to write to a file.BufferedWriter writer = new BufferedWriter(new FileWriter("page.html"));Read each line ... Read More

Difference between super() and this() in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 12:42:48

7K+ Views

Following are the notable differences between super() and this() methods in Java. super()this()Definitionsuper() - refers immediate parent class instance.this() - refers current class instance.InvokeCan be used to invoke immediate parent class method.Can be used to invoke current class method.Constructorsuper() acts as immediate parent class constructor and should be first line in ... Read More

Difference between ArrayList and CopyOnWriteArrayList in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 12:23:44

3K+ Views

Following are the notable differences between ArrayList and CopyOnWriteArrayList classes in Java. ArrayListCopyOnWriteArrayListSynchronizedArrayList is not synchronized.CopyOnWriteArrayList is synchronized.Thread SafeArrayList is not thread safe.CopyOnWriteArrayList is thread safe.Iterator typeArrayList iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.CopyOnWriteArrayList is fail-safe and it will never throw ConcurrentModificationException during iteration. The ... Read More

What kind of string comparison, case-sensitive or not, can be performed by MySQL?

Vikyath Ram

Vikyath Ram

Updated on 20-Jun-2020 13:46:14

238 Views

MySQL cannot perform a case-sensitive comparison when comparing characters. It can be illustrated with the following example from table ‘Employee’ having the following data −mysql> Select * from Employee; +----+--------+--------+ | ID | Name   | Salary | +----+--------+--------+ | 1  | Gaurav | 50000  | | 2  | Rahul ... Read More

How Can MySQL operator precedence affect result set?

Vikyath Ram

Vikyath Ram

Updated on 20-Jun-2020 13:05:49

243 Views

MySQL follows operator precedence and it has the following list of operators, having the same precedence which is on the same line −INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + & | =, , >=, >,

How can we generate the same sequence of random numbers in MySQL?

Vikyath Ram

Vikyath Ram

Updated on 20-Jun-2020 13:01:46

255 Views

When invoked with an integer argument, RAND( ) uses that value to seed the random number generator. Each time you seed the generator with a given value, RAND( ) will produce the same sequence of random numbers. Following example will demonstrate it −Examplemysql> Select RAND(1), RAND(1), Rand(1); +---------------------+---------------------+---------------------+ | RAND(1) ... Read More

What MySQL returns if the search string, provided in FIELD() function, is NULL?

Vikyath Ram

Vikyath Ram

Updated on 20-Jun-2020 08:42:50

136 Views

As we know that NULL fails equality comparison with any value hence if the search string, provided in FIELD() function, is NULL then MySQL returns 0 as output.Examplemysql> Select FIELD(NULL,'Ram','is','good','boy'); +-------------------------------------+ | FIELD(NULL,'Ram','is','good','boy') | +-------------------------------------+ |                                   0 | +-------------------------------------+ 1 row in set (0.00 sec)

How can we get all the unique rows in MySQL result set?

Vikyath Ram

Vikyath Ram

Updated on 20-Jun-2020 07:09:52

260 Views

With the help of DISTINCT keyword in SELECT statement, we can get the unique rows in MySQL result set.Examplemysql> Select * from names; +------+-----------+ | id   | name      | +------+-----------+ | 1    | Rahul     | | 2    | Gaurav    | | ... Read More

Previous 1 ... 3 4 5 6 7 ... 14 Next
Advertisements