Data Types in java
DataTypes is used to store the different types of data and size like a "int,float and String ..etc."
Types of Data Type
- Primitive DataTypes
- Non Primitive DataTypes.
1. Primitive DataTypes
Primitive DataTypes has a specific size and value.Example(int,float,char,..etc).This datatypes are limited size.
Data Types | Size | Limit |
---|---|---|
byte | 1 byte | -128 to 127 |
short | 2 byte | -32,768 to 32,767 |
int | 4 byte | -2,147,483,648 to 2,147,483,647 |
float | 4 byte | It's store 5 to 6 decimal points. |
double | 8 byte | It's store 15 decimal points. |
char | 2 byte | It's store single character. |
long | 8 byte | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
boolean | 1 byte | It's store true or false |
byte
public class Main { public static void main(String[] args) { byte a=1; } }
short
public class Main { public static void main(String[] args) { short a=1; } }
int
public class Main { public static void main(String[] args) { int a=111; } }
float
public class Main { public static void main(String[] args) { float f=1.2f; } }
double
public class Main { public static void main(String[] args) { double d=1.232151; } }
char
public class Main { public static void main(String[] args) { char c='z'; } }
long
public class Main { public static void main(String[] args) { long l=456165486l; } }
boolean
public class Main { public static void main(String[] args) { boolean a=true; } }
2. Non Primitive DataTypes
Non Primitive DataTypes is a user declare.Its size and value is not specified.
Data Types | Size |
---|---|
String | Not declare |
Array | Not declare |
Class | Not declare |
Interface | Not declare |
etc... | Not declare |
String
public class Main { public static void main(String[] args) { String str="mycrazycoding"; } }