All fields

“Design Patterns in Java” in Information Technology

120 questions across 6 technologies.

Information Technology

120 questions in 6 technologies

#QuestionTechnologyTopicLevel
1What is the difference between composition and inheritance as ways to reuse code, and why does the design principle "favor composition over inheritance" generally guide modern Java design (including many design patterns themselves)? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
2What is the Strategy pattern, and how do Java 8's functional interfaces and lambdas make implementing it significantly more concise than the traditional interface-plus-implementation-classes approach? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
3What is the Adapter pattern, and when would you use it to make an existing class compatible with an interface it wasn't originally designed to implement? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
4How would you implement the Visitor pattern in Java to add new operations to an existing class hierarchy without modifying those classes, and how do Java's sealed classes and pattern matching (switch expressions) provide a modern alternative? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
5What is the Singleton pattern, and how would you implement a thread-safe Singleton in Java? Java › Design Patterns in JavaJavaDesign Patterns in JavaBeginner
6How would you implement the Observer pattern in Java, and how does it compare to using the built-in PropertyChangeSupport or a reactive streams library? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
7How would you implement the Decorator pattern in Java, and how does java.io's InputStream/OutputStream class hierarchy exemplify this pattern in the JDK itself? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
8How would you implement the Proxy pattern to add lazy initialization to an expensive-to-create object, and how does this differ structurally from the Decorator pattern despite both wrapping an object behind a shared interface? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
9What is the Factory Method pattern's simplest form -- a basic static factory returning different subtype instances based on input -- and why might you prefer it over exposing constructors directly? Java › Design Patterns in JavaJavaDesign Patterns in JavaBeginner
10What is the Template Method pattern, and how is it used to define the skeleton of an algorithm while letting subclasses customize specific steps? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
11How would you implement the Composite pattern to treat individual objects and groups of objects uniformly, such as a file system with files and directories? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
12How would you implement the Dependency Injection pattern manually (without a framework like Spring) using constructor injection, and what testability benefits does this provide? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
13How would you use the Chain of Responsibility pattern to implement a request-processing pipeline (such as middleware-style validation/authentication/logging), and how does this relate conceptually to servlet filters or web framework middleware? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
14How does the Builder pattern solve the "telescoping constructor" problem, and how would you implement it for a class with many optional parameters? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
15When is it a mistake to force a 'classic' design pattern into idiomatic JavaScript? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptAdvanced
16What is the Factory Method pattern, and how does it differ from the simpler Static Factory Method idiom (like List.of() or Optional.of())? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
17How is the Decorator pattern typically implemented in JavaScript? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptIntermediate
18What is the Command pattern and where is it useful in JavaScript apps? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptAdvanced
19What are design patterns, and how are the Singleton, Adapter, and Strategy patterns typically implemented in C#? C# › Design Patterns in C#C#Design Patterns in C#Advanced
20What is the Singleton pattern and how is it implemented in JavaScript? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptBeginner
21How do you implement the Observer pattern in JavaScript? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptIntermediate
22What is the Strategy pattern and how does it help avoid large if/else chains? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptAdvanced
23How do you implement the Proxy pattern using JavaScript's built-in Proxy object? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptAdvanced
24What is the Factory pattern, and how does it differ from calling a class constructor directly? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptIntermediate
25What is the Adapter pattern and why is it useful when integrating third-party code? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptAdvanced
26What is the Module pattern and what problem does it solve? JavaScript › Design Patterns in JavaScriptJavaScriptDesign Patterns in JavaScriptBeginner
27What is Domain-Driven Design (DDD), and how do its concepts of entities, value objects, and aggregates apply to a Node.js codebase? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsAdvanced
28What is a non-static (inner) class in Java, and how does its relationship to an enclosing instance differ from a regular top-level class? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesBeginner
29What is the fundamental difference between an interface and an abstract class in Java, and when would you choose one over the other? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesBeginner
30Why was the modern java.time API (introduced in Java 8) created to replace the legacy Date and Calendar classes, and what specific problems did the old classes have? Java › Java Date & Time API (java.time)JavaJava Date & Time API (java.time)Beginner
31How does the ServiceLoader mechanism (java.util.ServiceLoader) provide a standardized way to discover and load implementations at runtime without hardcoding class names, and how does it relate to class loading? Java › Class Loading & Bytecode VerificationJavaClass Loading & Bytecode VerificationIntermediate
32How would you implement a callback or event listener using an anonymous class, and how does this same use case increasingly get replaced by lambda expressions for functional interfaces in modern Java? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
33How would you implement the 'mixin' pattern in Java using default methods on an interface, letting a class gain reusable behavior without traditional inheritance? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
34How do the requires and exports directives in a module-info.java file work together to define a module's dependencies and public API surface? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Intermediate
35How would you design a fluent, chainable validation API using functional interfaces, similar to how Comparator's thenComparing() works, but for validation rules that accumulate error messages rather than short-circuiting on the first failure? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
36How would you implement the classic Iterator design pattern using a private non-static inner class, letting the inner Iterator implementation access the outer collection's private internal state directly? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
37How would you decide between using a static nested class, a non-static inner class, a local class, an anonymous class, or a lambda expression for a given design scenario, weighing their respective trade-offs? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
38How is the 'diamond problem' (a class implementing two interfaces with conflicting default methods) resolved in Java, and what rule determines which default method 'wins' or whether the compiler requires explicit resolution? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
39How is the Factory pattern commonly applied in Node.js applications, and what problem does it solve? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsIntermediate
40What is the Singleton pattern, and what are the specific risks of using it in a Node.js application? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsIntermediate
41What is Dependency Injection, and how is it typically implemented in Node.js given the language has no built-in DI container? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsIntermediate
42What is the Strategy pattern, and how would you apply it to support multiple payment providers in a Node.js checkout service? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsIntermediate
43What is a Facade pattern, and how might it be used to simplify a Node.js application's interaction with several third-party SDKs? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsAdvanced
44How does styled components let you write CSS directly inside your JavaScript files? React › Styling in React (CSS Modules, Styled Components & Tailwind)ReactStyling in React (CSS Modules, Styled Components & Tailwind)Intermediate
45What is error propagation, and how does an uncaught error in a nested function behave? JavaScript › Error HandlingJavaScriptError HandlingIntermediate
46What are the five formal properties an equals() implementation must satisfy according to its documented contract (reflexive, symmetric, transitive, consistent, and null-handling)? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
47What is a static nested class, and why is it generally preferred over a non-static inner class when the nested class doesn't actually need access to the enclosing instance? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
48What are static methods on an interface, and how do they differ from default methods in terms of inheritance and typical use case? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
49How would you use an abstract class to implement the Template Method pattern, defining a fixed algorithm skeleton with some steps left abstract for subclasses to fill in? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
50Can an interface extend multiple other interfaces simultaneously, and how does this differ from a class's single-inheritance restriction for abstract/concrete classes? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
51What is the purpose of declaring an abstract class with a protected constructor, and how does this pattern communicate the class's intended usage to other developers? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
52How would you calculate a person's age or the number of days until a recurring annual event (like a birthday) using ChronoUnit, and what's a common pitfall with leap-year birthdays (February 29)? Java › Java Date & Time API (java.time)JavaJava Date & Time API (java.time)Intermediate
53How does the ServiceLoader/Service Provider Interface pattern integrate with JPMS using the 'uses' and 'provides ... with' directives, replacing the older META-INF/services file-based mechanism? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Intermediate
54What is snapshot testing and what's a common pitfall with it? JavaScript › Debugging, Testing & ToolingJavaScriptDebugging, Testing & ToolingAdvanced
55Why is BigInt generally the wrong tool for representing monetary amounts with decimals, like $19.99? JavaScript › Numbers, Math & BigIntJavaScriptNumbers, Math & BigIntAdvanced
56How does the same class name loaded by two different ClassLoaders create two genuinely distinct types in the JVM, and what problems does this cause (such as with singletons or ClassCastException)? Java › Class Loading & Bytecode VerificationJavaClass Loading & Bytecode VerificationAdvanced
57How does a thread context ClassLoader (Thread.currentThread().getContextClassLoader()) solve the problem of a core JDK class needing to load an application-provided implementation class, given parent delegation normally prevents this? Java › Class Loading & Bytecode VerificationJavaClass Loading & Bytecode VerificationAdvanced
58How does the getClass() versus instanceof choice in an equals() implementation affect whether subclasses can be considered equal to their superclass instances, and what's the Liskov Substitution Principle tension involved? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
59How would you correctly implement equals() and hashCode() for a class in an inheritance hierarchy where the superclass itself defines meaningful equality-relevant fields, without breaking the contract when subclasses add their own fields? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
60How do local classes (defined within a method body) and anonymous classes differ in their capabilities and use cases, particularly regarding capturing local variables and reusability? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
61How would you use a local class defined within a method to implement a fairly complex, stateful callback that needs multiple methods and constructor parameters, where a lambda expression genuinely wouldn't suffice? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
62How would you use an interface with only static and default methods (no abstract methods at all) to build a fluent, extensible utility API, and what's a real JDK example of this pattern? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
63How would you use an abstract class combined with the Non-Virtual Interface (NVI) idiom to enforce that certain methods are always called in a specific pattern, even when subclasses override customizable parts? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
64How would you implement a custom TemporalAdjuster to calculate business-specific date logic (like 'the next business day, skipping weekends and holidays')? Java › Java Date & Time API (java.time)JavaJava Date & Time API (java.time)Advanced
65What is the difference between 'requires' and 'requires transitive', and how does transitive dependency propagation work in the module system? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Advanced
66What are the two primary ways to create a thread in Java (extending Thread versus implementing Runnable), and which is generally preferred? Java › Concurrency & ThreadsJavaConcurrency & ThreadsBeginner
67How do you create a custom annotation in Java, and what role do @Retention and @Target play? Java › AnnotationsJavaAnnotationsIntermediate
68What are the immutable collection factory methods (List.of(), Set.of(), Map.of()) introduced in Java 9, and how do they differ from Collections.unmodifiableList()? Java › Collections FrameworkJavaCollections FrameworkIntermediate
69What is the synchronized keyword, and how does it use Java's intrinsic (monitor) locks to prevent race conditions on shared mutable state? Java › Concurrency & ThreadsJavaConcurrency & ThreadsIntermediate
70What is the difference between wait()/notify()/notifyAll() (Object's intrinsic monitor methods) and the newer java.util.concurrent tools, and why are the older methods considered error-prone? Java › Concurrency & ThreadsJavaConcurrency & ThreadsIntermediate
71How do you add fields, constructors, and methods to a Java enum, and how would you implement an enum representing planets with mass and radius that calculates surface gravity? Java › EnumsJavaEnumsIntermediate
72How does method overriding with super work in JavaScript classes? JavaScript › Classes & Class SyntaxJavaScriptClasses & Class SyntaxAdvanced
73How does Java's annotation processing API (javax.annotation.processing) enable compile-time code generation frameworks like Lombok or Dagger, and what are its key limitations? Java › AnnotationsJavaAnnotationsAdvanced
74How would you design a custom annotation-driven caching mechanism (similar to Spring's @Cacheable) using a dynamic proxy combined with reflection? Java › AnnotationsJavaAnnotationsAdvanced
75How does Java's virtual threads feature (Project Loom, finalized in Java 21) fundamentally change the thread-per-task model for high-concurrency applications, and how do they differ from traditional platform threads? Java › Concurrency & ThreadsJavaConcurrency & ThreadsAdvanced
76How does Java implement enums under the hood at the bytecode level (extending java.lang.Enum), and what makes them inherently thread-safe and serialization-safe as singletons? Java › EnumsJavaEnumsAdvanced
77How would you build an interactive CLI wizard that prompts the user for multiple pieces of input using a library like Inquirer.js? Node.js › CLI Tools & Scripting with Node.jsNode.jsCLI Tools & Scripting with Node.jsAdvanced
78What does the node:util.types module provide, and how does it differ from JavaScript's built-in typeof operator? Node.js › Core Node.js ModulesNode.jsCore Node.js ModulesIntermediate
79How do you format a date for a specific locale without a library? JavaScript › Date, Time & Internationalization (Intl API)JavaScriptDate, Time & Internationalization (Intl API)Intermediate
80How would you use TemporalAdjusters to compute dates like 'the next Monday' or 'the last day of the month' relative to a given LocalDate? Java › Java Date & Time API (java.time)JavaJava Date & Time API (java.time)Intermediate
81How do you handle out-of-range writes to a TypedArray safely? JavaScript › ArrayBuffer, TypedArrays & Binary DataJavaScriptArrayBuffer, TypedArrays & Binary DataAdvanced
82What is the Temporal API and what problem does it solve? JavaScript › Date, Time & Internationalization (Intl API)JavaScriptDate, Time & Internationalization (Intl API)Advanced
83What is event bubbling? JavaScript › DOM & EventsJavaScriptDOM & EventsBeginner
84What is the difference between calling Thread.start() and Thread.run() directly, and why is calling run() directly a common beginner mistake? Java › Concurrency & ThreadsJavaConcurrency & ThreadsBeginner
85What is IndexedDB and how does it differ from a simple key-value store? JavaScript › Browser Storage & Web APIsJavaScriptBrowser Storage & Web APIsIntermediate
86How do you delegate from one generator to another using yield*? JavaScript › Iterators & GeneratorsJavaScriptIterators & GeneratorsIntermediate
87How do annotations with elements (parameters) work, including default values and the special `value` element? Java › AnnotationsJavaAnnotationsIntermediate
88What is the purpose of the Deque interface, and how does it unify both stack (LIFO) and queue (FIFO) behavior in a single interface? Java › Collections FrameworkJavaCollections FrameworkIntermediate
89How does PriorityQueue work internally (as a binary heap), and what ordering does it use by default versus with a custom Comparator? Java › Collections FrameworkJavaCollections FrameworkIntermediate
90How would you implement an enum that also implements an interface, and what's the benefit of having different enum constants provide different behavior through a shared interface contract? Java › EnumsJavaEnumsIntermediate
91How would you implement a generic Stack<T> class from scratch, demonstrating how a self-contained generic data structure is typically structured? Java › GenericsJavaGenericsIntermediate
92How would you write a generic interface (like a custom Repository<T, ID> pattern common in data-access layers) and implement it for a specific entity type? Java › GenericsJavaGenericsIntermediate
93How does sort() compare values by default, and how do you fix numeric sorting? JavaScript › Arrays & Array MethodsJavaScriptArrays & Array MethodsAdvanced
94What's the difference between the capturing and bubbling phases of event propagation? JavaScript › DOM & EventsJavaScriptDOM & EventsAdvanced
95How does mark-and-sweep garbage collection actually determine which objects are reachable? JavaScript › Memory Management & Garbage CollectionJavaScriptMemory Management & Garbage CollectionAdvanced
96How would you read custom annotations at runtime using reflection to implement annotation-driven behavior, such as a simple dependency injection or validation framework? Java › AnnotationsJavaAnnotationsAdvanced
97How do you choose between HashMap, LinkedHashMap, and TreeMap based on their different ordering guarantees and performance characteristics? Java › Collections FrameworkJavaCollections FrameworkAdvanced
98How does TreeMap/TreeSet's red-black tree implementation guarantee O(log n) operations, and what role does the Comparable/Comparator interface play in maintaining sorted order? Java › Collections FrameworkJavaCollections FrameworkAdvanced
99How would you implement the Strategy pattern using an enum with constant-specific method bodies, and how does this compare to a traditional interface-based Strategy implementation? Java › EnumsJavaEnumsAdvanced
100How would you use an EnumMap combined with a switch expression to implement a state machine, and what compile-time safety benefits does an exhaustive switch over an enum provide? Java › EnumsJavaEnumsAdvanced
101How would you handle adding behavior to an enum where the number of constants might grow very large or needs to be data-driven rather than hardcoded at compile time, and why might a class-based registry be more appropriate in that scenario? Java › EnumsJavaEnumsAdvanced
102How does exception handling interact with performance, particularly regarding the cost of filling in a stack trace, and how would you optimize exception usage in a performance-critical hot path? Java › ExceptionsJavaExceptionsAdvanced
103How would you implement a generic builder pattern with a self-referential generic type parameter (the 'curiously recurring generic pattern', <T extends Builder<T>>) to support fluent method chaining that correctly returns the actual subclass type in an inheritance hierarchy? Java › GenericsJavaGenericsAdvanced
104How would you implement a generic pair/tuple utility method that returns different concrete types depending on the number of elements, and how does target-type inference help the compiler choose the correct generic instantiation from context alone? Java › GenericsJavaGenericsAdvanced
105What does the node:events module's EventEmitter class provide, and what naming convention do most Node.js core APIs follow when using it? Node.js › Core Node.js ModulesNode.jsCore Node.js ModulesBeginner
106How do you create a custom class that emits events by extending Node's built-in EventEmitter? Node.js › Events & EventEmitterNode.jsEvents & EventEmitterBeginner
107How would you implement Attribute-Based Access Control (ABAC) in a Node.js application when RBAC roles aren't expressive enough? Node.js › Authentication & AuthorizationNode.jsAuthentication & AuthorizationIntermediate
108How does Sequelize define models and relationships for a relational (SQL) database in Node.js? Node.js › Databases & ORMs (MongoDB/Mongoose, SQL/Sequelize)Node.jsDatabases & ORMs (MongoDB/Mongoose, SQL/Sequelize)Intermediate
109Why can decorators make code harder to statically analyze or tree-shake, and what's a common criticism of overusing them? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
110How would you implement a custom event that carries multiple pieces of data, and what's the convention for structuring the emitted payload? Node.js › Events & EventEmitterNode.jsEvents & EventEmitterAdvanced
111What's the difference between a named export and a default export? JavaScript › ES ModulesJavaScriptES ModulesBeginner
112What does the # syntax mean for class members? JavaScript › Classes & Class SyntaxJavaScriptClasses & Class SyntaxIntermediate
113What's the difference between event.target and event.currentTarget? JavaScript › DOM & EventsJavaScriptDOM & EventsIntermediate
114How do you create and dispatch a custom DOM event? JavaScript › DOM & EventsJavaScriptDOM & EventsIntermediate
115How does MutationObserver let you react to DOM changes made by other code? JavaScript › DOM & EventsJavaScriptDOM & EventsAdvanced
116Why can circular module imports (Module A imports B, which imports A) cause subtle bugs? JavaScript › ES ModulesJavaScriptES ModulesAdvanced
117How would you implement a custom Symbol.iterator for a tree data structure to enable depth-first traversal with for...of? JavaScript › Iterators & GeneratorsJavaScriptIterators & GeneratorsAdvanced
118How would you use a Map to implement an LRU (Least Recently Used) cache? JavaScript › Map, Set, WeakMap & WeakSetJavaScriptMap, Set, WeakMap & WeakSetAdvanced
119How would you implement a generic class with multiple type parameters and bounded type parameters (like <T extends Comparable<T>>), and what does this specific bound enable? Java › GenericsJavaGenericsAdvanced
120What is optimistic concurrency control, and how would you implement it to prevent lost updates when two users edit the same record simultaneously? Node.js › DatabasesNode.jsDatabasesAdvanced