• 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

Inheritance

Dec 22, 2018

is one of the four pillars of Java. Its purpose[...]

What Is A Class

Dec 22, 2018

What is a Java Class? There are two kinds of[...]

Abstraction

Jan 4, 2019

Abstraction is used to hide the implementation details of a particular[...]

Recent Posts

  • Producer
  • Interfaces
  • Abstraction
  • Polymorphism
  • Conditional Statements

Categories

  • Basics
  • Kafka
  • Welcome

© 2025 · thecodestandard.com

Prev Next