01pi logo

Computer Science (CS)

Interactive 01pi contents for Computer Science. Step-by-step descriptions of what is happening behind the scenes.

CS - Primitive Types
CS primitive types

Symbol table and memory allocation for primitive types in Java

There two types in Java: primitive types and objects. In this visualization memory organization during their definition and assignment is investigated.

Primitive types such as int, double are easy to understand. Both primitive type int b and object Point pA are represented by one memory location each. But similarity ends there.

Try it yourself

CS - Arrays of Primitive Types
CS primitive types

Symbol table and memory allocation for array of primitive types in Java

Variables are listed in the symbol table. Their content is kept in the memory. Variable refers to either a primitive type or an object in Java.

An array of a primitive type, such as int[] arrInt, is very different from primitive int a. An array of a primitive type is an object, which contains many primitives in it.

Try it yourself

CS - String Object
CS primitive types

Strings have sophisticated operations on the symbol table and the memory.

A String is an object in Java. A variable strA defined as String strA has interesting behavior.

What do you expect to get if you compare a string concatenation such as "A" + "B" with "AB".

Try it yourself

CS - Simple Objects
CS primitive types

Objects also have nontrivial symbol table and memory operations.

You can define objects in Java. Objects can be complex.

One of the simplest object one can think of is coordinate in 1D, Coor1D, which contains one number, possibly a primitive type such as a double.

Try it yourself

CS - Complex Objects
CS complex objects

Objects may contain objects in them. As a result, interesting symbol table and memory operations are needed.

Objects can contain other objects in them. That can be quite deep. It is not unusual to have objects within objects, contained in other objects.

Consider object Point1D, which represents a point in 1D. It has a coordinate, represented by Coor1D, and it has a name, represented by String. That is, our 1D point contains two objects in it.

Try it yourself