What is Data type?
- A simple word in data type stores the variable value.
There are two types of data types in java
- primitive data type
- non-primitive data type
- The primitive data type is already predefined datatype in a java
- Primitive data types that give some specific range of value
- Primitive data type default value is ZERO(0)
- Primitive data types always start in the lowercase letter
- it's not any method type datatype
- Primitive data type full name is called us a wrapper class. like int to Integer.
There are few(8 type) primitive data is available in the java
- boolean
- char
- byte
- short
- int
- long
- float
- double
Example
public class PremitiveDataType {
public static void main(String[] args) {
byte a=10;
short b= 15;
int c= 100;
long d=10000;
float e= 15.5f;
double f = 20.3455d;
System.out.println("byte datatype value is : "+a);
System.out.println("short datatype value is : "+b);
System.out.println("int datatype value is : "+c);
System.out.println("long datatype value is : "+d);
System.out.println("float datatype value is : "+e);
System.out.println("double datatype value is : "+f);
}
}
output
byte datatype value is : 10
short datatype value is : 15
int datatype value is : 100
long datatype value is : 10000
float datatype value is : 15.5
double datatype value is : 20.3455
2) Non-primitive DataType
- Non-primitive data type includes in some object and class
- non-primitive data type Create a user in your need purpose and not define in java
- non-primitive data is his own some range
- non-primitive data type his default value is null
- it starts with the upper case letter like us a String
- non-primitive datatype his own class and method ex string is class and method and datatype
There are some Non-primitive data type are available
- String
- Array
- Class
- Object
- Interface
Example
output
import java.util.Arrays;
public class NonPrimitiveDataType {
public static void main(String[] args) {
String name = "javaoverflow";
int[] a= new int[]{1,2,3,4,5};
System.out.println("our website name is : "+name);
//hear tostring method to print array value
System.out.println("arrays value is : "+Arrays.toString(a));
}
}
our website name is : javaoverflow
arrays value is : [1, 2, 3, 4, 5]
so it's all about in Difference Between Primitive And Non-Primitive Data Type In Java.