Java Data Types

A data type in Java represents the size and different values that can be stored in a variable. A Java data type is a set of values and operations defined on those values.

There are two types of data types in Java

  • Non-primitive data types
  • Primitive data types

1. Non-primitive data types : 

Non-primitive data types are as belows

  • Arrays
  • Classes

2. Primitive data types :

Primitive data types are as belows

  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char
Data Type Size Stores Value
byte 1 byte from -128 to 127
short 2 bytes -32,768 to 32,767
int 4 bytes -2,147,483,648 to 2,147,483,647
long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes 6 to 7 decimal digits
double 8 bytes 15 decimal digits
boolean 1 bit  true or false values
char 2 bytes single character/letter or ASCII values

 

Syntax : 

data type variable [ = value][, variable [ = value] ...] ;

 

 

Example :

int p, q, r; // Declares three integer p, q, and r.
int l = 10, m = 10; // Example for initialization value
byte C = 22; // initializes a byte type variable C.
double a = 5.56; // declares and assigns a value of a.
char a = 'a'; // the char variable a its initialized with value 'a'

Comments

Leave a Reply

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

17763