• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is literal in Java?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know What are literals in Java?
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html


I read this document but do not understand.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Literals are exactly what they say.

String bike;

Bike is not a literal, it's a variable.

String x = "bike";

"Bike" is a literal. It is exactly what it says.

Int x = 1;

1 is a literal.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Literal meaning you read the actual value. If you can read the value of a number as 123 because 213 is written there, that is a literal. If you can read the value of a String because "Kishor Joshi" has been written there, that is a literal.

Note there are three pre‑defined literals in Java®: true false null.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!