Data Types in Java

Edu Tech Learner
0


Data types in Java are the categories of values that can be stored in variables. They define the size and type of the data that can be manipulated by the program. 

There are two types of data types in Java: 

  1. primitive 
  2. non-primitive.

1.Primitive data types are the basic data types that are built-in to the Java language. They are also called simple or atomic data types because they cannot be further divided into smaller parts. There are eight primitive data types in Java: byte, short, int, long, float, double, char and boolean. Each of these data types has a fixed size and range of values that it can store.

2.Non-primitive data types are the data types that are defined by the programmer or by the Java library. They are also called complex or reference data types because they refer to objects that have attributes and methods. Non-primitive data types include classes, interfaces, arrays, strings, etc. They can store complex or dynamic data that can vary in size and structure.

Here is a table that summarizes the main characteristics of the primitive data types in Java:

Data TypeSizeDescriptionExample
byte1 byteStores whole numbers from -128 to 127byte b = 10;
short2 bytesStores whole numbers from -32,768 to 32,767short s = 1000;
int4 bytesStores whole numbers from -2,147,483,648 to 2,147,483,647int i = 100000;
long8 bytesStores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807long l = 1000000000L;
float4 bytesStores fractional numbers with up to 6-7 decimal digitsfloat f = 3.14f;
double8 bytesStores fractional numbers with up to 15 decimal digitsdouble d = 3.14159;
char2 bytesStores a single character or Unicode valuechar c = ‘A’;
boolean1 bitStores true or false valuesboolean b = true;

Post a Comment

0Comments
Post a Comment (0)