Java Interview Questions
1 .
Is String a class or data type?
String is a class in java.lang package. But in Java, all classes are also considered as data types. So we can take String as a data type also. 
2 .
Can we call a class as a data type?
Yes, a class is also called ‘user-defined’ data type. This is because a user can create a class.
3 .
How many objects will be created in the following code?
                        String s = new String("Welcome");
Two objects, one in string constant pool and other in non-pool(heap).
4 .
What is the purpose of toString() method in java ?
The toString() method returns the string representation of any object. If you print any object, java compiler internally invokes the toString() method on the object. 

So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.
5 .
Can we use string for switch statement?
Yes to version 7. From JDK 7, we can use string as switch condition. Before version 6, we can not use string as switch condition.

   switch (str.toLowerCase()) // java 7 only!
      case "a":value = 1;
      case "b":value = 2;
6 .
What is a string constant pool?
String constant pool is a separate block of memory where the string objects are held by JVM. If a string object is created directly, using assignment operator as: 
String s1= “Hello”, then it is stored in string constant pool.
7 .
What is the difference between == and equals() while comparing strings? Which one is reliable?
== operator compares the references of the String objects. It doesn’t compare the contents of the objects. equals() method compares the contents. While comparing the strings, equals() method should be used as it yields the correct results.
8 .
What is the meaning of immutable in terms of String?
The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can't be changed.
9 .
Explain the difference between following : statement String s=”World”; String s=new String (“world”);
In First Statement assignment operator is used to assign the string .In this case Jvm first check the String pool whether the same vale already available in the String container or not and notify if available, if it is not available then it create another reference to it.
In Second case each and every time it creates a new object of string.
10 .
There are any other classes in java that is immutable?
All the wapper classes in java are immutable like. Integer, Flot.Double, etc