Skip to content

Datatypes

  • Primitive Data Type: boolean, short, char, int, byte, float, long, and double.
  • Non-Primitive Data Type or Object Data Type: String, Array, etc.
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.java
String : MyName
Date : Sat Apr 19 13:09:27 IST 2025
*/
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.java
Byte: 127
Short: 32000
Int: 999
Long: 1000000
Float: 0.0
Double: 0.098769
Char: a
Bool: false
*/