Skip to content

Java Data Types | Primitive & Non-primitive (Object) with Examples

  • by

When you are Creating variables in Java, that time you need to define a data type with the varible name. The varible memory allocating (size) is depended on Java data types.

This Tutorial you will learn about basic of data types in Java.

Java Data Types Primitive & Non-primitive (Object) with Examples

There are 2 data types in Java, then further divided into many parts as bellow.

  1. Primitive data types: Predefined class data types include boolean, char, byte, short, int, long, float, and double.
  2. Non-primitive data types (Reference/Object): The non-primitive data types include Classes, Strings, Interface, and Arrays.
Java Data Types | Primitive & Non-primitive with Examples

Primitive data types in Java are:

  • boolean - The type whose values store or sates are either true or false
  • char -  The character type whose values are 16-bit Unicode characters, used for store character values.
  • The arithmetic or Numeric  types:
    • integral types:
      • byte - It's value-range lies between -128 to 127 (inclusive).
      • short - It's value-range lies between -32,768 to 32,767 (inclusive)
      • int - It's value-range lies between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive).
      • long - Its value-range lies between -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive).
    •  floating-point types:
      • float - It's default value is 0.0F.
      • double - It's default value is 0.0d.

Java data types size and details.

Here is more details about data type with its default value, size and example.

TypeDescriptionDefaultSizeExample Literals
booleantrue or falsefalse1 bittruefalse
bytetwos complement integer08 bits(none)
charUnicode character\u000016 bits'a''\u0041''\101''\\''\'''\n''ß'
shorttwos complement integer016 bits(none)
inttwos complement integer032 bits-2-1012
longtwos complement integer064 bits-2L-1L0L1L2L
floatIEEE 754 floating point0.032 bits1.23e100f-1.23e-100f.3f3.14F
doubleIEEE 754 floating point0.064 bits1.23456e300d-1.23456e-300d1e1d

Java data types examples  

Simple Primitive data type examples.

class Hello {
    public static void main(String args[]) {

        Boolean active = false;
        byte byteV = 10;
        short shortV = 400;
        int iintV = 100000;
        long longV = 100330L;
        float flotV = 84.5f;
        double doubleV = 19.8d;
        char letterA = 'E';

Non – Primitive data type Examples

class Hello {
    public static void main(String args[]) {

        String name = "EyeHunts";
        int a[] = new int[20]; //Array size of 20


Must read below linked tutoiral based on Non – Primitive data type

Do comment if you have any doubt and suggestion on this tutorial.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

Java version 11

All Java Data Types Examples are in Java 11, so it may change its different from Java 9 or 10 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading