Java Interview Questions

Bikash NishankBikash Nishank
24 min read

String:

  1. What is the difference between String, StringBuilder, and StringBuffer in Java?

  2. Explain how String is immutable in Java. What are the benefits of immutability?

  3. How does the intern() method work with String objects?

  4. What will be the output of the following code?

     String s1 = "abc";
     String s2 = new String("abc");
     System.out.println(s1 == s2);
     System.out.println(s1.equals(s2));
    
  5. Can you explain how the split() method works in the String class? Provide an example.

  6. How can you reverse a string in Java without using a built-in reverse function?

  7. What is the difference between == and equals() when comparing strings?

  8. How does Java handle string concatenation internally? What are the performance implications?

  9. What will be the output of the following code?

     String str = "Java";
     str.concat("Programming");
     System.out.println(str);
    
  10. Explain the concept of String Pool in Java. How does it optimize memory usage?

  11. How does the substring() method work in Java? What is the time complexity of substring()?

  12. How can you convert a String to an int and vice versa in Java?

  13. What is the difference between String.valueOf() and toString()?

  14. How does the replace() method work in the String class? Provide an example.

  15. Explain how you can check if a String is a palindrome in Java.

  16. What is the difference between trim() and strip() methods in Java?

  17. How can you convert a String to a char[] in Java? Provide an example.

  18. How can you efficiently concatenate a large number of strings in Java?

  19. What is the difference between String.intern() and a regular string in the pool?

  20. Can you explain how string immutability improves performance in Java?

  21. What is String.intern() method, and when would you use it?

  22. How does StringBuilder internally manage memory, and how does it differ from StringBuffer?

  23. What is the output of the following code, and why?

    String a = "abc";
    String b = "abc";
    String c = new String("abc");
    System.out.println(a == b);
    System.out.println(a == c);
    
  24. Tracing: What will be the output of the following code?

    String s = "Java";
    s = s.concat(" is fun");
    System.out.println(s);
    
  25. Coding: Write a Java program to find the first non-repeating character in a given string.

OOPs Concepts:

  1. What is the difference between method overloading and method overriding? Can we override a static method? Why or why not?

  2. Can a constructor be final or static in Java? Why or why not?

  3. Can you have an abstract class without any abstract methods?

  4. How can we achieve multiple inheritance in Java?

  5. What will happen if a class has two interfaces with default methods having the same method signature? How would you resolve the conflict?

  6. Can you overload a constructor in Java? If yes, how is it different from method overloading?

  7. What is the difference between encapsulation and abstraction in Java OOP?

  8. Can a private method be inherited in Java?

  9. Can you explain polymorphism with an example in Java?

  10. How does Java handle object creation with respect to constructor chaining?

  11. How does the super keyword work in Java? Provide a use case.

  12. Explain the significance of the instanceof keyword in Java. Can it be used with interfaces?

  13. What is the significance of the this keyword? Can we use it inside static methods?

  14. What is the difference between composition and inheritance? Which is preferred in Java?

  15. How does the Java Virtual Machine (JVM) distinguish between overloaded methods?

  16. Can we override a private or static method in Java? Why or why not?

  17. What is a copy constructor? Does Java have it by default?

  18. What is the difference between an interface and an abstract class? Can a class be both abstract and final?

  19. How do access modifiers affect method overriding and inheritance?

  20. What is object slicing, and how does it occur in Java?

  21. What is composition over inheritance? Why is it recommended in design patterns?

  22. How is the @Override annotation useful in Java? What happens if you don't use it?

  23. Can you explain what shadowing is in Java with respect to variables?

  24. What is a bounded type parameter in generics, and why is it useful?

  25. What is method overriding covariant return type, and why is it important in Java?

  26. Coding: Write code to demonstrate method overriding in Java. Create a Parent class and a Child class, and override a method to show polymorphism.


