File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes primitives, literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "primitives, literals" Watch "primitives, literals" New topic
Author

primitives, literals

satish balantrapu
Greenhorn

Joined: Sep 30, 2003
Posts: 4
can somebody plz tell me the difference between primitives and literals
thank u
Layi Egbeyemi
Greenhorn

Joined: Oct 08, 2003
Posts: 9
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??
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Sep 30, 2003
Posts: 4
thank u very much
i now hav a very clear idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitives, literals