• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Doubt on literal!!

 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dhwani,
Refer this link.


Regards
Nik
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you Nik and marc.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic