• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

primitives, literals

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can somebody plz tell me the difference between primitives and literals
thank u
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,I think i can understand ur confusion. U have got them in the wrong context. U shouldn't be comparing primitives and literals. Primitives are the fundamental datatypes that are used to hold data in programs along with object(reference) datatypes ok? Together we can call them variables. Now a Literal "is used to assign values to variables". This variable maybe "a primitive" eg int i = 5; or "a reference" eg Integer i = new Integer("5"); type. In both cases 5 is a literal. In the first case we have a primitive i whose value is 5 and in the second case we a wrapper i whose value again is 5. A bit clearer??
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two kinds of types in the Java programming language: primitive types (�4.2) and reference types (�4.3).
There are, correspondingly, two kinds of data values that can be stored in variables, passed as arguments, returned by methods, and operated on: primitive values (�4.2) and reference values (�4.3).
The primitive types are boolean, byte, short, int, long, char, float, double.
The reference types are class types, interface types and array types. Variables of these types can refer to objects of the corresponding type.
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).
Each type has literals, which are the way that constant values of that type are written.
Examples of primitive literals are true, false, 'm', '\n', 10, -10, 0xff, 077, 10L, 1.23E4. This is a literal of reference type, "abc" and this is a literal of null type, null.
(credits: JLS and The Java Programming Language)
[ October 08, 2003: Message edited by: Marlene Miller ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLS uses �primitive� as an adjective � a primitive type or a primitive data value (as defined above). Some people use �primitive� as a noun. Used as a noun, �primitive� means a value of a primitive type.
So, comparing primitives and literals, a primitive is a value (of a variable or the result of an expression)(of type boolean, byte, short, char, int, long, float or double) and a literal is the source code representation of a value (of primitive type or reference type).
 
satish balantrapu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u very much
i now hav a very clear idea.
reply
    Bookmark Topic Watch Topic
  • New Topic