Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA PROGRAMMING

Data Types

 The Simple types

Java defines eight simple types of data: byte, short, int, long, char, float, double, and boolean.

Integer

Java defines four integer types :byte, short, int and long. All of these are signed, positive and negative values.

The width and ranges of these integer type vary widely, as shown in this table:

Name Width Range
long 64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int 32 -2,147,483,648 to 2,147,483,647
short 16 -32,768 to 32,767
byte 8 -128 to 127

Declaration of Integer types

long price;

int num;

short qty;

byte bt;

 

Floating - Point Types

Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision. Their width and range shown here:

Name Width Range
double 64 1.7e-308 to 1.7e+308
float 32 3.4e-038 to 3.4+038

Declaration of floating-point types

double price;

float salary;

Character

In Java, the data type used to store character is char. In Java, char is a 16-bit type. The range of char is 0 to 65536. 

Declaration of character types

char ch;

Boolean

Java has a simple type, called boolean, for logical value. It can have only two possible values, true or false.

Declaration of boolean types

boolean b;

A sample code  using different data types:



 


Previous

Next