How to Add Buttons and Text to Your JavaFX Project
Java Keywords and Identifiers
JavaFX: Bloom and Glow Classes

The Eight Data Types of Java

The term data type refers to the type of data that can be stored in a variable. Sometimes, Java is called a “strongly typed language” because when you declare a variable, you must specify the variable’s type. Then the compiler ensures that you don’t try to assign data of the wrong type to the variable. The following example code generates a compiler error:

int x;
x = 3.1415;

Because x is declared as a variable of type int (which holds whole numbers), you can’t assign the value 3.1415 to it.

Java distinguishes between two kinds of data types: primitive types and reference types. Primitive types are the data types defined by the language itself. By contrast, reference types are types defined by classes in the Java application programming interface (API) or by classes you create rather than by the language itself.

Java defines eight primitive types:

Type Explanation
int A 32-bit (4-byte) integer value
short A 16-bit (2-byte) integer value
long A 64-bit (8-byte) integer value
byte An 8-bit (1-byte) integer value
float A 32-bit (4-byte) floating-point value
double A 64-bit (8-byte) floating-point value
char A 16-bit character using the Unicode encoding scheme
boolean A true or false value
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Write a Disk-Oriented Program in Java
Access Modifiers in Java
Calling Methods in Java
Java Development: Inside a View or an Editor in Eclipse
How to Use Initializers in Java