prep code
A form of pseudocode, to help you focus on the logic without stressing about syntax
Testing code
A class or methods that will test the real code and validate that it’s doing the right thing
Real code
The actual implementation of the class.
Coding strategy
What happens in Integer.parseInt() if the thing you pass isn’t a number? And does it recognize spelled-out numbers, like “three”?
Integer.parseInt() works only on Strings that represent the ascii values for digits (0, 1, 2,3, 4, 5, 6, 7, 8, 9). If you try to parse something like “two”, the code will blow up at runtime
Difference between for and while
A while loop has only the boolean test; it doesn’t have a built-in initialization or iteration.
If you know how many times to loop, a for loop is cleaner
Enhance for loop
Easier to iterate over all the elements in an array
Casting primitives
A long is bigger than an int and the compiler can’t be sure where that long has been
ArrayList vs. Array
Non Short Circuit Operators (&, |)
When used in boolean expressions, the & and | operators act like their && and “” counterparts, except that they force the JVM to always check both sides of the expression
Package
How does a full-name really help package? What’s to prevent two people from giving a class the same package name?
Java has a naming convention that usually prevents this from happening, as long as developers adhere to it
Does import make my class bigger? Does it actually compile the imported class or package into my code?
2. Import is simply the way you give Java the full name of a class
How come I never had to import the String class?
Because java.lang package sort of “pre-imported” for free
Inheritance
2. Subclass extends the superclass
Subclass
Why isn’t Instance variable overriden
Because they don’t need to be. They don’t define any special behaviors, so a subclass can give an inherited instance variable any value it chooses
What if the superclass wants to use the subclass version of the method?
No, there’s no sort of reverse or backward inheritance
What if I want to use BOTH the superclass version and my overriding subclass version of a method?
we can do so using super.method(), which calls the inherited version, then comes back to do your own subclass-specific code
Are there any practical limits on the levels of subclassing? How deep can you go?
Most are no more than one or two levels deep. It usually makes more sense to keep your inheritance trees shallow
Can you make a method final, without making the whole class final?
If you want to protect a specific method from being overridden, mark the method with the final modifier.
Mark the whole class as final if you want to guarantee that none of the methods in that class will ever be overridden
Why would you ever want to make a final class?
A final class prevent from overriden
Overload method
A different method that happens to have the same method name. It has nothing to do with inheritance and polymorphism
Concrete class
Those that are specific enough to be instantiated