Primitive Data Types in Java

Graphic with the eight primitive data types by MakeTheBrainHappy.
Data in computer science, especially in Java, it defined with a type that defines the type of data that can be stored (words, numbers, etc.) and the range of values (i.e. length of the words or size of numbers, etc.) that can be acted upon.

Primitives are built-in data types; other types are "reference" types that need to be defined in a class blueprint and "created" as objects. Primitives are simpler and will allow us to begin our discussion of data. Java has eight primitive data types (the three most common are starred):

Byte: integer value (8 bits)

Short: integer value (16 bits)

*Int: integer value (32 bits)

Long: integer value (64 bits)

Float: floating point # (32 bits)

*Double: floating point # (64 bits)

Character: one unicode character

*Booleans: a true or false value

A larger number of bits corresponds to a larger number which can be stored into those variables.

Declaring Primitives:

byte varName;
short VarName;
int varname;
long Varname;
float vArname;
double vArName;
char varNAme;
boolean varNAMe;

These variables can be then be assigned using the = operator to values fitting the descriptions for each of the primitive data types. If you add the keyword final between the type and variable name, then you have declared a constant (you cannot change the data within the variable later in the program).

Reserved Keywords:

Java has certain reserved keywords that cannot be utilized as variable names due to their special functions within the language. These are abstract, assert, boolean, break, byte, case, catch, char, class, const, default, do, double, else, enum, extends, false, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, null, package,  private, protected, public, return, short, static, strictfp, super, switch, synchronized,  this, throw, throws, transient, true, try, void, volatile, while, and continue.

Visibility Modifiers:

Variables can either be declared as public or private, reserved keywords which are placed in front of the type. Public variables can be accessed by all classes while private variables can only be utilized by the class in which they are declared.

Static vs. Non-Static Variables:

This keyword, also placed before the type but after the visibility modifier, determines whether the variable is a part of the object declared from the class (thereby only being accessible through the identifiers of an object) as opposed to static variables are a part of the class and therefore can be accessed from "static" contexts such as the main method or static methods.


Some variables can be changed from one type to another through casting. Between the six types dealing with numerical values, you can cast utilizing the casting operator placed before the variable name. For example, here is a variable being converted from a integer to a double.

int varname = 1;
double newDouble = (double)varname;

This is a widening conversion since a more restrictive data type is changed to a more free version; therefore, no data is lost. But if you are converting a double to an integer, you would lose the information encoded by the decimals. This means that this would be a narrowing conversation.


  1. Very useful message. This is my first time visiting here. I found a lot of interesting things on your blog, especially your discussion. It really is a great article. Keep on going.

    Data Analytics Course in Ernakulam

  2. Wonderful illustrated information. Thank you. It will certainly be very useful for my future projects. I would love to see more articles on the same topic!

    Data Science Training in Bangalore

  3. Its content is brilliant in many ways. I think it is an attractive and revealing material. Thank you very much for caring about your content and your readers.

    Data Science Course in Durgapur

  4. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you... data science course in Vadodara

  5. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! data science course in Kolkata

  6. It’s not how it’s about where? Get trained at 360DigiTMG, the best Data Analytics training institute, and experience the power of technical knowledge. Hone your skills with the ground-breaking curriculum.

  7. 360DigiTMG is the top-ranked and the best Data Science Course Training Institute in Hyderabad.

  8. Explore what the best Data Science training institute is offering you. Learn advanced technologies from the best industry experts.

    data analytics course in lucknow

  9. This comment has been removed by the author.

  10. Get dual certification from IBM and UTM Malaysia with the 360DigiTMG Data Science Certification analytics course in jalandhar

  11. It’s not how it’s about where? Get trained at 360DigiTMG, the best Data Analytics training institute, and experience the power of technical knowledge. Hone your skills with the ground-breaking curriculum.
    Data Analyst Course in Bangalore with Placement