Vikyath Ram has Published 95 Articles

Factory method to create Immutable Map in Java SE 9

Vikyath Ram

Vikyath Ram

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

248 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

Difference between super() and this() in Java

Vikyath Ram

Vikyath Ram

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

8K+ 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

4K+ 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

How Can MySQL operator precedence affect result set?

Vikyath Ram

Vikyath Ram

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

290 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

298 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

158 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 emulate CHECK CONSTRAINT by using views?

Vikyath Ram

Vikyath Ram

Updated on 19-Jun-2020 13:39:38

147 Views

As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car1’ which can have the fix ... Read More

How can we apply the PRIMARY KEY constraint to the field of an existing MySQL table?

Vikyath Ram

Vikyath Ram

Updated on 19-Jun-2020 11:52:38

447 Views

We can apply the PRIMARY KEY constraint to a column of an existing MySQL table with the help of ALTER TABLE statement. SyntaxALTER TABLE table_name MODIFY colum_name datatype PRIMARY KEY;                  OR ALTER TABLE table_name ADD PRIMARY KEY (colum_name); Suppose we have the following table ... Read More

Factorial program in Java without using recursion.

Vikyath Ram

Vikyath Ram

Updated on 18-Jun-2020 08:09:48

2K+ Views

Following is the required program.ExampleLive Demopublic class Tester {    static int factorial(int n) {       if (n == 0)          return 1;       else          return (n * factorial(n - 1));    }    public static void main(String args[]) {       int i, fact = 1;       int number = 5;       fact = factorial(number);       System.out.println(number + "! = " + fact);    } }Output5! = 120

Advertisements