CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Primitive data types in Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor
  • Home

Primitive data types in Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 4 min read · 0 Comments
Share: in X
Primitive Data Types in Java

Primitive data types in Java are built-in data types that are available in the language from the beginning. There are 8 (eight) premitive data types in Java. In this blog post, we’ll take a look each of them.

Table of Contents

  • int data type
  • long data type
  • short data type
  • byte data type
  • float data type
  • double data type
  • char data type
  • boolean data type
  • Frequently Asked Questions
    • What are primitive data types in Java?
    • How many primitive data types are there in Java?
    • What is the difference between primitive and reference data types in Java?
    • What is the default value for primitive data types in Java?
    • Can I create user-defined data types in Java similar to primitives?

int data type

The int data type we use to store whole numbers (integers).

Example:

int rollNumber  = 5;

In the above code, we declare a variable called rollNumber to store a numeric value 5. The int data type can store a value size of 4 bytes and can range from -2147483648 to 2147483647.

long data type

This data type is also used to store whole numbers, but it has a larger size of 8 bytes and can store values in the range from -9223372036854775808 to 9223372036854775807.

Example:

long mobileNumber = 9851150050;

short data type

This data type is similar to int, but it has a smaller size of 2 bytes and can store values in the range of -32768 to 32767.

byte data type

This data type is similar to short, but it has an even smaller size of 1 byte and can store values in the range of -128 to 127.

float data type

The float data type we use to store floating-point numbers (numbers with decimal points).

Example:

float price = 125.50f;

In the above code, I’ve added a character f along with the value. If we don’t define a value along with the f character then the Java compiler will assume it as a double value. Hence, it is very important to remember this while declaring a float value.

It has a size of 4 bytes and can store values in the range of approximately 3.4 x 10^-38 to 3.4 x 10^38.

double data type

This data type is similar to float, but it has a larger size of 8 bytes and can store values in the range of approximately 1.7 x 10^-308 to 1.7 x 10^308.

char data type

The char data type we can use to store a single character enclosing by a single quote, such as a letter or a symbol. It has a size of 2 bytes and can store any Unicode character.

Example:

char gender = 'M';

boolean data type

This data type is used to store a true or false value. It has a size of 1 byte and can only store the values true or false.

Example:

boolean isMale = true;

These primitive data types in Java are essential to work with, as they are the basic building blocks for storing and manipulating data. When writing code in Java, it’s important to choose the appropriate primitive data type based on the type of data we need to store.

These data types have assigned a default value. To understand the default values of each data type, you can see below table:

Data typeDefault value
byte0
short0
int0
long0L
float0.0f
double0.0d
char‘\u0000’
booleanfalse
Primitive Types Default Values

In summary, the primitive data types in Java include int, long, short, byte, float, double, char, and boolean. We can use these data types to store a variety of different types of data and are an important part of working with the Java programming language.

Frequently Asked Questions

What are primitive data types in Java?

Primitive data types in Java are basic data types used to represent simple values like integers, floating-point numbers, characters, and booleans.

How many primitive data types are there in Java?

Java has 8 primitive data types, including byte, short, int, long, float, double, char, and boolean.

What is the difference between primitive and reference data types in Java?

Primitive data types store actual values, while reference data types (objects) store references to objects in memory.

What is the default value for primitive data types in Java?

Primitive data types have default values, such as 0 for numeric types, false for boolean, and ‘\u0000’ for char, when not explicitly initialized.

Can I create user-defined data types in Java similar to primitives?

No, Java doesn’t allow users to create custom primitive data types; you can only create objects and use reference data types for that purpose.

Related Posts:

  • Control Statements in Java
  • MySQL Commands for Developers
  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Java Swing Tutorial
  • Spring Data JPA Projection
  • Default Variable Initialization in Java
Tags:javalanguage-fundamentals
Was this article helpful?
← Previous ArticleServlet Life Cycle
Next Article →Difference between PreparedStatement and CallableStatement

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap