Questions
Java questions
Choose a question page, learn the concept, then test your understanding with a quiz.
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.
Get a Generic Type Class in Java: Why T.class Does Not Work
Learn why Java cannot use T.class in generic code and how to pass Class<T> safely using type tokens and reflection-aware patterns.
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.
HashMap vs LinkedHashMap vs TreeMap in Java
Learn the difference between HashMap, LinkedHashMap, TreeMap, and Hashtable in Java with examples, ordering rules, and use cases.
Hibernate hbm2ddl.auto Values Explained: validate, update, create, create-drop, and schema strategies
Learn Hibernate hbm2ddl.auto values, what each option does, when to use update, and safer alternatives for schema changes in real projects.
How Android SDK Finds the JDK on Windows
Learn why Android SDK setup may not detect the JDK on Windows and how Java paths, environment variables, and 32/64-bit tools affect it.
How Java Servlets Work: Instantiation, Sessions, Instance Variables, and Multithreading
Learn how Java servlets handle instantiation, sessions, shared variables, and multithreading for multiple users and requests.
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 a File Exists in Java
Learn how to check whether a file exists in Java using File and Path APIs, with examples, pitfalls, and best practices for beginners.
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 Check if a String Is Numeric in Java
Learn how to check whether a String is numeric in Java before parsing it, with examples, pitfalls, and practical validation patterns.
How to Check if a long Is a Perfect Square in Java
Learn how to test whether a Java long is a perfect square, including Math.sqrt, integer checks, optimizations, and common pitfalls.
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 Configure the Server Port in Spring Boot
Learn how to change the default 8080 port in a Spring Boot application using properties, YAML, command-line args, and code.