Questions
Java questions
Choose a question page, learn the concept, then test your understanding with a quiz.
JSF vs Servlet vs JSP: Differences and Relationships in Java Web Development
Learn how Java Servlets, JSP, and JSF differ, how they work together, and why modern JSF applications typically use Facelets views.
JVM Heap Size Explained: What -Xms and -Xmx Mean in Java
Learn what JVM -Xms and -Xmx mean, how they control heap memory, typical defaults, and how to use them safely in Java apps.
Java 8 Method References: Understanding the :: Operator and Math::max
Learn how Java 8 method references work, including :: syntax, functional interfaces, and why Math::max fits IntBinaryOperator.
Java 8 Stream map() vs flatMap(): Differences, Examples, and Uses
Learn the difference between Java 8 Stream map() and flatMap(), including one-to-one transformation, flattening nested data, and practical examples.
Java Access Modifiers Explained: public, protected, package-private, and private
Learn the differences between Java access modifiers and when to use public, protected, package-private, and private in classes and inheritance.
Java Arithmetic Performance: Why Parentheses Can Benchmark Differently
Learn why equivalent Java arithmetic can benchmark differently, how JIT compilation changes code, and how to measure performance reliably.
Java ArrayList Initialization in One Line
Learn how to initialize a Java ArrayList in one line, when to use Arrays.asList, List.of, and how mutability affects your code.
Java Class Names Explained: getSimpleName() vs getName() vs getCanonicalName()
Learn the difference between getSimpleName(), getName(), and getCanonicalName() in Java with clear examples and real use cases.
Java Date Parsing and Time Zone Transitions: Why 1 Second Becomes 353 Seconds
Learn why Java parses 1927 dates strangely in Asia/Shanghai and how time zone history affects epoch milliseconds and date math.
Java Double Brace Initialization: Efficiency, Risks, and Better Alternatives
Learn how Java double brace initialization works, its anonymous-class costs and risks, and safer ways to create collections with Set.of and more.
Java Enum Comparison: Should You Use == or equals()?
Learn how to compare Java enum values correctly using == or equals(), with examples, null safety, pitfalls, and best practices.
Java GC Overhead Limit Exceeded: Causes and Fixes
Learn what Java's GC overhead limit exceeded error means, why it occurs in JUnit tests, and how to diagnose memory leaks and heap usage.
Java Generic Invariance: Why List<Dog> Is Not List<Animal>
Learn why Java generics are invariant, why List<Dog> cannot be used as List<Animal>, and how wildcards safely model polymorphism.
Java Generics: List<? super T> vs List<? extends T>
Learn the difference between Java List<? super T> and List<? extends T>, including PECS, safe reads, safe writes, examples, and common mistakes.
Java Inner Class vs Static Nested Class: Differences, Use Cases, and When to Choose Each
Learn the difference between Java inner classes and static nested classes, with examples, use cases, mistakes, and design guidance.
Java LINQ Equivalent: Stream API, Filters, Maps, and Collectors
Learn how Java Stream API provides LINQ-like data querying with filter, map, sorted, and collect, plus practical examples and pitfalls.
Java Multi-Catch: Catch Multiple Exceptions in One Catch Clause
Learn how Java multi-catch handles several exception types in one catch block, including syntax, rules, examples, and common mistakes.
Java PECS: Understanding Producer Extends and Consumer Super
Learn Java PECS with clear examples of extends and super wildcards, type-safe copying, API design, and common generics mistakes.
Java Scanner nextLine() After nextInt(): Why Input Is Skipped
Learn why Java Scanner nextLine() appears to skip input after nextInt(), and how to handle the leftover newline reliably.
Java Static Method Equivalents in Kotlin: Companion Objects and Top-Level Functions
Learn Kotlin alternatives to Java static methods: top-level functions, companion objects, object declarations, and @JvmStatic for Java interop.