100% Practical, Personalized, Classroom Training and Assured Job Book Free Demo Now
App Development
Digital Marketing
Other
Programming Courses
Professional COurses
Garbage collection is the automatic process of reclaiming memory occupied by objects that are no longer reachable or referenced by the program. The Java Virtual Machine (JVM) identifies unreferenced objects and frees up their memory. Java employs different garbage collection algorithms, such as the generational garbage collector, to efficiently manage memory.
synchronized
: Ensures mutual exclusion by preventing multiple threads from executing a block of code simultaneously. It can be applied to methods or code blocks.volatile
: Guarantees visibility of changes across threads. When a variable is declared as volatile
, any thread reading the variable sees the most recent modification made by any other thread.The Java Memory Model defines the rules and semantics for how threads interact with memory in a multithreaded environment. It ensures that the changes made by one thread to shared variables are visible to other threads. The JMM provides guarantees for the ordering and visibility of reads and writes performed by multiple threads.
The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. In Java, the Observer
interface and Observable
class can be used for implementation. However, it's worth noting that these classes are deprecated in newer versions of Java, and alternatives like the java.util.concurrent.Flow
package or third-party libraries are recommended.
FileInputStream
: Reads bytes from a file. It is not buffered, meaning each read operation involves disk access.BufferedInputStream
: Wraps around a FileInputStream
to provide buffering. It reads data from the file into an internal buffer, making read operations more efficient by minimizing disk access.Serialization is the process of converting an object into a byte stream, which can be persisted to a file, sent over a network, or stored in a database. In Java, the java.io.Serializable
interface is used to mark classes as serializable. Object serialization is performed using ObjectOutputStream
for writing objects and ObjectInputStream
for reading objects.
Wildcards in Java Generics allow for more flexibility when working with generic types. There are two types of wildcards:
<?>
): Represents an unknown type that is a subtype of the specified bound.<? super T>
): Represents an unknown type that is a supertype of the specified bound.Type erasure is a feature in Java Generics where type information is erased at compile-time, and generic types are replaced with their bounding types or the Object
type. This is done to maintain compatibility with code written in older versions of Java that do not support generics. Type erasure ensures that generics do not affect the runtime performance of Java programs.
Java Reflection allows for the examination and manipulation of class metadata at runtime. It provides a way to inspect classes, interfaces, fields, methods, and other elements, as well as instantiate objects and invoke methods dynamically. Reflection is commonly used in scenarios such as creating frameworks, serialization, and dependency injection.
The java.lang.reflect
package provides classes and interfaces that support Java Reflection. Some key classes in this package include:
Class
: Represents classes and interfaces at runtime.Field
: Represents fields (variables) in a class.Method
: Represents methods in a class.Constructor
: Represents constructors in a class.try...catch
block or declared using the throws
clause in the method signature. Examples include IOException
and SQLException
.RuntimeException
or its subclasses. Examples include NullPointerException
and ArrayIndexOutOfBoundsException
.Custom exceptions, also known as user-defined exceptions, allow developers to create their own exception classes to represent specific error conditions in their applications. Custom exceptions must extend either Exception
or one of its subclasses. They are useful for improving code readability and handling application-specific errors.
JDBC (Java Database Connectivity) is a Java API that allows Java applications to interact with databases. It provides a standard interface for connecting to relational databases, executing SQL queries, and processing result sets. JDBC consists of the java.sql
package, which includes classes and interfaces for database access.
Class.forName("com.mysql.jdbc.Driver")
to load the appropriate JDBC driver.DriverManager.getConnection(url, username, password)
to establish a connection to the database.Statement
or PreparedStatement
object to execute SQL queries.Error: Contact form not found.