Lecture
- To build a list that can grow infinitely large, we must use recursion.
Bits
- Computers stores information in memory as sequence of ones and zeros.
- When variables are declared in Java, the computer sets aside exactly enough bits to hold an object/thing of that type.
- Declaring an int sets a box of 32 bits.
- Declaring a double sets aside a box of 64 bits.
- Golden Rule of Equals (GRoE): In Java, the equals sign copies the bits from one variable to another variable.
- Everything in Java that is not a primitive is called a reference type.
- When an object of a reference type is instantiated:
- Java initializes memory for each instance variable of the class.
- Java then stores the address to the object as an integer to the variable. The
new
keyword finds a place in memory to allocate the object to, and then returns the address of the new object.
Parameter Passing
- Passing parameters to a function also follows the golden rule of equals.
- Bits are copied over into new variables defined in the function signature.
- Java is a purely pass by value language.
Comparison
- The
==
operator compares the bits in the two memory boxes. - To compare the content of two arrays, use
Arrays.equals