Data Types in Java
Data types indicate the various sizes and qualities that can be put away in the variable. There are two sorts of information types in Java:
Primitive data types:- The primitive types incorporate boolean, char, byte, short, int, long, float and double.
Non-primitive data types:- The non-primitive data types incorporate Classes, Interfaces, and Arrays.
Java Primitive Data Types
In Java language, primitive data types are the structure squares of information control. These are the most essential information types accessible in Java language.
Notes :- Java is a statically-composed programming language. That is to say, all factors should be announced before its utilization. That is the reason we need to announce variable's sort and name.
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
Boolean Data Type
The Boolean data type is utilized to store just two potential qualities: true and false. This information type is utilized for straightforward banners that track true/false conditions.
The Boolean data type determines the slightest bit of data, however its "size" can't be characterized definitively.
Example:-
Boolean one = false
Byte Data Type
The byte data type is an illustration of primitive data type. It is an 8-bit marked two's supplement number. Its worth reach lies between - 128 to 127 (comprehensive). Its base worth is - 128 and greatest worth is 127. Its default esteem is 0.
The byte data type is utilized to save memory in huge clusters where the memory investment funds is generally required. It saves space on the grounds that a byte is multiple times less than a whole number. It can likewise be utilized instead of "int" information type.
Example:-
byte a = 10, byte b = - 20
Short Data Type
The short data type is a 16-bit marked two's supplement whole number. Its worth reach lies between - 32,768 to 32,767 (comprehensive). Its base worth is - 32,768 and greatest worth is 32,767. Its default esteem is 0.
The short data type can likewise be utilized to save memory very much like byte information type. A short data type is multiple times less than a number.
Example:-
short s = 10000, short r = - 5000
Int Data Type
The int data type is a 32-bit marked two's supplement number. Its worth reach lies between - 2,147,483,648 (- 2^31) to 2,147,483,647 (2^31 - 1) (comprehensive). Its base worth is - 2,147,483,648and greatest worth is 2,147,483,647. Its default esteem is 0.
The int data type is by and large utilized as a default data type for basic qualities except if in case there is no issue about memory.
Example:-
int a = 100000, int b = - 200000
Long Data Type
The long data type is a 64-bit two's supplement whole number. Its worth reach 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 worth is - 9,223,372,036,854,775,808and most extreme worth is 9,223,372,036,854,775,807. Its default esteem is 0. The long data type is utilized when you need a scope of qualities more than those gave by int.
Example:-
long a = 100000L, long b = - 200000L
Float Data Type
The float data type is a solitary accuracy 32-bit IEEE 754 drifting point. Its esteem range is limitless. It is prescribed to utilize a buoy (rather than twofold) in the event that you need to save memory in huge varieties of skimming point numbers. The buoy information type ought to never be utilized for exact qualities, like money. Its default esteem is 0.0F.
Example:-
float f1 = 234.5f
Double Data Type
The double data type is a double accuracy 64-bit IEEE 754 gliding point. Its worth reach is limitless. The twofold information type is by and large utilized for decimal qualities very much like buoy. The double data type additionally ought to never be utilized for exact qualities, like money. Its default esteem is 0.0d.
Example:-
double d1 = 12.3
Char Data Type
The char data type is a solitary 16-bit Unicode character. Its worth reach lies between '\u0000' (or 0) to '\uffff' (or 65,535 inclusive).The char data type is utilized to store characters.
Example:-
char letter A = 'A'
Why char utilizes 2 byte in java and what is \u0000 ?
It is on the grounds that java utilizes Unicode framework not ASCII code framework. The \u0000 is the most reduced scope of Unicode framework. To get detail clarification about Unicode visit next page.
No comments:
Post a Comment