ORM Framework features, advantages, and disadvantages
What methods are available in the Object class (4)?
.clone
.hashcode
.equals
.toString
How would you clone an object?
First, tag the class with the Cloneable marker interface.
Next, invoke clone().
The clone method is declared in java.lang.Object and does a shallow copy.
What is an enhanced for loop?
Enhanced for loops allow easier traversal of Collections (actually any arrays or Iterables)
Syntax - for (object x : collection){. . .}
What is try-with-resources?
What interface must the resource implement to use this feature?
How would you make numbers in your code more readable?
Use the underscore ( _ ) for numeric literals; must be placed between numbers (EX - 45,000 = 45_000)
What are covariant return types?
A method is allowed to return objects that are child classes of the return type.
Also, when overriding a method, the return type of the new method can be a child class of the original return type
What are 3 usages of the super() keyword?
Can you overload / override a main method? static? private? default? protected?
Main method - overload, cannot override b/c is static method.
Static method - overload, cannot override b/c belongs to class (not inherited).
Private method - overload, cannot override b/c doesn’t get inherited.
Default method - both.
Protected method - both (override if inherited).
What is the difference between FileReader and BufferedReader?
FileReader is just a Reader which reads a file, so it reads characters and uses the platform-default encoding.
BufferedReader reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines (e.g. can read one line at a time).
You can wrap a BufferedReader around a FileReader
How would you pass multiple values with a single parameter into a method?
Use varargs
What is static block?
- executed only once - upon creation of the first object of a class or access to static methods of a class
What are static imports?
a static method or variable from a class - syntax: import static
How would you clone an object?
use the .clone() method inherited from object class
What makes a class immutable (6)?
If 2 objects are equal, do they have the same hashcode? If not equal?
If two objects have the same hashcode then they are NOT necessarily equal.
But if objects are equal, then they MUST have same hashcode.
What data types are supported in switch statements (6)?List all non-access modifiers?
List all non-access modifiers (9)?
Which collections cannot hold null values (4)?
HashTable
TreeSet
ArrayDeque
PriorityQueue
What is the .forEach() merthod in Java 8?
The forEach() method accepts what is called a functional interface as its parameter (specifically a Consumer), which the lambda expression ( -> ) then implements at runtime.
If 2 interfaces have default methods and you implement both, what happens?
The code will NOT compile unless you override the method.
However, the code WILL compile if one interface is implemented further up in the class hierarchy than the other - in this case, the closest method implementation in the hierarchy will be called.
If 2 interfaces have same variable names and you implement both, what happens?
The code will compile unless you make a reference to the variable (this is an ambiguous reference).
You must explicitly define the variable by using the interface name: int a = INTERFACENAME.a;
Why does HashTable not take null key?
The HashTable hashes the keys given as input, and the null value cannot be hashed
What new syntax for creating variables was introduced with Java 10?
The var keyword, with type inference