Java Data Types

Java Data Types

What is Data Type?

Data type is a classification of the type of data that a variable or object can hold in computer programming.

Ex: character, integer, float etc....

> Java supports explicit declaration of Data types.
(we need to specify the data type before declaring the Variable)

Syntax:data_type variable_name;

data_type variable_name = value;

int a;

int a = 100;
Two types of Data types in java:

a) Primitive Data types

b) Non-primitive Data types / Reference Data types
a) Primitive Data types (8 primitive data types)

Integer types1) byte (8 bits)


byte a =100;

2) short (16 bits)

short a = 10000;

3) int (32 bits)

int a = 100000;

4) long (64 bits)

long a = 100000L
Rational types (Numbers with decimal places)5) float (32 bits)

float a = 1.2;

6) double (64 bits)
double a = 19.3456;
Characters7) char (16 bits)


char a ='Z'
Conditional8) boolean (undefined, depends on JVM)

boolean a = true
b) Non-primitive / Reference data types

Non-primitive data types in Java are Objects and Arrays.


Reference types are not passed value, passed by reference


Button a = new Button("OK")

Java String:

> Java String provides a lot of concepts that can be performed on Strings.

> Java String is not a data type in Java, It is a Class.

Declaring String variables and Arrays:

String myTool = "Selenium"; // String Variable

String [] myTools = {"Selenium", "UFT", "RFT", "SilkTest", LoadRunner"}; Array of Strings
Also Read:

Java Variables

Java Operators 

Java Conditional Statements 

Java Loop Statements

Java Arrays 

Java Methods


Post a Comment