Questions
Java questions
Choose a question page, learn the concept, then test your understanding with a quiz.
Avoiding Java Code in JSP with JSP 2: EL and JSTL Explained
Learn how to avoid Java scriptlets in JSP 2 using Expression Language and JSTL, with examples, best practices, and common mistakes.
Choosing a @NotNull Annotation in Java: Validation vs Static Analysis
Learn how Java @NotNull annotations differ, when to use each one, and how to choose between validation, IDE hints, and static analysis tools.
Convert a Java Stack Trace to a String
Learn how to convert a Java exception stack trace to a string using StringWriter and PrintWriter, with examples and common mistakes.
Convert an Array to a List in Java: Arrays.asList, Primitive Arrays, and Safe Alternatives
Learn how to convert arrays to lists in Java, including why Arrays.asList behaves differently for primitive arrays like int[].
Create an Executable JAR with Dependencies in Maven
Learn how to build a runnable Maven JAR with all dependencies included using plugins like Shade and Assembly.
Does Java Support Default Parameter Values? Overloading and Constructor Chaining Explained
Learn how Java handles default parameter values using method overloading and constructor chaining, with examples and common pitfalls.
Does a finally Block Always Execute in Java? Exceptions, Return, and Edge Cases
Learn when a finally block runs in Java, how it behaves with return and exceptions, and the rare cases where it may not execute.
Generate Random Integers in a Range in Java
Learn how to generate random integers within a specific range in Java correctly, avoid overflow bugs, and use Random and ThreadLocalRandom safely.
HashMap vs Hashtable in Java: Differences, Performance, and When to Use Each
Learn the differences between HashMap and Hashtable in Java, including thread safety, null handling, performance, and when to use each.
How the Enhanced for-each Loop Works in Java
Learn how Java's enhanced for-each loop works, its equivalent standard loops, limitations, and when to use iterators or index-based loops.
How to Add Local JAR Files to a Maven Project in Java
Learn how to use local JAR files in a Maven project, including system scope, installing to a local repository, and best practices.
How to Assert Exceptions in JUnit Tests
Learn how to test that code throws exceptions in JUnit using expected exceptions, assertThrows, and clean test patterns.
How to Avoid Null Checks in Java
Learn practical ways to avoid repeated null checks in Java, prevent NullPointerException, and write cleaner, safer code.
How to Break Out of Nested Loops in Java
Learn how to break out of nested loops in Java using labeled break, flags, and cleaner control-flow patterns with examples.
How to Call One Constructor from Another in Java
Learn how constructor chaining works in Java, how to call one constructor from another, and when to use this() and super().
How to Change the Default Java JDK Version on macOS
Learn how to view, set, and switch the default Java JDK version on macOS using java_home, shell profiles, and practical examples.
How to Check If an Array Contains a Value in Java
Learn how to test whether a Java array contains a value using loops, Arrays.asList, streams, and best practices for beginners.
How to Concatenate Two Arrays in Java
Learn how to concatenate two arrays in Java, especially String arrays, with simple examples using arrays, loops, and utility methods.
How to Convert a String to an Enum in Java
Learn how to get an enum value from a string in Java using Enum.valueOf(), with examples, errors, validation, and best practices.
How to Convert a String to an int in Java
Learn how to convert a String to an int in Java using parseInt and valueOf, with examples, mistakes, and practical use cases.
Page 1 of 4 - 69 questions