• Home
  • Java
    • Java Basics
  • Kafka
    • Producer
  • AWS
  • GoLang
  • About Me
mjpric3@gmail.com
Curriculum Vitae

The Code Standard

  • Home
  • Java
    • Java Basics
  • Kafka
    • Producer
  • AWS
  • GoLang
  • About Me

Java Data Types

Basics

There are two different data types in Java. Reference and Primitives.

Primitive Types

There are eight primitive types: Before we defined the size of these primitives, let’s first define what a bit is. A bit stands for binary digit. A bit is the smallest unit of data in a computer. Its value can either be a 1 or 0. (True, False)

Primitive Data TypeNumber of Bits
byte8 (Integral Value)
char16 (Unicode Value)
short16 (Integral Value)
int32 (Integral Value)
long64 (Integral Value)
float32 (Floating-Point Value)
double64 (Floating-Point Value)
booleanTrue or False

Here are some examples of declaring and initializing all of these types.

byte b = 1;

char c = 'c';

short s = 1;

int n = 100;

long l = 200L;

float f = 100.1f;

double d = 100.1;

boolean flag = true;

Reference Types

A reference type  refers to an instance of a class. If you remember from my previous post that a class instance is called an object. A reference type points to the location in memory where the objects lives. The reference variable stores the memory address where the objects is located.

Will use the String object as an example:

String name = "Mike"; 
// name is the reference object and can only point to a String object.

You also might be interested in

Conditional Statements

Dec 27, 2018

Conditional Statements are a core part of programming and everyday[...]

Java Objects

Dec 22, 2018

Objects in Java An object in Java is a runtime[...]

What Is A Computer Program?

Dec 21, 2018

A computer program is a useful piece of code written[...]

Recent Posts

  • Producer
  • Interfaces
  • Abstraction
  • Polymorphism
  • Conditional Statements

Categories

  • Basics
  • Kafka
  • Welcome

© 2025 · thecodestandard.com

Prev Next