Static:

  1. Can you access non-static members from a static context? Why not? Provide an example.

  2. What is the output of the following code?

     class Test {
         static {
             System.out.println("Static block");
         }
         Test() {
             System.out.println("Constructor");
         }
         public static void main(String[] args) {
             Test obj = new Test();
             Test obj2 = new Test();
         }
     }
    
  3. Explain the difference between a static block, static method, and static variable in Java.

  4. What happens if you declare a static method in a subclass that overrides a static method in the superclass?

  5. Can we access the this keyword inside a static method? Why or why not?

  6. Can you create a static class inside a non-static class? If yes, explain how it works.

  7. Can we declare static methods inside an interface? How are they different from default methods?

  8. What is the output when you call a static method from a null object reference?

  9. Can a static block throw an exception?

  10. Can static methods be synchronized in Java?

  11. Can we have multiple static blocks in a Java class? How are they executed?

  12. Explain the lifecycle of static variables in Java.

  13. Can a static method access instance variables in any scenario?

  14. What is the significance of static import? Provide an example.

  15. Can static methods be abstract? Why or why not?

  16. How does JVM initialize static variables when a class is loaded?

  17. Can we serialize static fields in Java?

  18. Can a static method in Java call another static method without using an object? Why or why not?

  19. What is a static factory method? How does it differ from constructors?

  20. Can we declare static variables inside static methods? Explain with an example.

  21. How does the JVM manage the lifecycle of static variables in memory?

  22. What is the static import feature in Java, and when would you use it?

  23. Explain the role of static initialization blocks when working with constant values.

  24. Tracing: Given the following code, what will be the output?

    class A {
        static {
            System.out.println("Static A");
        }
        A() {
            System.out.println("Constructor A");
        }
    }
    class B extends A {
        static {
            System.out.println("Static B");
        }
        B() {
            System.out.println("Constructor B");
        }
    }
    public class Test {
        public static void main(String[] args) {
            B b = new B();
        }
    }
    
  25. Coding: Write code to demonstrate static block execution in a class with inheritance. Explain the order in which static blocks and constructors are executed.


Final:

  1. What is the significance of the final keyword in Java? Can you give examples of final for variables, methods, and classes?

  2. Can you change the object that a final reference variable points to? Explain with an example.

  3. What happens if you declare a method as final and try to override it?

  4. What is the difference between immutability and using the final keyword?

  5. Can we declare a final method in an abstract class?

  6. What will happen if we declare a class as both final and abstract?

  7. Can you declare an interface method as final? Why or why not?

  8. Can final variables be initialized later? If yes, explain with an example.

  9. Can a final variable be modified inside a constructor?

  10. What is the use of a blank final variable in Java?

  11. Can we declare a final variable without initializing it? Provide an example.

  12. Can we change the reference of a final object if the object is mutable?

  13. How does the final keyword work with inheritance? Provide an example.

  14. What happens if you declare a constructor as final in Java?

  15. Can final methods be overloaded? If yes, how?

  16. What are the performance implications of the final keyword in Java?

  17. Can you explain the difference between the final keyword and the immutability of an object?

  18. Why is it a good practice to use final variables in multi-threaded programs?

  19. Can a final method be overridden by a subclass if it is inside an anonymous class?

  20. What are the implications of having a final class implementing an interface?

  21. Can we declare a method final and abstract together? Why or why not?

  22. Why is the final keyword important for constants in Java?

  23. Tracing: What will be the output of the following code?

    class Test {
        final int a = 10;
        void display() {
            a = 20;
        }
        public static void main(String[] args) {
            Test obj = new Test();
            obj.display();
        }
    }
    
  24. Coding: Write code to demonstrate how a final method cannot be overridden in a subclass.

  25. Coding: Write a Java program to demonstrate that a final variable can only be assigned once and cannot be changed later.


Abstract Classes and Interfaces:

  1. Can you have a constructor in an abstract class? If yes, when is it invoked?

  2. What is the difference between an abstract class and an interface? When should you use one over the other?

  3. Can an abstract class have a main() method? What will happen if we run it?

  4. Can a class implement multiple interfaces? Can it extend multiple classes? Why or why not?

  5. If an interface has 100 methods, do you need to implement all methods in the implementing class? Explain.

  6. Can an abstract class implement an interface without providing an implementation for all methods?

  7. Can we have static methods in an interface? How are they different from default methods?

  8. What is the purpose of having private methods in interfaces?

  9. What happens if two interfaces have methods with the same signature but different return types, and a class implements both interfaces?

  10. Can a non-abstract class extend an abstract class without implementing any abstract methods?

  11. Can an abstract class extend another abstract class?

  12. Can we mark an abstract class as final in Java?

  13. What happens if a class does not implement all abstract methods of its abstract parent class?

  14. Can an interface have instance variables? Why or why not?

  15. What is the diamond problem in Java, and how does the interface solve it?

  16. Can you instantiate an abstract class? If not, how can you use its constructor?

  17. What are the differences between default and static methods in an interface?

  18. Can an abstract class have private methods? Why would you do this?

  19. How does the @FunctionalInterface annotation work in Java, and why is it useful?

  20. Can an interface have a constructor? Explain with reasoning.

  21. What is the difference between a default method in an interface and a normal method in a class?

  22. Can abstract classes implement interfaces? If yes, what is the significance?

  23. Tracing: What will be the output of the following code?

    interface A {
        void display();
    }
    class B implements A {
        public void display() {
            System.out.println("Display from B");
        }
    }
    class C extends B {
        public void display() {
            System.out.println("Display from C");
        }
    }
    public class Test {
        public static void main(String[] args) {
            A obj = new C();
            obj.display();
        }
    }
    
  24. Coding: Write a program to demonstrate multiple inheritance using interfaces.

  25. Coding: Create an abstract class Shape with a method calculateArea(). Implement two subclasses Circle and Rectangle that calculate the area of the respective shapes.


