DEV Community

RainbowJier
RainbowJier

Posted on

Data Types

Table of Contents

Basic Data Structure

There are eight major data types in Java, which can be divided into numerical, character, and boolean types.

  • Numerical Types
Data Type Size Ranges
byte 8 bit -128 ~ 127
short 16 bit -2^15 ~ 2^15 - 1
int 32 bit -2^31 ~ 2^31 - 1
long 64 bit -2^63 ~ 2^63 - 1
float 32 bit single precision floating point type, such as 2.0f
double 64 bit higher precision floating point type, such as 2.0
  • Character Types
Data Type Size Ranges
char 16 bit Used to represent Unicode characters, 1 character = 2 bytes
  • Boolean Types
Data Type Size Ranges
boolean logical value true && false

Wrapper Types

In Java, each primitive data type has a corresponding wrapper class. Assignment and conversion between the primitive types and their corresponding wrapper classes are achieved through automatic boxing and unboxing.

Primitive Data Types Wrapper Classes
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
  1. Automatic Boxing refers to automatically converting a primitive value into its corresponding object wrapper.

  2. Unboxing is the reverse process where an object wrapper's value is converted back to its corresponding primitive type.

system diagram

Top comments (0)