Breaking

Monday, 1 April 2019

Data Types in Java | Java Tutorial | Data Types Of Java


Data Types in Java

Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:
  1. Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
  2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Java Primitive data Types



In Java language, primitive data types are the building blocks of data manipulation. These are the most basic data types available in Java language.
There are 8 types of primitive data types:
  • boolean data type
  • byte data type
  • char data type
  • short data type
  • int data type
  • long data type
  • float data type
  • double data type

Data Type
Default Value
Default size
boolean
false
1 bit
char
'\u0000'
2 byte
byte
0
1 byte
short
0
2 byte
int
0
4 byte
long
0L
8 byte
float
0.0f
4 byte
double
0.0d
8 byte

Boolean Data Types



The Boolean information type is utilized to store just two conceivable qualities: genuine and false. This information type is utilized for basic banners that track genuine/false conditions.

The Boolean information type indicates one piece of data, yet its "measure" can't be characterized definitely.
Example: Boolean one = false

Byte Data Types

The byte information type is a case of crude information type. It isan 8-bit marked two's supplement number. Its esteem run lies between - 128 to 127 (comprehensive). Its base esteem is - 128 and most extreme esteem is 127. Its default esteem is 0.

The byte information type is utilized to spare memory in huge clusters where the memory investment funds is generally required. It spares space on the grounds that a byte is multiple times littler than a whole number. It can likewise be utilized instead of "int" information type.
Example: byte a = 10, byte b = -20

Short Data Types

The int information type is a 32-bit marked two's supplement number. Its esteem extend lies between - 2,147,483,648 (- 2^31) to 2,147,483,647 (2^31 - 1) (comprehensive). Its base esteem is - 2,147,483,648and most extreme esteem is 2,147,483,647. Its default esteem is 0.

The int information type is commonly utilized as a default information type for essential qualities except if there is no issue about memory.
Example: int a = 100000, int b = -200000


Long Data Types

The long information type is a 64-bit two's supplement whole number. Its esteem extend lies between - 9,223,372,036,854,775,808(- 2^63) to 9,223,372,036,854,775,807(2^63 - 1)(inclusive). Its base esteem is - 9,223,372,036,854,775,808and greatest esteem is 9,223,372,036,854,775,807. Its default esteem is 0. The long information type is utilized when you need a scope of qualities more than those given by int.
Example: long a = 100000L, long b = -200000L

Float Data Types

The buoy information type is a solitary accuracy 32-bit IEEE 754 coasting point.Its esteem extend is boundless. It is prescribed to utilize a buoy (rather than twofold) on the off chance that you have to spare memory in expansive varieties of drifting point numbers. The buoy information type ought to never be utilized for exact qualities, for example, cash. Its default esteem is 0.0F.
Example: float f1 = 234.5f

Double Data Types

The twofold information type is a twofold exactness 64-bit IEEE 754 drifting point. Its esteem run is boundless. The twofold information type is commonly utilized for decimal qualities simply like buoy. The twofold information type likewise ought to never be utilized for exact qualities, for example, money. Its default esteem is 0.0d.
Example: double d1 = 12.3

Char Data Types

The char data type is a single 16-bit Unicode character. Its value-range lies between '\u0000' (or 0) to '\uffff' (or 65,535 inclusive).The char data type is used to store characters.
Example: char letterA = 'A'

Why char uses 2 byte in java and what is \u0000 ?

It is because java uses Unicode system not ASCII code system. The \u0000 is the lowest range of Unicode system. To get detail explanation about Unicode visit next page.

 

No comments:

Post a Comment