my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on literal!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on literal!!" Watch "Doubt on literal!!" New topic
Author

Doubt on literal!!

dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Please can anybody explain me what is difference between object and literal....
for suppose String s="ok";
now here s is a string literal and we can even call methods of class String using s(.dot) operator but,when we declare
String s=new String()

here i think s is object.......so what is actualy a literal?
i have also heard integer literal and all others........please if anyone could explain me it will be helpful to me.thanks in advance..
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi Dhwani,
Refer this link.


Regards
Nik
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

According to JLS - 3.10 Literals, "A literal is the source code representation of a value of a primitive type (�4.2), the String type (�4.3.3), or the null type (�4.1)..."

Basically, when you specify a specific value in your code for these types, that is a literal. Using your example of String s = "ok"; the "ok" is a String literal. The variable 's' is assigned a reference to a String object representing that literal.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Thanks you Nik and marc.
 
 
subject: Doubt on literal!!
 
Similar Threads
Difference between String s = "Marcus"; vs String s2 = new String("Marcus");
Garbage collection & string literal pool
this will make you think
What the output related to string
what is string an object or literal ?