data-types-in-java

Get Started: Data Types in Java

In This Article, You will learn about Data Types in Java.

Data Types in Java – Before moving ahead, let’s know a bit about Introduction to Java.

Table of Contents

What is Data Type?

In Normal language, Data Type identifies what type of data type a data has. 

Data Types in Java

There are two types of Data Types in Java.

Primitive Data Type – Primitive Data Type is a type of Data Type which are pre-defined or built-in in Java language. E.g., numeric types, boolean types, and character types.

The numeric types contain integral types and floating-point types. Integral types contain byte, short, int, and long and the floating-point types contain a float and double.

Default Value & Size of Primitive Data Types

Data Type

Default Value

Default Size

byte

0

1 byte (8 bits)

short

0

2 bytes (16 bits)

int

0

4 bytes (32 bits)

long

0L

8 bytes (64 bits)

char

‘\u0000’

2 bytes (16 bits)

boolean

false

1-bit

float

0.0f

4 bytes (32 bits)

double

0.0d

8 bytes (64 bits)

Integral Types and Values

Types

Range of Values

Default Values

byte

ranging from -128 (-27)to 127 (27– 1), inclusive

Default value is 0

short

range from -32768 (216 ) to 32767(216 – 1), inclusive

Default value is 0

int

range from -2147483648  (-231) to 2147483647 to (231– 1), inclusive

Default value is 0

long

range from -9223372036854775808 (-263 ) to 9223372036854775807 (263 – 1), inclusive

Default value is 0L

Floating-Point Type

Data Types

Bit-size

Fractional Number Store

Default Value

float

32-bit

6 to 7 decimal digits

0.0f

double

64-bit

15 decimal digits

0.0d

The float data type is characterized by single-precision 32-bit and double data type is double-precision 64-bit. Precision means how many digits the value can have after the decimal point. It is recommended to use a float if you want to save memory area in large arrays of floating point numbers. 

The float data type stores fractional numbers which are capable to store 6 to 7 decimal digits whereas the double data type stores fractional numbers which are capable to store 15 decimal digits. The default value of the float data type is 0.0f and for double it is 0.0d.

Reference or user-defined – Reference Data Type is a type of Data Type which are manually defined by the user. E.g. class, interface, array, etc. 

Reference Type

Class: It is a collection of objects that can be used as a blueprint to create as many objects as you want. Hence, we can say a class is a group of objects which have common properties i.e. in a single class we can put many similar types of objects and objects created from this class. 

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on