In a Java there are eight different primitive types of data: byte, short, int, long, char, float, double, and boolean. This types are also referred to as a simple data types and these types are grouped into four different types:

  • Integers: In this group byte, short, int and long are included, which are for whole-valued signed numbers.
  • Floating-point : In this group includes float and double, which is represents the numbers with the fractional precision.
  • Characters: In this group includes char, which represents characters, like letters and numbers.
  • Boolean: In this group includes boolean, which is representing tru or false values.

You can use these data types is to construct the arrays or your own class types. These primitive types represents single values it does not represent complex object.

Let’s look at each data types in java briefly:

Integers

In a java there are four integer types: byte, short, int and long. All of these types are signed, positive and negative values. The width and the range of these types are as shown in this table:

NameWidthRange
long64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int32-2,147,483,648 to 2,147,483,647
short16-32,768 to 32,767
byte8-128 to 127

Let’s look at each integer types:

  • byte: byte is a smallest integer type.This is a signed 8 bit type and it has range from -128 to 127. The byte type variable are especially useful when you are working in network or file. Here you work with a stream of data. The byte type variables are declared by using byte keyword. For example, byte a, c;
  • short: short type is a 16 bit signed data type. It has a range from -32,768 to 32,767. These type variable are declared using short keyword. For example, short a; short b;
  • int: int is a most commonly used integer data type. It is a 32 bit signed type and it has a range from -2,147,483,648 to 2,147,483,647. For example, int a;
  • long: long is a 64 bit signed data type and is useful where the int type is not enough large to hold the desired values. The range of these long type is quite large. This is useful when you need to store whole big numbers. For example, long seconds;

Floating-Point :

Floating point numbers are also known as a real numbers. This are used when evaluating expression that require fractional precision.For example calculations of square root. There are two types of floating-point types float and double. Their width and range shown here.

NameWidth in BitsApproximate Range
double644.9e-324 to 1.8e+308
float321.4e-045 to 3.4e+038

Let’s look each of these floating point number:

  • float: float type specifies the single precision value that uses 32 bits of storage. Here are example of float variable declarations: float hightemp;
  • double: double type specifies the double precision value that uses 64 bits to store a value. All transcendental math functions such as the sin(), cos() or sqrt() return double values. Example double area;

Characters:

char: For store a characters char data type is use in java. The range of char is 0 to 65,536. The char is designed to hold unicode characters. For example, char ch1;

Booleans:

Java has a boolean primitive data type for store logical values. boolean can only two values true or false. Boolean is a return type of all relational operators. For declaration of boolean variable use boolean keyword. For example, boolean b;

This are the primitive data type used in java. If you want to know more about the data types so you can see our programs. In which you can understand how to use data type. For integer data type see these article addition of numbers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top