Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. It is platform-independent because of the Java Virtual Machine (JVM), which allows Java applications to run on any device that has the JVM installed.
Abstract Class: Can have both abstract and concrete methods, supports instance variables, can have constructors, and allows method implementation.
Interface: Only abstract methods (until Java 8 introduced default and static methods), no instance variables, no constructors, all methods are implicitly public.
JDK (Java Development Kit): It is a software development environment used for developing Java applications, containing tools like the compiler (javac), JRE, and libraries.
JRE (Java Runtime Environment): It provides the libraries, Java Virtual Machine (JVM), and other components necessary for running Java applications.
JVM (Java Virtual Machine): It is a virtual machine that executes Java bytecode and provides platform independence.
Java provides four access modifiers:Private: Accessible only within the class.
Default (no modifier): Accessible within the same package.
Protected: Accessible within the same package and subclasses.
Public: Accessible from everywhere
The static keyword can be used with variables, methods, blocks, and nested classes. It means the member belongs to the class rather than instances of the class. Static members are shared across all instances.
==: Compares references (whether two references point to the same object).
equals(): Compares the actual content of the strings.
The this keyword refers to the current instance of the class. It is used to differentiate instance variables from local variables or to invoke another constructor in the same class.
Local variables do not have a default value and must be explicitly initialized before use.
The finalize() method is called by the garbage collector on an object when the garbage collection is about to destroy that object. It allows the object to clean up resources before being reclaimed, though its execution is not guaranteed.
ArrayList: Backed by a dynamic array, offers constant-time access but slower insertions and deletions.
LinkedList: Backed by a doubly-linked list, offers faster insertions and deletions but slower access time.
Multithreading is the ability of a Java program to execute multiple threads simultaneously. Threads are lightweight sub-processes that improve the performance of programs by utilizing CPU resources efficiently.
There are two main ways to create a thread:By implementing the Runnable interface and overriding its run() method.
By extending the Thread class and overriding its run() method.
Synchronization in Java is the capability to control the access of multiple threads to shared resources. It helps prevent thread interference and inconsistency. It can be achieved using the synchronized keyword.
HashMap: Non-synchronized, allows null keys and values.
HashTable: Synchronized, doesn’t allow null keys or values.
ArrayList: Non-synchronized, faster but not thread-safe.
Vector: Synchronized, slower but thread-safe.
The instanceof keyword is used to check whether an object is an instance of a specific class or implements a particular interface.
Wrapper classes are used to convert primitive data types into objects. For example, int can be wrapped into Integer, char into Character, and so on.
Autoboxing: Automatic conversion of primitive types to their corresponding wrapper classes (e.g., int to Integer).
Unboxing: Automatic conversion of wrapper types to their corresponding primitive types (e.g., Integer to int).
A NullPointerException occurs when an application attempts to use an object reference that has not been initialized (i.e., is null), such as calling a method on a null object.
The String pool is a special memory region where Java stores string literals to save memory. When you create a string using a literal (e.g., "abc"), Java checks the string pool first and creates a new string only if one does not already exist.