String s1 = new String("Java");
String s2 = new String("Java");
It will create 2 objects in heap.
String s1 = new String("Java");
String s2 = new String("Ruby");
This will create 2 objects in heap.
String s1 = new String("Java");
String s2 = "Java";
This will create one object in heap for first line.
For second line, it will check whether "Java" exists in string pool or not.If exists, it wont create a new string.It will return the reference to already existing string in pool
String s1 = "Java";
String s2 = "Java";
First line will check whether "Java" exists in string pool or not.If exists, it wont create a new string.It will return the reference to already existing string in pool.
Second line will get the reference to already created string.So no new objects if "Java" exists or maximum one object