Java
Java
Java: A programming language and platform that provides a system for developing and running
applications.
JDK (Java Development Kit): A software development kit for Java developers, including tools like
compilers, debuggers, and libraries.
JVM (Java Virtual Machine): A virtual machine that enables Java applications to run on any platform
without modification. It reads and executes bytecode.
JRE (Java Runtime Environment): A package that provides libraries, Java Virtual Machine (JVM), and
other components to run Java applications.
5. Composition vs Inheritance
Composition: A "has-a" relationship where one object contains another object.
Inheritance: An "is-a" relationship where one class inherits properties and behavior from another.
7. Explain the following keywords in Java: static, this, super, final, finally, finalize, volatile, transient.
static: Defines class-level members that are shared across all instances of the class.
this: Refers to the current object instance.
super: Refers to the superclass of the current object.
final: Used to define constants, prevent method overriding, or restrict inheritance.
finally: A block of code that always executes after a try-catch block, regardless of an exception.
finalize: A method called by the garbage collector before an object is destroyed.
volatile: Ensures visibility of changes to a variable across threads.
transient: Prevents serialization of a field.
21. Explain Threading, Life Cycle, Thread Communication, and Thread Local.
Threading: The process of running multiple threads (independent units of execution) within a program.
Life Cycle: A thread goes through various states such as New, Runnable, Blocked, Waiting, Timed
Waiting, and Terminated.
Thread Communication: Threads communicate using methods like wait(), notify(), and notifyAll().
Thread Local: A special type of variable that is isolated to a thread, so each thread has its own copy.
22. Why must wait(), notify(), and notifyAll() be called from synchronized methods or blocks?
These methods must be called from synchronized methods or blocks because they work on the intrinsic
lock (monitor) of the object, ensuring proper thread synchronization.
28. How does HashMap work? Explain the equals and hashcode contract.
A HashMap stores key-value pairs, using the key’s hashCode to determine the bucket in which the entry
is stored. The equals() method is used to compare keys for equality. The contract states that:
If two objects are equal according to equals(), they must have the same hashCode.
If two objects have different hashCode, they are not equal.