1/60
A set of flashcards covering important concepts related to Java interfaces and various design patterns.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What describes the ___________, but does not describe the ____________?
Interfaces describe the what, but they do not describe the how.
What keyword replaces 'class' when declaring an interface in Java?
interface
Can an interface be instantiated directly (e.g., new Fruit())?
No — interfaces have no constructors and cannot be instantiated directly.
What is the declared type vs. dynamic type in Java?
Declared type is set at compile time by declaration; dynamic type is set at runtime by assignment.
Can an interface be the dynamic type of a variable?
No — all dynamic types are classes; interfaces can only be declared types.
What does 'coding to the interface' mean?
All variable, field, argument, and return types use interface types instead of class types.
What must variables in an interface be?
Constants — public static final.
What visibility must interface methods be declared as?
public
Can interface methods be final?
No.
What is a primary operation?
A method that needs direct access to private data to do anything useful.
What is a secondary operation?
A method that does NOT need direct access to private data.
What keyword is used to add a method body (default implementation) to an interface?
default
When should default methods be used in an interface?
Only to implement secondary methods.
Can an interface have private data fields?
No — interfaces cannot contain private data fields.
Can secondary methods always be written using primary methods?
Yes — secondary methods should always be implemented using primary operations.
Can primary methods be implemented as if they were secondary?
No — primary methods require direct access to private data.
What is the benefit of using default methods (factoring out code)?
They allow common code to be written once in the interface and work for any implementation.
What happens when an implementing class does not provide its own version of a default method?
It automatically uses the default implementation provided in the interface.
Can a default method in an interface be overridden by an implementing class?
Yes — implementing classes can override default methods.
What does 'implements' mean in Java?
A class provides code for all behaviors specified by an interface.
Does the Java compiler check that a method was implemented correctly (matching behavior)?
No — Java only checks that the method signature exists.
What is interface inheritance and how is it written?
One interface can extend another using the 'extends' keyword.
If class C implements child interface, does it also need to fulfill the parent interface?
Yes — implementing the child interface requires fulfilling both the child and parent interface contracts.
Can constructors be inherited when a class extends another class?
No — constructors are NOT inherited.
What is polymorphism in Java?
Java decides which method body to execute at runtime based on the dynamic type of the receiver object.
What is an abstract class?
A 'partial' class that provides bodies for some but not all methods.
What is the difference between an abstract class and an interface?
Abstract classes can have private data fields; interfaces cannot.
When is an abstract class useful over an interface?
When you want to define shared data fields and concrete methods.
An abstract class with no private data fields is essentially equivalent to what?
An interface.
What is a design pattern?
A general, reusable solution to a commonly occurring problem in software design.
What is the Template Method design pattern?
A pattern where an abstract class defines hook methods and template methods.
What are hook methods and template methods in the Template Method pattern?
Hook methods are primary/abstract; template methods are secondary/default.
What is the Factory Method design pattern?
A pattern that creates an indirection for object construction.
What is the benefit of the Factory Method pattern?
Only the factory constructor call changes if the implementation needs to change.
How is the Factory Method pattern simplified for JUnit tests?
A private method in the test class acts as the factory.
What is the Observer Pattern?
A pattern where subjects maintain a list of registered observers.
What are the two roles in the Observer Pattern?
Subject and Observer/Listener.
What is polling in the context of the Observer Pattern?
An observer continuously asks the subject 'has anything changed?'.
What is a callback in the Observer Pattern?
An observer registers interest with a subject; the subject calls back when an event occurs.
Can a subject have multiple observers?
Yes — a subject can have many registered observers.
What is the MVC architectural pattern?
Model-View-Controller — separates the UI from business logic.
What is the Model in MVC?
Contains entity objects and business rules; must not reference the UI.
What is the View in MVC?
The low-level UI code.
What is the Controller in MVC?
Connects the View and Model.
How does the Observer Pattern integrate with MVC?
The Controller acts as an observer of the View.
What part of MVC changes most often?
The View.
Which MVC components change when the UI is ported or redesigned?
View (will change); Controller (may change).
What is the difference between a design pattern and an architectural pattern?
Design patterns solve a specific problem; architectural patterns structure the program as a whole.
What is a changelist in a code review?
A set of changes to source code that are submitted for review.
What is a 'round' in a code review?
A complete round-trip between author and reviewer.
What does LGTM stand for in code reviews?
'Looks good to me' — the reviewer's approval.
What is CI/CD and why is it used in code reviews?
Continuous Integration/Continuous Delivery — automates checking of code.
What order should feedback be given in a code review?
Start with high-level changes; work down to low-level changes.
Why should code review feedback avoid being directed at the person?
To prevent misunderstandings — feedback should target the code, not the author.
What is a stalemate in a code review?
When the reviewer won't approve until more changes are made.
What should you do if the same error appears repeatedly in a code review?
Comment on it the first few times, then ask the author to find remaining instances.
What is the scope rule of a code review?
Don't review code outside of the changelist.
What are Agile's typical workflow stages?
Inception, Construction/Iteration, Testing, Deployment, Feedback and Review.
What is the List interface in Java an example of?
A built-in Java interface.
What is the Grid interface example used to illustrate?
Trade-offs between implementations.
What is the Decorator Pattern?
Extending an interface you can't edit by creating a child interface.