Questions

Java questions

Choose a question page, learn the concept, then test your understanding with a quiz.

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.

javadatetimezone

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.

javaperformancecollectionsinitialization

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.

javaenums

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.

javagarbage-collectionout-of-memoryheap-memory

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.

javagenericsinheritancepolymorphism

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.

javainner-classesstatic-classes

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.

javagenericssuperbounded-wildcard

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.

javaiojava.util.scanner

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.

javakotlinstaticstatic-methods

Java ThreadLocal: When and How to Use Per-Thread Variables

Learn when to use Java ThreadLocal for per-thread state, how get, set, and remove work, and how to prevent thread-pool memory leaks.

javamultithreadingconcurrencythread-local

Java Threads: implements Runnable vs extends Thread

Learn the difference between implements Runnable and extends Thread in Java, when to use each, and why Runnable is usually preferred.

javamultithreadingrunnableimplements

Java Unicode Escapes in Comments: Why Commented Code Can Still Execute

Learn why Java processes Unicode escapes before tokenizing, allowing sequences like \u000d in comments to affect code parsing.

javaunicodecomments

Java Varargs Explained: What `String...` Means in Method Parameters

Learn what `String...` means in Java methods, how varargs work, when to use them, and how they compare to arrays.

javavariadic-functions

Java instanceof and null: Do You Need a Null Check?

Learn how Java's instanceof works with null, whether a null check is needed, and how to use it safely in real code.

javanullpointerexceptionnull

Linking to External URLs in Javadoc

Learn how to link to external websites in Java Javadoc with HTML anchors, and when to use @link, @linkplain, and @see tags.

javaurljavadochyperlink

Maven Dependency Versions: Latest Releases, Ranges, and Updates

Learn how Maven resolves dependency versions, why always using latest is risky, and safer ways to find and update library releases.

javamavendependenciesmaven-2

Optional Parameters in Java: Practical Ways to Simulate Them

Learn how optional parameters work in Java, why Java has no true optional parameters, and the common patterns to model them cleanly.

javaoptional-parameters

Reading a Plain Text File in Java: Common Ways and Differences

Learn how to read plain text files in Java using BufferedReader, Scanner, Files, and streams, with examples and key differences.

javatextfile-ioascii

RecyclerView Multiple View Types in Android (Java)

Learn how to use multiple view types in an Android RecyclerView with Java using getItemViewType, ViewHolders, and practical examples.

javaandroiduser-interfaceandroid-recyclerview

Return a Method Argument with Mockito in Java

Learn how to configure Mockito mocks to return the argument passed to a method using AdditionalAnswers and custom Answer callbacks.

javamockito

Page 6 of 8 - 147 questions