Inside the JVM — Part 01 (JVM Data Types)

Chamal Weerasinghe
4 min readApr 30, 2021
Photo by Garett Mizunaka on Unsplash

“What really matters is what’s on the inside” — Victoria Justice

We know the JVM is the wizard of Java executing programs on different platforms, If you want to get a better idea I suggest going through this article and video to know actually JVM and JRE.

After compilation of the Java program (This could be any language running on top of JVM, ex — Kotlin, Scala) the end result will be the byte code which is an intermediate code before reaching it into the machine level. Then when want to execute the program provide the following command,

java <classname>

After that, the irrespective JRE installed into the system will create a JVM instance for that program and execute the program. It is important to know that one JVM instance is only for one application only.

Number of Java Application Running = Number of Active JVM instances

But how? this is the BlackBox we are about to explore. 💡

Before diving into the JVM, Let’s first talk about the JVM variables, these are not the variables we are using inside the java language we are talking about those are the JVM variables.

JVM Variables

As we can see the main two data types are the primitive and reference type variables. primitive types are capable of holding the value itself and reference types hold the reference address of the value where it actually resides in the heap(Discussing this soon 😉).

1. Primitive Variables

The two floating-point types float and double, are conceptually associated with the 32-bit single-precision and 64-bit double-precision format IEEE 754. both the default value of these is positive zero.

Other non-floating-point types are called integral values, which are

byte, whose values are 8-bit signed two’s-complement integers, and whose default value is zero.

short, whose values are 16-bit signed two’s-complement integers, and whose default value is zero.

int, whose values are 32-bit signed two’s-complement integers, and whose default value is zero.

long, whose values are 64-bit signed two’s-complement integers, and whose
default value is zero.

char, whose values are 16-bit unsigned integers representing Unicode code
points in the Basic Multilingual Plane, encoded with UTF-16, and whose default value is the null code point (‘\u0000’)

As you can see all the values are treated as default in the Java language variables except long where it treats as 64bit value.

2. Reference Variables

When it comes to the reference variables there few like class, interface, and array also something that not mentioned in the chart is the null.

When it comes to the class data type, it always references instances of a class, as an example,

public class Employee { }Employee emp = new Employee()

The code above it shows the class and the instance of a class created using the “new” keyword, at that time the “class” variable reference not to the blueprint of the class, it stores the reference to the “emp” object (instance of the class).

The next one is the “interface” data type, it stores the reference to the instance of the implementation. Let’s look at the code below!

public interface UserRepository { }public class UsrRepoImpl implements UserRepository { }public class DBUtil {
UsrRepoImpl implementedInstance = new UsrRepoImpl();
}

In the above scenario, the interface datatype holding the “UserRepository” will not hold the reference to the “UserRepoImpl” but it holds the reference to the “implementedInstance” instance used inside the DBUtil class.

The other data type is the Array which is referencing arrays. Also, the null type which we mentioned above actually is referenced to nothing.

Also, there is a special base in JVM which is called the “WORD SIZE”, this has no static size and it can differ from one JVM instance to another, but there are certain rules to follow when implementing a word,
1. One word size should be able to hold any type of primitives.
2. Total of two words should be able to hold long and double values.

That’s all about the JVM data types! If you want to dive deeper and find about these please follow the reference which helps to clear your doubts. and in the next article, we are going to find out about the ClassLoader.

--

--