Explain term Literals in java?
Literals are pieces of Java source code which mean exactly what they say. For example "Hello World!" is a String literal and its meaning is the words Hello World!
The string "Hello World!" looks like it's various things; but to the compiler it's only one thing, a String. This is same to how an expression such as 1,987,234 may be seven digits and two commas but is actually just one number.
The double quote marks tell you this is a string literal. A string is an prearranged collection of characters (letters, digits, punctuation marks, etc.). While the String might have meaning to a human being reading the code, the computer sees it as no more than a particular set of letters in a particular order. It has no concept of the meaning of the characters. For example it does not know that "two" + "two" is "four." Actuallythe computer thinks in which "two" + "two" is "twotwo"
The quote marks display where the string starts and ends. Therefore the quote marks themselves are not a elements of the string. The value of this string is Hello World!, not "Hello World!" You can modify the output of the program through changing Hello World to a few other line of text.
A string in a Java program has no concept of italics, bold face, font family or other formatting. It cares just about the characters in which compose it. Even if you're using an editor such as NisusWriter that lets you format text files, "Hello World!" is identical to "Hello World!" as far as Java is concerned.
char literals are same to string literals except they're enclosed in single quotes and must have precisely one character. For example 'c' is a char literal which means the letter c.
true and false are boolean literals which mean true and false.
Numbers can also be literals. 34 is an int literal and it means the number thirty-four. 1.5 is a double literal. 45.6, 76.4E8 (76.4 times 10 to the 8th power) and -32.0 are also double literals.
34L is a long literal and it means the number thirty-four. 1.5F is a float literal. 45.6f, 76.4E8F and -32.0F are also float literals.