Your first part of code:
2 objects are created.
If "Java" is not present in String Pool, a string is created and added there.
Your 2nd part of code:
2 objects are created and if neither "Java" nor "Ruby" are present in String Pool, both strings are created and added to it.
Your 3rd part of code:
one object created. and same condition is executed to add to String Pool.
Your 4th part of code:
Only one object created, if "Java" not present in String Pool. else no new object created.