Exception Handling:

  1. What is the difference between checked and unchecked exceptions in Java? Provide examples.

  2. Can you catch more than one type of exception in a single catch block? How?

  3. What is the difference between throw and throws in exception handling?

  4. What will happen if you throw an exception in the finally block?

  5. Explain the difference between Error and Exception in Java.

  6. Can you override a method that throws a checked exception to throw an unchecked exception instead?

  7. What happens if an exception is not handled in a multi-threaded application?

  8. Can a constructor throw an exception? If yes, what will happen?

  9. Can you catch an exception thrown by a static block?

  10. How does the JVM handle exceptions when they are not caught by any catch block?

  11. Can we have a try block without a catch block? Provide an example.

  12. Can you rethrow an exception in Java? If yes, explain how.

  13. What happens when an exception occurs in a catch block?

  14. Explain the purpose of the finally block. Will it always be executed?

  15. Can we write multiple finally blocks for a single try-catch block?

  16. What is the difference between checked and unchecked exceptions in Java?

  17. How does the throw keyword differ from the throws keyword in Java?

  18. Can a catch block throw an exception? Explain how you would handle this.

  19. How would you handle exceptions in Java without using try-catch?

  20. What is SuppressedException in Java, and how is it used?

  21. Tracing: What will be the output of the following code?

    public class Test {
        public static void main(String[] args) {
            try {
                System.out.println(10 / 0);
            } catch (Exception e) {
                System.out.println("Caught Exception");
            } finally {
                System.out.println("Finally block executed");
            }
        }
    }
    
  22. Coding: Write a program to demonstrate custom exception handling by creating a InvalidAgeException that throws an exception if the age is below 18.

  23. Coding: Write code to demonstrate how to rethrow an exception from a catch block.

  24. Coding: Write a program to demonstrate the order of exception handling when a method throws multiple exceptions.

  25. Coding: Write a program to demonstrate exception handling when an exception occurs inside a catch block.


Collections:

  1. What is the difference between ArrayList and LinkedList in terms of performance and internal implementation?

  2. Explain the difference between HashSet and TreeSet. In what scenarios would you use each?

  3. How does the HashMap work internally? Explain the role of hashCode() and equals() methods.

  4. What is the difference between HashMap and Hashtable? Why is Hashtable considered legacy?

  5. How does ConcurrentHashMap differ from HashMap in terms of thread safety and performance?

  6. Explain the differences between List, Set, and Map interfaces.

  7. What is the difference between fail-fast and fail-safe iterators? Give examples of collections that use each type.

  8. Can you explain the concept of "resize" in ArrayList? How does it impact performance?

  9. What is the difference between Comparable and Comparator? When would you use one over the other?

  10. What is a PriorityQueue in Java? Provide an example of its usage.

  11. Can you sort a HashMap? If so, how? Provide an example.

  12. How does LinkedHashMap maintain the order of elements, and how does it differ from HashMap?

  13. Explain how the remove() method works in ArrayList. What happens if you try to remove an element during iteration?

  14. How can you make a collection immutable in Java? Provide examples.

  15. What are the performance implications of using a TreeMap versus a HashMap?

  16. How does the ConcurrentLinkedQueue work, and in which scenarios is it useful?

  17. Can you create a synchronized ArrayList or HashMap? If yes, how?

  18. What is the difference between LinkedHashSet and HashSet?

  19. How does ConcurrentSkipListMap differ from a TreeMap in terms of concurrency?

  20. What are the pros and cons of using a LinkedHashMap over a HashMap?

  21. What is EnumMap, and why is it optimized for use with enumerations?

  22. How does a TreeSet maintain order internally, and what are its performance implications?

  23. What are the differences between SynchronousQueue and ArrayBlockingQueue?

  24. Tracing: What will be the output of the following code?

    public class Test {
        public static void main(String[] args) {
            Set<String> set = new HashSet<>();
            set.add("one");
            set.add("two");
            set.add("three");
            set.add("one");
            for (String s : set) {
                System.out.println(s);
            }
        }
    }
    
  25. Coding: Write a Java program to remove duplicates from an ArrayList of integers without using any built-in functions.


