Professional Documents
Culture Documents
Identifiers are used for identification purpose. A name in java program is called Identifier which
can be used for identification purpose. It can be method name or variable name or class name.
Eg.
}
Identifiers in above eg are Test, main, String, args, X
e.g.
public class Test {
int digit=10;
int Digit=10;
}
Keyword:
Keywords are reserved names whose meaning is already set at memory called as
Keyword.
Data Types:
1. In java, every variable & every expression has some type. Each & every data type is clearly
defined. Every assignment should be checked by compiler for type compatibility
Because, of above reasons, we can conclude java language is strongly typed programming
language.
2. Java is not considered as pure object-oriented programming language because, several OOP
features are not satisfied by java (like, Operator overloading, multiple inheritance etc)
Moreover, we are depending on primitive data types which are non-objects.
3. There are two types of data types:
1) Primitive
2) Non-Primitive
Except char & boolean, remaining data types are considered as signed data types. Because,
we can represent both positive & negative numbers.
Default value: 0.
byte b=127;//valid
2) Short:
Range from -2^15 to 2^15-1 (–32768 to 32767)
Default value: 0
Short data type is best suitable for 16 bit processor like 8085 but this processors are completely
outdated & hence, corresponding short data type is also outdated data type.
e.g. of short:
3) int:
The most commonly used datatype is int.
Range from -231 to 231-1 (-2,147,483,648 to 2,147,483,647)
Default value: 0
e.g. of int:
4)long:
Whenever int is not enough to hold big values then we should go for long data type.
Default value: 0
e.g of long:
Note: All the above data types (byte, short, int and long) can be used to represent whole numbers. If
we want to represent real numbers then we should go for floating point data types.
Size : 4 bytes
e.g.
float x=10f;//valid
float x=10.0f;//valid
float x=10;//valid
float x=true;//invalid
2)Double:
If we want to 14 to 15 decimal places of accuracy then we should go for double.
Size : 8 bytes
e.g. of double
double x=10d;//valid
double x1=10.0d;//valid
double x2=10;//valid
double x3=true;//invalid
e.g. of Boolean :
boolean b = true;//valid
boolean b = false;//valid
boolean b = True;//invalid
boolean b = 0;//invalid
2)char :
Size : 2 bytes(16 bits)
(old languages like c or c++ are ASCII code based & no. of different allowed ASCII code
characters are less than or equal 256 to represent this 256 characters 8 bits are enough.
Hence, size of char in old languages in 1 byte, But java is Unicode based & no. of different
allowed Unicodes are >256 & less than equal to <65536. To represent these many
characters 8 bits may not enough. Compulsory we should go for 16 bits. Hence size of char
in java is 2 bytes.)
e.g. of char
char ch = 'a';//valid
char ch1 =97;//valid output = a
char ch2=20.0f;//invalid