0% found this document useful (0 votes)
2 views

Java

The document outlines key concepts and features of Java, including its platform independence, differences between JDK, JRE, and JVM, and the purpose of keywords like final, static, and volatile. It also explains object-oriented principles such as inheritance, interfaces, and exception handling, along with data structures like ArrayList and HashMap. Additional topics include lambda expressions, functional interfaces, and the differences between various collection types and concurrency mechanisms.

Uploaded by

dev344448
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java

The document outlines key concepts and features of Java, including its platform independence, differences between JDK, JRE, and JVM, and the purpose of keywords like final, static, and volatile. It also explains object-oriented principles such as inheritance, interfaces, and exception handling, along with data structures like ArrayList and HashMap. Additional topics include lambda expressions, functional interfaces, and the differences between various collection types and concurrency mechanisms.

Uploaded by

dev344448
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

 Why is Java considered platform-independent?

→ Java code runs on the JVM, making it independent of the underlying operating
system.
 What is the difference between JDK, JRE, and JVM?
→ JDK is for development, JRE is for running Java programs, and JVM executes
bytecode.
 Why does Java not support multiple inheritance?
→ To avoid ambiguity and the Diamond Problem, Java allows multiple inheritance
only through interfaces.
 What is the purpose of the final keyword in Java?
→ It prevents modification of variables, methods, and classes.
 What is the difference between == and .equals() in Java?
→ == compares references, while .equals() compares object content.
 Why is Java not a purely object-oriented language?
→ It includes primitive data types like int, char, and boolean.
 What is autoboxing in Java?
→ Automatic conversion of primitive types to their corresponding wrapper
classes.
 What is the difference between String, StringBuilder, and StringBuffer?
→ String is immutable, StringBuilder is mutable but not thread-safe, and
StringBuffer is thread-safe.
 What is the purpose of the static keyword in Java?
→ It allows a method or variable to belong to the class instead of instances.
 What is the difference between method overloading and method overriding?
→ Overloading occurs in the same class with different parameters, while
overriding redefines a method in a subclass.
 What is an abstract class in Java?
→ A class that cannot be instantiated and may contain abstract methods.
 What is the use of the super keyword in Java?
→ It refers to the parent class and can be used to access its methods and
constructors.
 What is a constructor in Java?
→ A special method used to initialize objects when they are created.
 What is the difference between an interface and an abstract class?
→ Interfaces contain only abstract methods (before Java 8), while abstract
classes can have both abstract and concrete methods.
 What is the instanceof operator used for in Java?
→ It checks if an object is an instance of a specific class or subclass.
 What is the difference between checked and unchecked exceptions?
→ Checked exceptions must be handled at compile time, while unchecked
exceptions occur at runtime.
 What is the purpose of try, catch, and finally blocks in Java?
→ They handle exceptions and ensure cleanup code runs regardless of an
exception.
 What is the purpose of the throws keyword in Java?
→ It declares that a method may throw an exception, warning callers to handle it.
 What is garbage collection in Java?
→ An automatic memory management feature that removes unused objects to
free memory.
 What is the volatile keyword in Java?
→ It ensures that a variable’s value is always read from and written to main
memory, preventing thread caching issues.
 What is the difference between synchronized and Lock in Java?
→ synchronized is a keyword for automatic locking, while Lock provides more
flexible locking mechanisms.
 What is the difference between ArrayList and LinkedList?
→ ArrayList is faster for random access, while LinkedList is better for insertions
and deletions.
 What is the purpose of hashCode() and equals() in Java?
→ They define how objects are compared and stored in hash-based collections.
 What is the difference between HashMap and TreeMap?
→ HashMap is unordered, while TreeMap maintains sorted order.
 What is the difference between ExecutorService and Thread?
→ ExecutorService manages thread pools, while Thread represents a single
thread execution.
 What is the transient keyword used for in Java?
→ It prevents a variable from being serialized.
 What is the difference between Comparator and Comparable?
→ Comparable defines a natural order, while Comparator provides custom sorting
logic.
 What is the purpose of the default method in Java interfaces?
→ It allows interfaces to have method implementations without breaking existing
implementations.
 What is a lambda expression in Java?
→ A concise way to write anonymous functions, introduced in Java 8.
 What is a functional interface in Java?
→ An interface with only one abstract method, used in lambda expressions.

You might also like