Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
67 views

Rules For Defining Data Identifier

1) An identifier in Java is a name used to identify variables, methods, classes, and other entities. Identifiers must begin with a letter, underscore, or dollar sign and can include numbers but cannot start with a number. 2) There are certain rules for defining valid Java identifiers, such as they are case sensitive, cannot use reserved words, and have no length limit. 3) Java supports various primitive data types including integer types like byte, short, int, long and floating point types like float and double. Each data type has a specific size and value range. Literals are constant values that can be assigned to variables and come in integer, floating point, boolean, and character forms.

Uploaded by

Khushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Rules For Defining Data Identifier

1) An identifier in Java is a name used to identify variables, methods, classes, and other entities. Identifiers must begin with a letter, underscore, or dollar sign and can include numbers but cannot start with a number. 2) There are certain rules for defining valid Java identifiers, such as they are case sensitive, cannot use reserved words, and have no length limit. 3) Java supports various primitive data types including integer types like byte, short, int, long and floating point types like float and double. Each data type has a specific size and value range. Literals are constant values that can be assigned to variables and come in integer, floating point, boolean, and character forms.

Uploaded by

Khushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

JAVA

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

Rules for defining data identifier


1 ) The only allowed character are given below and if we are using other than this then it will
give error.
a to x
A to Z
0 to 9
$,_
2) Identifier can not start with number example 123total is not valid but total123 is valid
3) Java identifier are case sensitive . Offcourse java language is also treated as case sensitive
programming language

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

53 reserved words in java


Note: goto and const are unused key words , if we are trying to use then it will give error.
Note : all 53 reserved in java contain lower case only

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

Note: positive no is represented in memory whereas negative no is represented in


compliment form.
2) Short data type : This is the most rarely used data type in java .
Size: 2 bytes(16 bits)
Range: -2^15 to 2^15-1 [-36768 to 36768]
Note : Short data type best suitable for 16 bit processor like 8085 but this processor are
completely outdated.
3) Int data type: The most commonly used data type is int data type .
Size : 4 bytes(32 bits)
Range: -231 to 231-1[-2147483648 to 2147483647]
.
.
.
.
.

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

Char literal : We can specify single character within single cotes .


Example char ch= ‘d’; valid

You might also like