Like Us On Facebook

Total Pageviews

195. Java Literals

Java Literals are Numeric, Boolean, Character and String representation of data.

Example of a Numeric Literal
int var = 5;
Here the value 5 is the Numeric literal.

Example of Boolean Literals
boolean var1 = true, var2 = false;
Here the values true & false are the Boolean literals.

Example of Character Literals  –
char var1 = ‘c’, var2 =’$’, var3=’5’;
Here the values ‘c’, ‘$’, ‘5’ including single quotes are the Character Literals.

Example of a String Literal
String var = “Sample Text”;
Here the value “Sample Text” including the double quotes is the String Literal.

Now you have got the basic understanding of what is a Java Literal. It’s nothing but the syntactical representation of data in Java. For example, integer value is represented as 5 whereas character is represented as ‘$’.  So there is a variation in how we represent different types of data in Java and we call their representation as Literals in Java.

As I have explained above that there are three categories in Java Literal –

1. Numeric
2. Boolean
3. String

Character literal is a part of Numeric category.

To start with, I will explain Numeric Literals concept in the next post.

Please comment below to feedback or ask questions.

Numeric Literals will be explained in the next post.

No comments:

Blog Index