Data Types in Java

by E-Computer Concepts October 23, 2019 at 7:17 am

There are two kinds of data types in java:-

  • Primitives/standard data types
  • Abstract/derived data types

Primitive Data Types

Primitive data types (also know as standard data types) are the data types that are built into the Java language. The Java compiler holds details instructions on each operation the data types that are built into the Java language.

The Java compiler holds detailed instructions on each legal operation the data type supports. There are eight primitive data types in Java.

Data
Type
Size/Form
at (Bits)
DescriptionRange
byte 8 Byte-length integer-128 to 128 (signed)
0 to 255 (unsigned)
short16Short integer-215 to 215 -1
int32integer -231 to 231 -1
long64Long integer -263 to 263 -1
float32Single precision
floating point
+/- about 10 317
double64Double precision
floating point
+/- about 1039
char16A single character
Boolean1A boolean value
(true or false)

The data types – byte, short, int, long, float and double are numeric data types. The first four of these can hold only whole numbers whereas the last two (float and double) can hold decimal values like 5.05.

All these data types can hold negative values. However, the keyword unsigned can be used to restrict the range of values to positive numbers.

Among-st others, boolean can hold the value true or false and char can hold only a single character.

Abstract/Derived Data Types

Abstract data types are based on primitives data types and have more functionality that the primitive data types.

For example, String is an abstract data type that can store alphabets, digits and other characters like /, (); :$#.

You can’t perform calculations on a variable of the string data type even if the data stored in it has digits.

Add Comment