Posts

Showing posts from March, 2013

String literal pool & Creating the String object Using new()

What is String literal pool? How to create a String There are two ways to create a String object in Java: Using the  new  operator. For example,  String str = new String("Hello"); . Using a  string literal  or  constant expression) . For example, String str="Hello";  (string literal) or String str="Hel" + "lo";  (string constant expression). What is difference between these String's creations? In Java, the  equals  method can be considered to perform a deep comparison of the value of an object, whereas the  ==  operator performs a shallow comparison. The  equals  method compares the content of two objects rather than two objects' references. The  ==  operator with reference types (i.e., Objects) evaluates as  true  if the references are identical - point to the same object. With value types (i.e., primitives) it evaluates as  true  if the value is identical. The  equals  method is to return true  if two objects have identical