DataType defines a particular kind of data or value it can take
Primitive DataType:
Primitive means “very basic”.
In Java, primitives are the most basic kinds of data types and they directly contain values like int, char etc.
NonPrimitive DataType:
Non primitive datatypes are those which uses primitive datatype as base like array, class etc.
Also called as reference types which references a memory location where the data is stored rather than directly containing a value.
Classification
Primitive types –
package mypackage; public class DataTypeSample { public static void main(String[] args) { int myInt = 234; System.out.println(myInt); System.out.println("Int size - " + Integer.SIZE); char myChar = 's'; System.out.println(myChar); System.out.println("Char size - "+ Character.SIZE); boolean myFlag = true; System.out.println(myFlag); float myFloat = 2.333f; System.out.println(myFloat); double myDbl = 3.44444; System.out.println(myDbl); } }
Output –
234 Int size - 32 s Char size - 16 true 2.333 3.44444
Watch in action here –