1. Definitions:
- Accessor method: A “getter” that returns the value of a private variable.
- Actual parameter: The value you pass when calling a method.
- Explicit parameter: The parameter declared in the method’s definition.
- Formal parameter: Another term for the parameter declared in the method.
- Implicit parameter: The hidden reference to the current object (via instance variables).
- Mutator method: A “setter” that changes a private variable’s value.
- Null reference: Indicates no object is referenced.
- Pass by reference: The reference (address) is passed; changes to arrays affect the original.
- Pass by value: A copy is passed; changes inside the method don’t affect the original.
- Promoting: Converting a smaller data type to a larger one automatically.
- Scope: The area of code where a variable is accessible.
- String literal: A fixed sequence of characters like “Hello”.
2. Variable Scope and Initialization:
- Local variables must be explicitly initialized before use.
- Instance variables are automatically given default values.
- Local variables vanish after the method finishes.
3. What’s Happening in RAM:
- String m = “My name”; A String with “My name” is created;
m
points to it. - String r = “Your name”; Similarly, a String for “Your name” is created;
r
points to it. - r = m; Now,
r
points to the same object asm
. - m = null;
m
no longer points to the object;r
still does.
4. compareTo(), compareToIgnoreCase(), and equals():
- compareTo(): Compares strings by Unicode values; case-sensitive.
- compareToIgnoreCase(): Like compareTo but ignores case.
- equals(): Checks if two strings have the same content.
5. The Object Class:
- equals(): Tests if two objects are logically equal (by default, checks references).
- hashCode(): Returns an integer for an object, used in hash-based collections.
- toString(): Provides a String representation of an object.
6. Class Downcasting:
- Converting a superclass reference to a subclass reference.
- Caution: Only do this if the object is actually an instance of the subclass; otherwise, you get a ClassCastException.
7. Class Casting:
- Refers mainly to downcasting and converting between class types.
- Essentially, it’s about converting references from one type to another.
8. PDT Casting:
- Converting between primitive data types.
- Caution: Downcasting (larger to smaller types) can lose data; booleans can’t be cast.
9. Static vs. Instance Methods:
- Static/class methods: Belong to the class and can be called without an instance.
- Instance/member methods: Require an object because they operate on instance data.