Let's go back to the basics.
Dr. Mackey begins the first lecture describing how Java works under the hood, in an easy-to-understand
high-level way. You start with compiling your .java source code using
javac <FileName>.java
. We can remember what this does because the "c" in javac stands
for compile. The compiler then converts the java source code into machine code, or byte code,
where a new .class file is generated. This machine code is then able to be ran with
java <FileName>
. This code is running in Java's Java Virtual Machine (JVM),
which is important because there are many different CPUs with many different architectures. With JVM,
our code is platform-independent and can be run nearly anywhere.

Pardon my poor handwriting and sloppy drawings. Going forward, let's pretend that it is legible and you perfectly understand what I am trying to convey.
Classes vs Objects
What is the difference between a class and an object? A class can be defined as a blueprint of states (memory, variables) and behaviors (methods/constructors). An object is an instance of a class.
Speaking of states/variables, there are two types.
- Primitive types: int, double, float, char, long, short, byte, and boolean
- Reference types: everything else, such as Strings, arrays, and other objects
More on primitive types
Type | Size |
---|---|
int | 4 bytes |
double | 8 bytes |
float | 4 bytes |
long | 8 bytes |
short | 2 bytes |
Because ints are 4 bytes (32 bits), they can hold 2^32 numbers. The first bit is reserved for the sign of the number, so it ranges from -2,147,483,648 to 2,147,483,647. It's probably wise to memorize this and the table above, since I think it might be on a quiz.
Syntax Refresh
To declare a variable:
VariableType variableName;
To initialize a variable:
variableName = 3; // primitive types
variableName = new VariableType(); // reference types
To declare + initialize a variable:
VariableType variableName = new VariableType();
...in case you forgot. It happens.
Possible Exam Questions
int[] x = new int[5];
long y = 123;
double = 456.78;
UACat c1 = new UACat();
UACat c2 = new UACat();
UACat c3 = new UACat();
UACat c4 = new UACat();
c1 = c4;
c3 = c2;
c2 = c4;
c1.name = "A";
c2.name = "B";
c3.name = "C";
c4.name = "D";
System.out.print(c1.name + c2.name + c3.name + c4.name);
