Data Type in Java

 What are Data Type In Java

datatype refers to what type of data a variable will store .


//Primitive DataTypes

byte: 8-bit integer data type. Range from -128 to 127.

byte myByte = 100;


Short: 16-bit integer data type. Range from -32,768 to 32,767.

// example

short myShort = 1000;'


int: 32-bit integer data type. Range from -2^31 to 2^31 - 1.

//Example

int myInt = 100000;


long: 64-bit integer data type. Range from -2^63 to 2^63 - 1.


//Example

long myLong = 1000000000L;


float: 32-bit floating-point data type.


//Example

float myFloat = 3.14f;


double: 64-bit floating-point data type.


//Example

double myDouble = 3.14159;


char: 16-bit Unicode character data type.


//Example

char myChar = 'A';



boolean: Represents true or false values.


//Example

boolean isTrue = true;



//Non primitive DataTypes

String and arrays are not primitive data types, but they are commonly used in Java.


String: Represents a sequence of characters.

//Example

String myString = "Hello, World!";


Arrays: Collections of elements of the same type.


//Example

// Array of integers

int[] intArray = {1, 2, 3, 4, 5};


// Array of strings

String[] stringArray = {"apple", "banana", "orange"};


// Multi-dimensional array

int[][] multiArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.