Java Collections Class, Map Interface
- In the Collections Class, what is the difference between Sorted Set and Sorted Map?
Answer:
- Map: A map from keys to at most one value each. (map does not extend Collection)
- SortedMap: A map whose keys are sorted (extends Map)
- What is an Anonymous Inner Class?
Answer:
When a local inner class seems too much for your needs, you can declare anonymous classes that extend a class or implement an interface. These classes are defined at the same time they are instantiated using the keyword new.
- What is the Factory Method design pattern used for?
Answer:
Factory and Abstract Factory represent design patterns that are both good at decoupling applications.
Creational Design Pattern
The factory method creates objects through inheritance. To create objects using the Factory method, you need to extend a class and override a factory method.
- In which class is the getClass() method defined in ?
Answer:
The getClass() method is defined in the Object class.
- What does the keyword transient indicate?
Answer:
The reserved word transient indicates that this field is not saved during serialization.
- What is a reference in Java?
Answer:
Java manipulates objects by reference, and all object variables are references. However, Java does not pass method arguments by reference. Java passes method arguments by value.
- What happens when you declare a reference variable as a data field within a class but do not instantiate an object for it in a constructor?
Answer:
This field will be initialized to null.
- What must be remembered when inheriting from an abstract class?
Answer:
Only non-abstract subclasses of an abstract class can be instantiated.
- Which facts hold true with respect to thread creation in Java?
Answer:
- To create a Thread, pass a runnable object to the Thread constructor.
- Subclass the Thread so that it defines its own run() method. isAvlie() returns true if a thread has been started, and the run() method has not yet exited.
- What are the characteristics of constructors?
Answer:
- Constructors can have normal access modifiers.
- Constructors can take arguments including "var-args"
- Constructors must have the same name as the class.
- Constructors can not be marked static.
- Constructors can not be marked final or abstract.