Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is platform-independent due to its "write once, run anywhere" capability using the Java Virtual Machine (JVM).
Java has several key features including: Object-Oriented, Platform Independence, Multi-threading, Security, Robustness, and Automatic Memory Management.
JVM (Java Virtual Machine): Runs Java bytecode and provides platform independence.
JDK (Java Development Kit): Contains tools for developing, compiling, and running Java programs.
JRE (Java Runtime Environment): Includes JVM and libraries required to run Java applications.
A class is a blueprint or template for creating objects.
An object is an instance of a class with a defined state and behavior.
Primitive types (int, char, boolean, etc.) store actual values, while reference types (String, Arrays, Classes) store memory addresses pointing to objects.
Encapsulation is the principle of wrapping data (variables) and code (methods) together into a single unit, restricting direct access to some components.
Inheritance allows a class to acquire the properties and behavior of another class using the extends keyword.
Abstraction is the process of hiding implementation details and exposing only relevant functionality using abstract classes or interfaces.
An interface defines a contract that implementing classes must follow. It contains only abstract methods (Java 8 introduced default and static methods).
An abstract class can have both abstract and concrete methods, whereas an interface only had abstract methods before Java 8.
Method overloading is defining multiple methods in the same class with the same name but different parameter lists.
Method overloading is defining multiple methods in the same class with the same name but different parameter lists.
== compares memory references, while .equals() checks content equality (overridden in String and wrapper classes).
Static methods and variables belong to the class rather than any specific object and are shared among all instances.
A constructor is a special method invoked when an object is created, used to initialize object properties.
Exception handling manages runtime errors using try, catch, finally, throw, and throws keywords.
Checked exceptions (IOException, SQLException) must be handled, while unchecked exceptions (NullPointerException, ArithmeticException) occur at runtime.
Multithreading allows multiple threads to run concurrently, improving application performance.
String is immutable, while StringBuffer and StringBuilder are mutable. StringBuffer is thread-safe, whereas StringBuilder is faster but non-thread-safe.
Garbage collection automatically frees unused memory using the JVM’s garbage collector.
ArrayList is better for indexing, whereas LinkedList is more efficient for insertions and deletions.
Lambda expressions (introduced in Java 8) enable functional programming by allowing concise syntax for implementing functional interfaces.
The Stream API (Java 8) provides a powerful way to process collections using functional programming constructs like map, filter, and reduce.
A shallow copy copies only references, while a deep copy duplicates the entire object structure.
The volatile keyword ensures that reads and writes to a variable are directly done from and to the main memory, not from CPU caches. This guarantees visibility (i.e., if one thread updates the variable, all other threads will see the updated value immediately).
The synchronized keyword is used to lock access to a critical section of code to ensure only one thread executes it at a time. It provides both visibility and atomicity, making it useful for thread safety.
Serialization in Java is the process of converting an object into a byte stream so that it can be saved to a file, transmitted over a network, or stored in a database. This byte stream can later be deserialized to reconstruct the original object.
Copyrights © 2024 letsupdateskills All rights reserved