Threads and Concurrency:

  1. What is the difference between Thread and Runnable in Java? Which one is preferred?

  2. Explain the concept of synchronization in Java. What are the different ways to achieve thread safety?

  3. What is a volatile keyword in Java, and how is it different from synchronized?

  4. Can you explain the purpose of the join() method in thread management?

  5. How does the wait(), notify(), and notifyAll() methods work in thread communication? Provide a use case.

  6. What is the difference between ExecutorService and creating your own threads using new Thread()?

  7. Explain the concept of deadlock in Java. How can you prevent it?

  8. What is the difference between a ReentrantLock and a synchronized block in Java?

  9. What is the purpose of the ThreadLocal class in Java? When would you use it?

  10. What is the Callable interface in Java, and how is it different from Runnable?

  11. Explain the difference between CyclicBarrier and CountDownLatch. Provide an example.

  12. What is a ForkJoinPool in Java, and how does it help in parallel processing?

  13. What is the difference between sleep() and yield() methods in thread management?

  14. How does Java handle thread starvation and fairness in thread scheduling?

  15. Can you explain the concept of a daemon thread in Java? How is it different from a user thread?

  16. What are Atomic classes in Java's concurrency package? Provide examples.

  17. What is a Semaphore in Java, and how is it used in thread synchronization?

  18. What is the difference between Future and CompletableFuture in Java?

  19. What are the advantages of using ForkJoinPool over a traditional ThreadPoolExecutor?

  20. How does the AtomicInteger class help avoid synchronization issues?

  21. Explain the ThreadLocal class and give a scenario where it's beneficial.

  22. What is the purpose of CountDownLatch and how does it differ from CyclicBarrier?

  23. What is the Semaphore class, and when would you use it?

  24. Tracing: What will be the output of the following code?

    public class Test {
        public static void main(String[] args) {
            Thread t = new Thread(() -> {
                for (int i = 0; i < 5; i++) {
                    System.out.println(i);
                }
            });
            t.start();
            t.run();
        }
    }
    
  25. Coding: Write a Java program to demonstrate a producer-consumer problem using wait() and notify() methods.


JVM (Java Virtual Machine) Tricky Questions:

  1. What is the difference between the JVM, JDK, and JRE?

  2. How does the JVM load a class, and what is the significance of classloaders in Java?

  3. Explain the structure of the JVM memory model (Heap, Stack, Method Area, and more). How does the JVM allocate memory for objects and methods?

  4. What is the difference between the young generation and the old generation in the JVM memory?

  5. Explain how the garbage collection process works in Java. What are the different types of garbage collectors available?

  6. What is the difference between serial, parallel, and CMS garbage collectors in the JVM?

  7. What is a memory leak in Java, and how can it occur despite automatic garbage collection?

  8. What is the role of the Just-In-Time (JIT) compiler in the JVM? How does it optimize the execution of bytecode?

  9. What is the permgen space in older versions of Java, and how does it differ from the metaspace in newer versions (Java 8+)?

  10. Explain what happens during a full garbage collection (GC) cycle in the JVM. What are its implications for performance?

  11. What is the OutOfMemoryError: PermGen space? How can you resolve this error?

  12. What is the purpose of the -Xms and -Xmx JVM options? When should you adjust these settings?

  13. What is the role of the -XX:+UseG1GC flag in JVM? How does G1GC differ from other collectors?

  14. How do soft references, weak references, and phantom references affect garbage collection in Java?

  15. What is the difference between heap memory and stack memory in Java?

  16. How does the JVM handle multithreading with respect to memory visibility and synchronization?

  17. What is a class file in Java, and what kind of information does it contain about the bytecode?

  18. What is escape analysis in the JVM, and how does it affect object allocation and garbage collection?

  19. How does the JVM handle native methods, and what is the significance of the JNI (Java Native Interface)?

  20. What are JVM tuning parameters, and how can you optimize memory usage for a large Java application?


