Data Types
- Keshari Abeysinghe

- Jul 20, 2020
- 1 min read
Why Data Types Are Important ?
Data types are especially important in Java because it is a strongly typed language. This means that all operations are type-checked by the compiler for type compatibility. Illegal operations will not be compiled. Thus, strong type checking helps prevent errors and enhances reliability. To enable strong type checking, all variables, expressions, and values have a type. There is no concept of a “type-less” variable, for example. Furthermore, the type of a value determines what operations are allowed on it. An operation allowed on one type might not be allowed on another.
In java ,two types of data types can describe as follows.
Primitive data types and non- primitive data types
1.Primitive data types
Primitive data types can broadly categorize as bellow
1.Integer
Type Size Reference Example
byte 8 bits byte x,y,z;
short 2 bytes short x;
int 4 bytes int num;
long 8 bytes long millise;
2.Floating point number
Type Size Reference Example
float 4 bytes float percentage;
double 8 bytes double distance;
3.Characters
char a='c';
Size of character is 2 bytes.
4. Booleans
It use for logical values , it represent either true or false .
boolean isNumber=false;
2.Non-primitive data types
Classes , Interfaces and Arrays belongs to the non-primitive datatypes
Lets move to next chapter >>>> Variables in Java



Comments