Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primitive

 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the differencew between a primitive and a literal?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sumaraghavi,

"primitives" in Java are usually the built-in primitive data types like short, int, long etc.

The term "literal" normally denotes only string literals like "hello".

Marco
 
Ronald Schild
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primitives are the non-object types:

boolean
byte
char
short
int
long
float
double

Literals are hard values, like:

1
'b'
252.234f
15124321L
0x25A
"Hello world!"
false
-18


There are literals for all primitives, do you know which?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sumaraghavi ragha:
what is the difference between a primitive and a literal?


One can't really say what "the difference" is, because they are not closely-enough related concepts. It's like asking what's the difference between a bus and a dog.

The word "primitive" applies to the subset of Java data types that don't involve objects. This is a concept specific to the Java language.

The word "literal" means a piece of data, such as a number or a text string, that is fixed and hard-coded into your program source code. The word "literal" has about the same meaning in most programming languages.
[ June 11, 2008: Message edited by: Peter Chase ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic