Java Interfaces and Design Patterns

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/60

flashcard set

Earn XP

Description and Tags

A set of flashcards covering important concepts related to Java interfaces and various design patterns.

Last updated 7:48 PM on 4/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

61 Terms

1
New cards

What describes the ___________, but does not describe the ____________?

Interfaces describe the what, but they do not describe the how.

2
New cards

What keyword replaces 'class' when declaring an interface in Java?

interface

3
New cards

Can an interface be instantiated directly (e.g., new Fruit())?

No — interfaces have no constructors and cannot be instantiated directly.

4
New cards

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.

5
New cards

Can an interface be the dynamic type of a variable?

No — all dynamic types are classes; interfaces can only be declared types.

6
New cards

What does 'coding to the interface' mean?

All variable, field, argument, and return types use interface types instead of class types.

7
New cards

What must variables in an interface be?

Constants — public static final.

8
New cards

What visibility must interface methods be declared as?

public

9
New cards

Can interface methods be final?

No.

10
New cards

What is a primary operation?

A method that needs direct access to private data to do anything useful.

11
New cards

What is a secondary operation?

A method that does NOT need direct access to private data.

12
New cards

What keyword is used to add a method body (default implementation) to an interface?

default

13
New cards

When should default methods be used in an interface?

Only to implement secondary methods.

14
New cards

Can an interface have private data fields?

No — interfaces cannot contain private data fields.

15
New cards

Can secondary methods always be written using primary methods?

Yes — secondary methods should always be implemented using primary operations.

16
New cards

Can primary methods be implemented as if they were secondary?

No — primary methods require direct access to private data.

17
New cards

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.

18
New cards

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.

19
New cards

Can a default method in an interface be overridden by an implementing class?

Yes — implementing classes can override default methods.

20
New cards

What does 'implements' mean in Java?

A class provides code for all behaviors specified by an interface.

21
New cards

Does the Java compiler check that a method was implemented correctly (matching behavior)?

No — Java only checks that the method signature exists.

22
New cards

What is interface inheritance and how is it written?

One interface can extend another using the 'extends' keyword.

23
New cards

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.

24
New cards

Can constructors be inherited when a class extends another class?

No — constructors are NOT inherited.

25
New cards

What is polymorphism in Java?

Java decides which method body to execute at runtime based on the dynamic type of the receiver object.

26
New cards

What is an abstract class?

A 'partial' class that provides bodies for some but not all methods.

27
New cards

What is the difference between an abstract class and an interface?

Abstract classes can have private data fields; interfaces cannot.

28
New cards

When is an abstract class useful over an interface?

When you want to define shared data fields and concrete methods.

29
New cards

An abstract class with no private data fields is essentially equivalent to what?

An interface.

30
New cards

What is a design pattern?

A general, reusable solution to a commonly occurring problem in software design.

31
New cards

What is the Template Method design pattern?

A pattern where an abstract class defines hook methods and template methods.

32
New cards

What are hook methods and template methods in the Template Method pattern?

Hook methods are primary/abstract; template methods are secondary/default.

33
New cards

What is the Factory Method design pattern?

A pattern that creates an indirection for object construction.

34
New cards

What is the benefit of the Factory Method pattern?

Only the factory constructor call changes if the implementation needs to change.

35
New cards

How is the Factory Method pattern simplified for JUnit tests?

A private method in the test class acts as the factory.

36
New cards

What is the Observer Pattern?

A pattern where subjects maintain a list of registered observers.

37
New cards

What are the two roles in the Observer Pattern?

Subject and Observer/Listener.

38
New cards

What is polling in the context of the Observer Pattern?

An observer continuously asks the subject 'has anything changed?'.

39
New cards

What is a callback in the Observer Pattern?

An observer registers interest with a subject; the subject calls back when an event occurs.

40
New cards

Can a subject have multiple observers?

Yes — a subject can have many registered observers.

41
New cards

What is the MVC architectural pattern?

Model-View-Controller — separates the UI from business logic.

42
New cards

What is the Model in MVC?

Contains entity objects and business rules; must not reference the UI.

43
New cards

What is the View in MVC?

The low-level UI code.

44
New cards

What is the Controller in MVC?

Connects the View and Model.

45
New cards

How does the Observer Pattern integrate with MVC?

The Controller acts as an observer of the View.

46
New cards

What part of MVC changes most often?

The View.

47
New cards

Which MVC components change when the UI is ported or redesigned?

View (will change); Controller (may change).

48
New cards

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.

49
New cards

What is a changelist in a code review?

A set of changes to source code that are submitted for review.

50
New cards

What is a 'round' in a code review?

A complete round-trip between author and reviewer.

51
New cards

What does LGTM stand for in code reviews?

'Looks good to me' — the reviewer's approval.

52
New cards

What is CI/CD and why is it used in code reviews?

Continuous Integration/Continuous Delivery — automates checking of code.

53
New cards

What order should feedback be given in a code review?

Start with high-level changes; work down to low-level changes.

54
New cards

Why should code review feedback avoid being directed at the person?

To prevent misunderstandings — feedback should target the code, not the author.

55
New cards

What is a stalemate in a code review?

When the reviewer won't approve until more changes are made.

56
New cards

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.

57
New cards

What is the scope rule of a code review?

Don't review code outside of the changelist.

58
New cards

What are Agile's typical workflow stages?

Inception, Construction/Iteration, Testing, Deployment, Feedback and Review.

59
New cards

What is the List interface in Java an example of?

A built-in Java interface.

60
New cards

What is the Grid interface example used to illustrate?

Trade-offs between implementations.

61
New cards

What is the Decorator Pattern?

Extending an interface you can't edit by creating a child interface.