Java and data types

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.










Wrapper Class









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.


Those are general ideas about basic data type in Java. It is quite interesting, right? 😀 Thanks for your reading.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at

Up ↑

%d bloggers like this: