Datatypes
PrimitiveData Type: boolean, short, char, int, byte, float, long, and double.Non-PrimitiveData Type or Object Data Type: String, Array, etc.
Reference Types
Section titled “Reference Types”package com.example;
import java.util.Date;
public class ReferenceTypes { public static void main(String... args) { String name = new String("MyName"); Date date = new Date();
System.out.println("String : "+name); System.out.println("Date : "+date); }}
/*Output=======$ java com/example/ReferenceTypes.javaString : MyNameDate : Sat Apr 19 13:09:27 IST 2025*/Primitive Types
Section titled “Primitive Types”package com.example;
public class PrimitiveTypes { public static void main(String... args) { byte byteVar = 127; short shortVar = 32000; int intVar = 999; long longVar = 1_000_000L; // Use this convention for better readbility float floatVar = 0.0F; double doubleVar = 0.098769; char charVar = 'a'; boolean boolVar = false;
System.out.println("Byte: " +byteVar); System.out.println("Short: " +shortVar); System.out.println("Int: " +intVar); System.out.println("Long: " +longVar); System.out.println("Float: " +floatVar); System.out.println("Double: "+doubleVar); System.out.println("Char: " +charVar); System.out.println("Bool: " +boolVar); }}
/*Output===========$ java com/example/PrimitiveTypes.javaByte: 127Short: 32000Int: 999Long: 1000000Float: 0.0Double: 0.098769Char: aBool: false*/References:
Section titled “References:”- Types of References - Link
- Oreilly Reference doc - Link
- Primitive Types, Oracle
- Java Primitives Types