String Object String Literal Java

2,566 views · Published 8 February 2014 · 4:00 · Indexed 30 September 2026

Channel: Interview DOT · 2014 · Science & Technology

Watch on YouTube

Click here - https://www.youtube.com/channel/UCd0U_xlQxdZynq09knDszXA?sub_confirmation=1 to get notifications. String Object String Literal Java

A Job Portal
http://www.InterviewDot.com http://www.InterviewDot.com http://www.InterviewDot.com
One Click Dream Job - http://www.interviewdot.com/upload-resume/uploadresume.htm

Are you looking for a new Job ?
InterviewDot.com - A Job Portal
http://www.InterviewDot.com http://www.InterviewDot.com http://www.InterviewDot.com
One Click Dream Job - http://www.interviewdot.com/upload-resume/uploadresume.htm

  Difference between "String Literal" and "String Object" in Java ? 
    /STRING LITERAL
    //-------------
    //When you use a string literal the string can be "interned" but when you use new String
    //you get a new string object.
    //STRING OBJECTS
    //--------------
    //Here two different objects are created and they have different references:
    //A String object is an individual instance of the java.lang.String class.

    //In general you should use the string literal notation when possible.
    //It is easier to read and it gives the compiler a chance to optimize your code.
    
    
    //s1Str will refer to an interned String object. This means, 
    //that the character sequence "abcde" will be stored at a central place and whenever the same literal "abcde" is used again, 
    //the JVM will not create a new String object but use the reference of the 'cached' String.

    //s2Str is guranteed to be a new String object,

String Object String Literal Java

More from this channel