What is data type
In general, an identifier that contains the size and type of a value is specified data type. Depending on what application you want to develop, you have many choices in java for the appreciated data type.
In java, the data type classifieds in two main types primitive which include Integer, Character, Boolean and Floating Point; and non-primitive or reference which includes classes, interfaces and arrays.
what is primitive data
primitive data type is the most basic data in Java. At once, one type of primitive data only store one single value. There are 8 types of primitive data in Java including byte, short, char, boolean, int, long, float and double.
For more detail about the value’s range of each primitive type in Java. Click here.
Wrapper class
In java, for each data type, there is one wrapper class. In the wrapper class, it can store the single value and has other methods that related with the that data.
Primitive
int
boolean
char
float
long
byte
short
double
Wrapper Class
Integer
Boolean
Character
Float
Long
Byte
Short
Double
Type casting
According to the definition, type casting is the process of converting from one type of data to another type. For example, int to float, int to string.
There are two directions of type casting including narrowing (from the larger type to the smaller type) and widening (from the smaller type to the lager type).
During program executing, widening casting can be done automatically. On another hang, narrowing casting must be done explicitly in code. For example:
int a = 10; //primitive data double c = a; // wide casting int b = (int) c //narrowing casting
Note: Using narrowing casting in some cases can be lost data.
Conclusion
Those are general ideas about basic data type in Java. It is quite interesting, right? 😀 Thanks for your reading.
Leave a Reply