Memory Management Tricky Questions:

  1. What is the difference between strong, weak, soft, and phantom references in Java?

  2. What are memory leaks, and how can you identify and prevent them in Java applications?

  3. Explain how the JVM’s garbage collector works. What triggers a garbage collection event?

  4. What are the different memory regions in Java (e.g., Heap, Stack, Metaspace), and what is stored in each?

  5. What happens when the JVM runs out of heap memory?

  6. What is the difference between minor GC and major (full) GC in the JVM?

  7. Explain how to use memory profiling tools like VisualVM or JConsole to monitor and troubleshoot memory issues.

  8. What is the use of the finalize() method in Java, and why is it considered deprecated?

  9. How does the JVM allocate memory for an object during object creation?

  10. What is a thread stack in Java? How does the JVM allocate memory for each thread?

  11. What is a memory barrier, and how does it work in multithreaded applications?

  12. Can you explain how memory alignment works in the JVM? Why is it important for performance?

  13. How does the JVM handle class metadata in the heap (especially in versions after Java 8)?

  14. What are the consequences of not properly releasing native resources in Java?

  15. What is the difference between direct memory and heap memory, and when would you use direct memory?

  16. What is the java.lang.OutOfMemoryError: Metaspace error, and how would you debug and resolve it?

  17. What is GC tuning, and how do you approach it for applications with large datasets or high throughput?

  18. How can you manage the lifecycle of large objects in memory to avoid frequent full GCs?

  19. What are the benefits and risks of using -XX:+UseCompressedOops in the JVM?

  20. How does Escape Analysis help in optimizing memory usage in Java?

Java 8 new features

Lambdas & Functional Interfaces:

  1. What is a lambda expression in Java, and how does it differ from an anonymous inner class?

  2. Can you explain the syntax of lambda expressions and provide examples for different use cases (e.g., single line, multi-line)?

  3. How do lambda expressions contribute to functional programming in Java?

  4. What is the @FunctionalInterface annotation, and what are its rules? Can you have multiple abstract methods in a functional interface?

  5. Can a lambda expression capture variables from the surrounding context? What are the restrictions on captured variables?

  6. What is the difference between a lambda expression and a method reference in Java?

  7. What happens if a functional interface method throws a checked exception? How can you handle that in a lambda expression?

  8. How does type inference work in lambda expressions? Can you explicitly specify the types of parameters?

  9. Can lambda expressions access static and instance variables from their enclosing class?

  10. What are the performance implications of using lambda expressions compared to anonymous inner classes?

  11. Can you create recursive lambdas? How would you implement them?

  12. Explain how lambdas improve the readability and maintainability of code. Can you give an example?

  13. What is the difference between Predicate, Function, Supplier, and Consumer interfaces?

  14. Can you use a lambda expression to implement the Runnable interface? Provide a code example.

  15. What happens if you use this inside a lambda expression? What does it refer to?

  16. Can you overload a method that takes lambda expressions? What rules apply in such cases?

  17. How does the effectively final concept apply to variables used in lambda expressions?

  18. What are method references, and how are they different from lambdas? Provide examples.

  19. Can lambda expressions be used in synchronized blocks or methods?

  20. How are lambdas represented internally in the JVM? Explain the invokedynamic instruction related to lambdas.


Streams API:

  1. What is the Streams API in Java 8, and how does it differ from traditional collections processing?

  2. Can you explain the difference between intermediate and terminal operations in a stream? Provide examples.

  3. What is the significance of laziness in streams, and how does it affect performance?

  4. What is the difference between map() and flatMap() in streams?

  5. Explain how filter(), map(), and reduce() work in the Streams API.

  6. How does the Streams API handle parallel processing? How do you make a stream parallel?

  7. What is the difference between findAny() and findFirst() in the Streams API?

  8. Explain the difference between forEach() and forEachOrdered() in streams.

  9. What is the difference between collect() and reduce() methods in streams? Provide use cases for each.

  10. How do you convert a stream back into a collection, like a List or a Set?

  11. What are the potential pitfalls of using parallel streams? How does it impact thread safety and performance?

  12. Explain how groupingBy() and partitioningBy() collectors work in streams.

  13. What is a Spliterator, and how does it differ from an Iterator in streams?

  14. Can streams be reused after a terminal operation? Why or why not?

  15. What is short-circuiting in streams, and how do limit() and findFirst() demonstrate it?

  16. What is the difference between a sequential stream and a parallel stream? How do you convert one to another?

  17. Can a stream have infinite data? How would you process such streams?

  18. What is a Stream pipeline, and how does it improve the clarity of code in functional programming?

  19. How can you use streams to find the sum of an array of integers?

  20. What are Collectors, and how do they work with the Streams API? Provide examples of commonly used collectors.


