CodeToConcept
About

java

java Tutorials

Introduction
Java Fundamentals
Java Variables
Java Data Types
Java Type Casting
Java Operators
Java Input/Output
Control Statements
Java Class & Object
java Method
Java Constructor
Java this keyword
OOP Principles
Java super keyword
Coming Soon Topics

java Tutorials

Introduction
Java Fundamentals
Java Variables
Java Data Types
Java Type Casting
Java Operators
Java Input/Output
Control Statements
Java Class & Object
java Method
Java Constructor
Java this keyword
OOP Principles
Java super keyword
Coming Soon Topics

Sample Question

Think it through, then check the tutorial.

CodeToConcept

Quickly learn through simple, structured, and practical coding tutorials. Build your confidence from step zero to real-world experience.

© 2026 CodeToConcept. All rights reserved.

Quick Links

AboutTutorials

Tutorials

Java

Support

Privacy PolicyTerms of ServiceContact
GitHubTwitterYouTube

Java Data Types

  1. It specifies what kind of value a variable can store.
  2. DataType tells the size, range and nature of data stored in memory.
  3. In Java, data types are divided into two categories: primitive types and reference (non-primitive) types .
  4. They are stored directly in the stack memory.
  5. They have fixed sizes.

Primitive Data Types :

Primitive data types are the most basic data types, It holds single, simple values like numbers or characters.

There are the 8 primitive data types in Java:

Data TypeSizeExample
byte1 bytebyte age = 25;
short2 bytesshort year = 2025;
int4 bytesint marks = 95;
long8 byteslong population = 8000000000L;
float4 bytesfloat price = 99.99f;
double8 bytesdouble pi = 3.14159;
char2 byteschar grade = 'A';
boolean-boolean isPassed = true;

Example:

   public class PrimitiveDataTypesDemo {
    public static void main(String[] args) {
 
        // byte (1 byte)
        byte age = 25;
 
        // short (2 bytes)
        short year = 2025;
 
        // int (4 bytes)
        int marks = 95;
 
        // long (8 bytes)
        long population = 8000000000L;
 
        // float (4 bytes)
        float price = 99.99f;
 
        // double (8 bytes)
        double pi = 3.14159;
 
        // char (2 bytes)
        char grade = 'A';
 
        // boolean (1 bit conceptually)
        boolean isPassed = true;
 
        // Printing all values
        System.out.println("byte: " + age);
        System.out.println("short: " + year);
        System.out.println("int: " + marks);
        System.out.println("long: " + population);
        System.out.println("float: " + price);
        System.out.println("double: " + pi);
        System.out.println("char: " + grade);
        System.out.println("boolean: " + isPassed);
    }
  }

Non-Primitive (Reference) Data Types:

Non-Promitive or reference type dataType stores the reference(address) of an objects in the memory, it does not stores the actual value directly. It stores objects or complex data or we can say collection of values, not simple values like primitives.

Below are the reference type datatype :

  • String
  • Arrays
  • Classes
  • Interface
  • Objects

Difference between Primitive and Non-primitive dataType:

PrimitiveNon-Primitive

It stores the actual value directly

It stores a reference (address) of an object

The size of the data is fix

The size of the data tynamically change

It has default values

Can be null

Predefined by the programming language

This is user-defined

Stored data in Stack memory

Stored data in Heap memory

See you in next page....🙂

← Java VariablesJava Type Casting →
← Java VariablesJava Type Casting →