Java
Java
The JVM is an engine that provides a runtime environment to execute Java bytecode.
JDK is the Java Development Kit, JRE is the Java Runtime Environment, and JVM is the Java Virtual Machine;
JDK includes JRE, which includes JVM.
Public, private, protected, and default (no modifier) control the visibility of classes and members.
Polymorphism allows methods to perform differently based on the object that invokes them.
Overloading is having multiple methods with the same name but different parameters; overriding is
redefining a superclass method in a subclass.
9. What is encapsulation?
Encapsulation is the wrapping of data and methods into a single unit, typically a class.
Abstraction is the process of hiding implementation details and showing only functionality.
Exception Handling
Exception handling manages runtime errors, allowing the normal flow of the program to continue.
Try contains code that might throw an exception; catch handles the exception; finally executes code
regardless of exception occurrence.
Throw is used to explicitly throw an exception; throws declares exceptions a method might throw.
15. Can we have multiple catch blocks for a single try block?
Collections Framework
A set of classes and interfaces that implement commonly reusable collection data structures.
List allows duplicate elements; Set does not allow duplicates; Map stores key-value pairs.
Synchronization controls access to shared resources by multiple threads to prevent data inconsistency.
26. What is the difference between byte streams and character streams?
Byte streams handle raw binary data; character streams handle character data.
Serialization is the process of converting an object into a byte stream for storage or transmission.
Java Memory Management
Garbage collection is the process of automatically freeing memory by deleting unreachable objects.
32. What are the different types of memory areas allocated by JVM?
Method Area, Heap, Stack, Program Counter Register, and Native Method Stack.
Stack stores method calls and local variables; Heap stores objects.
Java Database Connectivity (JDBC) is an API for connecting and executing queries with databases.
Load the driver, establish a connection, create a statement, execute queries, and close the connection.
Comparable is used for natural ordering; Comparator is used for custom ordering.
Java 8 Features
Lambda expressions provide a clear and concise way to implement functional interfaces.
Interfaces with a single abstract method, used primarily with lambda expressions.
Miscellaneous
String is immutable; StringBuilder is mutable and not thread-safe; StringBuffer is mutable and thread-safe.
Autoboxing is the automatic conversion of primitives to their wrapper classes; unboxing is the reverse.
Metadata that provides data about a program but is not part of the program itself.