Optional:

  1. What is Optional in Java 8, and why was it introduced?

  2. How does Optional help in avoiding NullPointerException?

  3. What is the difference between Optional.of(), Optional.ofNullable(), and Optional.empty()?

  4. What is the purpose of the orElse(), orElseGet(), and orElseThrow() methods in Optional?

  5. How can you chain Optional operations using map() and flatMap()? Provide examples.

  6. What happens if you call get() on an empty Optional? How should you handle it?

  7. What is the difference between isPresent() and ifPresent() in Optional?

  8. How does Optional relate to streams, and how can you convert an Optional to a stream?

  9. Can you use Optional in method parameters? Is it considered good practice? Why or why not?

  10. How does Optional improve code readability and reduce boilerplate code for null checks?

  11. What is the difference between Optional.map() and Optional.flatMap()?

  12. How can you combine two Optional values?

  13. Is Optional serializable? Why or why not?

  14. Can you use Optional with primitive types? If not, what alternatives are provided by Java?

  15. How does Optional fit into the overall functional programming paradigm introduced in Java 8?

  16. Can you return an Optional from a method? How does this improve code safety?

  17. Why is Optional not designed to be used for fields in Java classes?

  18. What is a typical use case for Optional when dealing with collections?

  19. Explain how Optional can be used to express the absence of a value in functional APIs.

  20. What are the performance implications of using Optional extensively in your code?


Default Methods in Interfaces:

  1. What are default methods in interfaces, and why were they introduced in Java 8?

  2. Can you override a default method in an implementing class? What happens if you don’t?

  3. What happens if a class implements two interfaces with conflicting default methods? How do you resolve it?

  4. Can a default method call other methods from the same interface? Provide an example.

  5. Can a default method be synchronized? Why or why not?

  6. Why can’t a default method be static or final?

  7. Can a default method access instance variables in the implementing class?

  8. What is the difference between default methods and abstract methods in interfaces?

  9. How do default methods impact backward compatibility with older Java versions?

  10. Can a default method in an interface call a static method from the same interface?

  11. How do default methods contribute to the multiple inheritance problem in Java?

  12. What is the significance of the super keyword when calling a default method from an interface?

  13. Can you declare a default method as private? Why or why not?

  14. Can a default method be used in an interface that already has abstract methods?

  15. How do default methods enable evolution of interfaces in large libraries like the JDK?

  16. Explain the use case for default methods in functional programming scenarios in Java.

  17. What are the implications of default methods for multiple inheritance in Java?

  18. Can you create a default method in an interface that calls another interface’s default method?

  19. Can you use default methods to provide a base implementation for commonly used methods?

  20. How do default methods interact with lambda expressions and functional interfaces?


New Date and Time API (java.time):

  1. What are the limitations of the old java.util.Date and java.util.Calendar classes, and how does the new Date/Time API improve upon them?

  2. What is the difference between LocalDate, LocalTime, and LocalDateTime classes in Java 8?

  3. How can you parse and format dates using DateTimeFormatter in Java 8?

  4. What is ZonedDateTime, and how does it handle time zones?

  5. How do you calculate the difference between two dates using the new Date/Time API?

  6. What is the purpose of Instant in Java 8, and how is it used for timestamp management?

  7. How do you convert between LocalDate and LocalDateTime?

  8. What are Period and Duration classes, and how do they differ?

  9. Can you explain the immutability of the Date/Time classes in Java 8 and why it’s important?

  10. What is TemporalAdjuster, and how is it used for date manipulation?

  11. How do you handle leap years and daylight savings time with the new API?

  12. Can you explain the significance of Clock and how it can be used for time manipulation in tests?

  13. How do you compare two dates using the new Date/Time API?

  14. What are the advantages of java.time package classes over java.sql.Date for database interactions?

  15. How does the ZoneId class work, and how do you use it to represent time zones?

  16. How can you convert the new date/time API to java.util.Date and vice versa?

  17. What are the key improvements of DateTimeFormatter over SimpleDateFormat?

  18. What are ChronoUnit and ChronoField, and how are they used for date manipulations?

  19. How do MonthDay and YearMonth classes work, and how do they differ from LocalDate?

  20. What is the OffsetDateTime class, and how does it handle UTC offsets?

0
Subscribe to my newsletter

Read articles from Bikash Nishank directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bikash Nishank
Bikash Nishank