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

  • Newton's laws of Motion, State and Explained, Formula
    Newton’s laws of Motion, State and Explained, Formula Science
  • Jagannath Rath Yatra History in Hindi | जगन्नाथ पुरी की कहानी
    Jagannath Rath Yatra History in Hindi | जगन्नाथ पुरी की कहानी Festival
  • Impeachment meaning in Hindi | महाभियोग की परिभाषा और प्रक्रिया
    Impeachment meaning in Hindi | महाभियोग की परिभाषा और प्रक्रिया General Knowledge
  • Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म
    Balkand Ramayana story in Hindi | रामायण बाल कांड राम का जन्म Spiritual
  • Apj Abdul Kalam biography in Hindi, Life, Missile Man of India
    Apj Abdul Kalam biography in Hindi, Life, Missile Man of India Biography
  • Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा
    Sawan ka Mahina : सावन का महीना का महत्व, भगवान शिव की पूजा Festival
  • Chhath Puja Story
    Chhath Puja History : क्यों मनाते हैं छठ महापर्व Festival
  • P V Sindhu Biography in Hindi
    P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति Biography

Data Types in Java

Posted on August 14, 2021October 11, 2021 By GeekCer Education
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

Variables in Java Variables in Java Java
Difference between JPanel and JFrame Difference between JPanel and JFrame Differences
Java Keywords Java Keywords Java
What is Array in Java? Types of array in Java What is Array in Java? Types of array in Java Java
Java If-else Statement Java If-else Statement Java
Difference between Interface and Abstract class Difference between Interface and Abstract class Differences
  • 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
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • 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