Core Java - Level II
Practice 191 Core Java - Level II interview questions with detailed answers. Part of the Core Java track on Java Interview Hub.
- Can you tell me the difference between JVM, JRE, and JDK?
- What are the key components of JVM Architecture?
- Can a Java application be run without installing the JRE?
- Is it possible to have the JDK installed without having the JRE?
- What are Memory storages available with JVM?
- Which is faster to access between heap and stack, and why?
- How does garbage collection work in Java?
- What's the role of finalized() method in garbage collection?
- Can you tell me what algorithm JVM uses for garbage collection?
- How can memory leaks occur in Java even we have automatic garbage collection?
- Is Java 100% object oriented programming language?
- What are the advantages of Java being partially object-oriented?
- What is the use of object-oriented programming languages in the enterprise projects?
- Explain public static void main(String args[])?
- What will happen if we don't declare the main as static?
- Can we override the main method?
- Can we overload the main method?
- Can JVM execute our overloaded main method?
- What's the difference between primitive data types and non primitive data types?
- Can primitive data types be NULL?
- Can we declare pointer in java?
- What are wrapper classes?
- Why do we need wrapper classes?
- Why we use wrapper class in collections?
- Can you explain the difference between unboxing and autoboxing in Java?
- Can you provide an example where autoboxing could lead to unexpected behavior?
- Is there a scenario where autoboxing and unboxing could cause a NullPointerException?
- Can you explain the role of each try, catch, and finally block in exception handling?
- What happens if a return statement is executed inside the try or catch block? Does the finally block still execute?
- Is it possible to execute a program without a catch block? If so, how would you use try and finally together?
- How does exception handling with try-catch-finally affect the performance of a Java application?
- Can you tell me a condition where the finally block will not be executed?
- Can we write multiple finally blocks in Java?
- What is the exception and the differences between checked and unchecked exceptions?
- How would you handle multiple exceptions in a single catch block?
- What is the difference between a Throwable and an Exception in Java?
- Discuss the difference between finalize() and finally. Under what circumstances might finalize() not get called in a Java application?
- What is string pool?
- Are there any scenarios where using the string pool might not be beneficial?
- Can you please tell me about String and StringBuffer?
- How does StringBuilder differ from StringBuffer, and when should each be used?
- Give a scenario where StringBuffer is better than the String?
- What is the difference between a String literal and a String object?
- Why is String immutable?
- What are the packages in Java?
- Why packages are used?
- What are access modifiers in Java?
- Can you provide examples of when to use each type of access modifier?
- Why do we use getters setter when we can make fields public and setting getting directly?
- Can a top-level class be private or protected in Java?
- Explain the concepts of classes and objects in Java.
- What are the ways to create an object?
- Can a class in Java be without any methods or fields?
- What are the methods available in the Object class, and how are they used?
- What are anonymous classes and their advantages?
- What is Singleton Class?
- How can we create this singleton class?
- Are these threads safe?
- What is a constructor in Java?
- Can we use a private constructor?
- Can constructor be overloaded?
- What is immutability mean in Java?
- Why immutable objects are useful for concurrent programming?
- What are immutable classes?
- How can we create immutable class?
- What does Java's inheritance mean?
- Can a class extend its own?
- Why multiple inheritance is not possible in java?
- What is the difference between inheritance and composition?
- Discuss the principle of "composition over inheritance". Provide an example where this principle should be applied in Java application design.
- What is the difference between association, aggregation, and composition in Java?
- Explain the IS-A (inheritance) and Has-A (composition) relationships in Java.
- What does mean by polymorphism in Java?
- How does method overloading relate to polymorphism?
- What is dynamic method dispatch in Java?
- Can constructors be polymorphic?
- What does mean by abstraction in java?
- Can you provide examples of where abstraction is effectively used in Java libraries?
- What happens if a class includes an abstract method?
- How does abstraction help in achieving loose coupling in software applications?
- What is interface in Java?
- What is the difference between an interface and an abstract class in Java?
- Can you provide examples of when to use an interface versus when to extend a class?
- How do you use multiple inheritance in Java using interfaces?
- Can an interface in Java contain static methods, and if so, how can they be used?
- When would you use an interface, and when would you use an abstract class?
- Explain the difference between Comparable and Comparator interfaces. When would you use one over the other?
- What is a static method in an Interface, and how is it different from a default method in an interface?
- What is the diamond problem in Java and how does Java address it?
- How does the concept of default methods in interfaces help resolve the diamond problem?
- What does mean by encapsulation in java?
- How Encapsulation Enhances Software Security and Integrity?
- What is the concept of Serialization in Java?
- What is the purpose of the serialVersionUID in Java serialization?
- What happens if the serialVersionUID of a class changes during deserialization?
- How can you prevent certain fields from being serialized in Java?
- Can a class be serialized if one of its member fields is not serializable?
- What is the difference between writeObject() and readObject() methods in Java serialization?
- Is it possible to serialize static fields in Java? Why or why not?
- How do you serialize an object with circular references in Java?
- What is method overloading in Java?
- How does the Java compiler determine which overloaded method to call?
- Is it possible to overload methods that differ only by their return type in Java?
- What are the rules for method overloading in Java?
- What is method overriding in Java?
- What are the rules and conditions for method overriding in Java?
- How does the @Override annotation influence method overriding?
- What happens if a superclass method is overridden by more than one subclass in Java?
- What is 'this' and 'super' keyword in java?
- Can 'this' keyword be assigned a new value in Java?
- What happens if you attempt to use the "super" keyword in a class that doesn't have a superclass?
- Can the this or super keyword be used in a static method?
- How does 'super' play a role in polymorphism?
- What is the static keyword in Java?
- Can a static block throw an exception?
- Can we override static methods in Java?
- Is it possible to access non-static members from within a static method?
- What is static block?
- Can we print something on console without main method in java?
- What is final keyword in java?
- What are some common use cases for using final variables in Java programming?
- How does the "final" keyword contribute to immutability and thread safety in Java?
- Can you describe any performance considerations related to using final?
- What is functional interfaces?
- Can functional interface extend another interface?
- What are the Advantages of using a functional interface.
- Can you tell me some new features that were introduced in Java 8?
- Why optional class, lambda expressions and stream API were introduced in java 8?
- Difference between filter and map function of stream API?
- Can you tell me some new features that were introduced in Java 11?
- Can you tell me some new features that were introduced in Java 17?
- Can you tell me some new features that were introduced in Java 21?
- Which is faster, traditional for loop or Streams?
- In which scenarios would you prefer traditional for loops and streams?
- Explain intermediate and terminal operations in streams.
- Differences in Interface from Java 7 to Java 8.
- Use of String.join(...) in Java 8?
- What is collection framework in java?
- What are the main interfaces of the Java Collection Framework?
- Can you explain how Iterator works within the Java Collection Framework?
- What are some common methods available in all Collection types?
- How does Java Collection Framework handle concurrency?
- How do you choose the right collection type for a specific problem?
- What enhancements were made to the Java Collection Framework in Java 8?
- What is the difference between Iterator and ListIterator?
- Name of algorithm used by Arrays.sort(..) and Collections.sort(..)?
- How do you store elements in a set to preserve insertion order?
- How do you store elements in a way that they are sorted?
- What's the use case of ArrayList, LinkedList and HashSet?
- How does a HashSet ensure that there are no duplicates?
- Can you describe how hashCode() and equals() work together in a collection?
- Why is it important to override the hashCode method when you override equals? What would be the consequence if we don’t?
- Can you give an example where a TreeSet is more appropriate than HashSet?
- What is the internal implementation of ArrayList and LinkedList?
- Can you explain internal working of HashMap in Java?
- What happens when two keys have the same hash code? How would you handle this scenario?
- How does a HashMap handle collisions in Java?
- Can you please tell me what changes were done for the HashMap in Java 8 because before Java 8 HashMap behaved differently?
- Can we include class as a key in HashMap?
- Can you please explain ConcurrentHashMap?
- How does it (ConcurrentHashMap) improve performance in a multi-threaded environment?
- What is time complexities insertions, deletion and retrieval of HashSet and HashMap?
- What is time complexities insertions, deletion and retrieval of TreeSet and TreeMap?
- What techniques did HashMap, TreeMap, HashSet and TreeSet use internally for performing operations?
- What is a design pattern in Java and why do we use this?
- Can you list and explain a few common design patterns used in Java programming?
- How can design patterns affect the performance of a Java application?
- Which design pattern would you use to manage database connections efficiently in a Java application?
- How do you choose the appropriate design pattern for a particular problem in Java?
- Difference between HashMap and TreeMap.
- In what scenarios would you prefer to use a TreeMap over a HashMap?
- Can we add objects as a key in TreeMap?
- What are SOLID Principles?
- What is a thread in Java and how can we create it?
- Can you explain the lifecycle of a Java thread?
- How would you handle a scenario where two threads need to update the same data structure?
- Can we start thread twice?
- What is the difference between Thread class and Runnable interface in Java?
- What are volatile variables?
- What is thread synchronization and why is it important?
- Can you describe a scenario where you would use wait() and notify() methods in thread communication?
- What challenges might you face with multithreaded programs in Java?
- What is Java Memory Model and how it is linked to threads?
- Can we create a server in Java application without creating Spring or any other framework?
- What is transient?
- What is Exchanger class?
- What is reflection in Java?
- What is the weak reference and soft reference in Java?
- What is Java Flight Recorder?
- Discuss Java Generics.
- What is the difference between Young Generation and Old Generation memory spaces?