Rules For Defining Data Identifier
Rules For Defining Data Identifier
IDENTIFIER
A name in java program is called identifier which can we used for identification purpose .It
can be method name , variable name , class name and level name is called as identifier .
Example: 5 identifier in a below program
4) There is not length limit for java identifier but its not good to take to lengthy identifier
5) We cant use reserve word as identifiers example if , else etc
6) All predefined java class name and interface name we can use as identifier like string , int
etc Eventhough its valid but its not good programming practice because it reduce relability
and create confuse
Which of the following are valid java identifier
1) Total123 = valid
2) total# = invalid
3) 123total = invalid
4) ca$h = valid
5) _$_$ = valid
6) all@cash = invalid
7) Integer = Valid
8) Int = valid
9) int= invalid
RESERVED WORDS
DATA TYPE
In java every varibale and every expression has some type . Each and every data type
clearly defined .Every assignment should check for type compaltibity . Because of above
reason we can conclude java language is strongly type programming language.
Java is not consider as pure objective programming language because several feature
are not satisfied by java like operator overloading , inheritance etc moreover we are
depending on primitive data type which are non object.
Except boolean and char remaining data type consider as sign data type because we can
represent both positive and negative data type.
1) Byte :
Size: 1 byte(8 bits)
Max value : +127
Min value : -128
Range : -128 to 127
LITERALS
Any constant value which can assign to the variable is called literals .
Example int x = 10 ;
Where 10 is constant/literals
Integral literals: for integral data type(bit , short , int , long we can specify literal value in the
following base )
1) Decimal literals(base 10 ) : allow digits are 0 to 10
2) Octal Literals(base 8) : Allow digits are 0 to 7 . Literals value should be prefix with 0 .
example int x = 010;
3) Hexadecimal literals (base 16) : allow digits are 0 to 9 and a to f (we can use both lower
case and upper case character). Literal value should be prefix with 0X or 0x.
Example int x = 0x10;
Floating Point Literals : By default every floating point lateral is double type hence we cant
assign directly to the float variable. But we can specify floating point lateral to float type by
suffix with f/F.
Example float f = 123.6536F; valid
double d = 123.6536; valid
float f = 123.6536; invalid
double d = 123.6536d; valid
Note : We can specify floating point literal only in decimal form and we cant specify in octal
and hexadecimal form .
Example double d = 0X123.6548; invalid
Note : We cant assign floating type literal to integral type literal but we can assign integral
literal to floating type literal .
Note: We can specify floating point literal in exponation form. Example1) double d = 1.2e3
Sytem(d) ;
O/p = 1200.0
2) float d = 1.2e3 invalid
Boolean literal: The only allowed value are true and false.
Example 1) boolean b = true valid
1. boolean b = “true” invalid
2. boolean b = 0 invalid
3. boolean b = True invalid