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.

  1. Primitive types: int, double, float, char, long, short, byte, and boolean
  2. 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

How much memory does this use?
int[] x = new int[5];
long y = 123;
double = 456.78;

x is an array of 5 ints, which are 4 bytes each. 5*4 = 20. A long and double are each 8 bytes. 20 + 8 + 8 = 36 bytes.
What does the following print out?
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);

DDCD. Keep in mind that when an object loses its pointer or reference, it is flagged for garbage collection. Also note that when you assign a variable to another, what you are actually doing is pointing to the other variable's object. Below is the work for the question.
...