A literal represent a value that is stored into a variable directly in the program. In an expression the right hand side data is called literal which are stored in variable. When data type changes the literal value will be changed.
For example, the expression int a=10; will store literal value "10" in variable "a". Depending upon the data types java supports five types of literals they are list below
- Integer literal
- Floating literal
- Character literal
- String literal
- Boolean literal
1. Integer literal
- These literals represents fixed integer values
- All these numbers belongs to decimal number system which uses 10 digits
- Example: int a=10;
2. Floating literal
- These literals represents fractional numbers
- These are the numbers with decimal points
- While writing these literals, we can use E or e for scientific notation.
- Example: float f=1250.4f;
3. Character literal
- These literal include characters, special characters, Unicode characters, and escape sequences
- These literals should be enclosed in single quotation marks.
- Example: char ch='A';
4. String literal
- String literal represents objects of string class
- All String literals can be directly stored in a string object
5. Boolean literal
- Boolean literals represents only two value - True and False
- It means we can store either true or false into Boolean type variable
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.