Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Java » Data Types in Java

  • Java 8 interview questions and answers, Java Stream, Optional
    Java 8 interview questions and answers, Java Stream, Optional Important
  • Java Operators
    Java Operators Java
  • Kumkum Bhagya Hindi TV Serial, Cast Name, Actress Name
    Kumkum Bhagya Hindi TV Serial, Cast Name, Actress Name News
  • Most Popular Hibernate Interview Questions and Answers
    Most Popular Hibernate Interview Questions and Answers Hibernate
  • Apj Abdul Kalam biography in Hindi, Life, Missile Man of India
    Apj Abdul Kalam biography in Hindi, Life, Missile Man of India Biography
  • Linear search algorithm | Linear search program in C, Example
    Linear search algorithm | Linear search program in C, Example Data Structure
  • Method Overloading in Java
    Method Overloading in Java Java
  • Spring Boot Tutorial
    Spring Boot Tutorial Spring Boot

Data Types in Java

Posted on August 14, 2021October 11, 2021 By admin
Data Types in Java

Data Types in Java represents the nature of data to be stored in memory. In other words, it specifies size and value that can be stored in the variable.

For example, a variable var can store an integer value like 100.


int var = 10;

Table of Contents

  • Data Type group
    • Primitive Data Types in Java
      • byte type
      • sort type
      • int type
      • long type
      • float type
      • double type
      • char type
      • boolean type
    • Summary of Primitive Data Types and Java Data Type size
  • Non primitive data types in Java
    • What is the range of short data type?

Data Type group

In group, there are two types of data are available which are as follows:

  • Primitive type
  • Non-primitive type

Primitive Data Types in Java

A reserved keyword of the language specifies the primitive type. Primitive values do not share state with other primitive values and there is no additional method for this.

There are following categories of primitive type:

  • Numeric Data Types (byte, short, int, long, float, double)
  • Char Data Types (char)
  • Boolean Data Types (boolean)

byte type

This type stores whole numbers from -128 to 127. It is an 8-bit signed two’s complement integer. The byte data type can be useful when the memory savings actually matters.

Default value of this data type is 0.


public class Example {  // Class Name
 public static void main(String[] args) {
  byte byteVar = 10;
 }
}

sort type

This data type can store whole numbers from -32,768 and a maximum value of 32,767 (inclusive). Default value is 0. It is suitable if you use 16 bit processors like 8086.


short shortVar = 500;

int type

This data type can store whole numbers between -231 and 231-1. Default value is 0. Programmers mostly prefer this data type for numeric value in Java.


int intVar = 100;

long type

long data type is used when int is not enough to hold big value. It can store whole numbers between -263 and 263-1. Default value is 0L. You should use L at the end of value.


long longVar = 1000L;

float type

It can store floating point numbers. Default value is 0f. You should use F or f at the end of value. It is mostly used when 5 to 6 digits of accuracy required.


float floatVar = 10.06F;

double type

It can store floating point numbers. Default value is 0d. You should use D or d at the end of value. It is mostly used when 14 to 15 digits of accuracy required.


double doubleVar = 10.06F;

char type

The char data type is a single 16-bit Unicode character and has a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (or 65,535 inclusive). The character must be surrounded by single quotes.


char charVar = 'x';

boolean type

The boolean data type has only two possible values: true and false. Most importantly, size is not applicable for boolean data type.


boolean booleanVar = true;

Summary of Primitive Data Types and Java Data Type size

#Data TypeSizeRangeWrapper ClassesDefault Value
1byte1-byte2-7 to 27-1Byte0
2short2-byte2-15 to 215-1Short0
3int4-byte2-31 to 231-1Integer0
4long8-byte2-63 to 263-1Long0L
5float4-byte3.4e-038 to 3.4e+038Float0F
6double8-byte1.7e-308 to 1.7e+308Double0D
7char2-byte0 to 65535Character‘\u0000’
8booleanN/Atrue or falseBooleanfalse

Non primitive data types in Java

The non primitive data types include Classes, Interfaces, and Arrays.

What is the range of short data type?

The range of short data type in Java is 2-15 to 215-1.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

Java Tags:Boolean, Char, Data Types, Double, Int, Primitive Type, Short, String, Variables

Post navigation

Previous Post: Variables in Java
Next Post: Java Keywords

More Related Articles

Collections in Java Collections in Java Java
Difference between GenericServlet and HttpServlet Difference between GenericServlet and HttpServlet Differences
Concurrent collections in Java, details, advantages, examples Concurrent collections in Java, details, advantages, examples Java
Loop in Java Loop in Java Java
Lambda Expression in Java 8 | Functional Interface | Example Lambda Expression in Java 8 | Functional Interface | Example Java
Java Operators Java Operators Java

Related Posts

  • Collections in Java
    Collections in Java Java
  • Difference between GenericServlet and HttpServlet
    Difference between GenericServlet and HttpServlet Differences
  • Concurrent collections in Java, details, advantages, examples
    Concurrent collections in Java, details, advantages, examples Java
  • Loop in Java
    Loop in Java Java
  • Lambda Expression in Java 8 | Functional Interface | Example
    Lambda Expression in Java 8 | Functional Interface | Example Java
  • Java Operators
    Java Operators Java
  • Java Home
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Keywords
  • Java Operators
  • Java If-else Statement
  • Java Switch
  • Java Loop
  • Java Arrays
  • Method Overloading in Java
  • Java OOP
  • Java Collections
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Multithreading in java
  • Thread Synchronization
  • Exception Handling
  • Java JDBC Driver
  • Java Database Connectivity steps
  • Lambda Expressions
  • Concurrent Collections

Recent Posts

  • Structured Vs Unstructured Data in Hindi | Key Difference
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
  • World Environment Day in Hindi : Objective, Importance, Theme
  • Thomas Edison Biography in Hindi – थॉमस एडिसन जीवनी
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
  • Fork/Join Framework in Java | RecursiveTask, RecursiveAction
  • DBMS in Hindi | DBMS क्या है? | DBMS की विशेषताएं और प्रकार
  • Java 8 interview questions and answers, Java Stream, Optional
    Java 8 interview questions and answers, Java Stream, Optional Important
  • Java Operators
    Java Operators Java
  • Kumkum Bhagya Hindi TV Serial, Cast Name, Actress Name
    Kumkum Bhagya Hindi TV Serial, Cast Name, Actress Name News
  • Most Popular Hibernate Interview Questions and Answers
    Most Popular Hibernate Interview Questions and Answers Hibernate
  • Apj Abdul Kalam biography in Hindi, Life, Missile Man of India
    Apj Abdul Kalam biography in Hindi, Life, Missile Man of India Biography
  • Linear search algorithm | Linear search program in C, Example
    Linear search algorithm | Linear search program in C, Example Data Structure
  • Method Overloading in Java
    Method Overloading in Java Java
  • Spring Boot Tutorial
    Spring Boot Tutorial Spring Boot
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved