Lest's Start JAVA Programming
Part 4
JAVA Literals
What are the things we write in source code call JAVA literals. There are different literals we use in JAVA.
- Integer Literals.
- Floating Literals.
- Character Literals.
- Boolean Literals.
- String Literals.
Integer Literals
In a source code we can write integers in three ways.
- Base 10 (decimal).
- Base 8 (octal).
- Base 16 (hexa).
We can see every thing output same value.
Reason for that,
In line 4 and line 11 have 100 as base 8 octal value and that's why it outputting value 100.
In line 5 and line 13 have 100 as base 16 hexadecimal value and that's why it outputting value 100.
In line 5 and line 13 have 100 as base 16 hexadecimal value and that's why it outputting value 100.
Floating Literals
As floating literals we are using float and double variable types and we can assign floating point numbers and real numbers to these variables.
When we assign floating point number to float variable we need to put "f" after number we need to assign. but in double variable we no need to do anything like that.
Also with real numbers we no need to do anything special things before or after assign values.
Character Literals
Character means single letter, For example 'A' or 'h' and 'AD' or 'sG' is not character because it have two letters.
In code we can write/define character in 3 different ways.
- As an English letter - 'A', 'm' etc.
- As the ascii code of the character - 65 = 'A'
- As the unicode of character - \u0041 = 'A'
Special Characters in JAVA
Boolean Literals
In boolean literals we can put value yes and no. but we write t as true and false.
true = yes.
false = no.
boolean heavily using in code logics and conditions. to check things true or false (yes or no.)
Comments
Post a Comment