wrapper class
wrapper class
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
Nested class
Grabage Collection
finalize() method
Package
Generic Programming
Java - Generics
No scarification of type-safety
No requirement of type-casting
Compile-time checking
Code reusability and improved performance
Base Derived
Derived from Exception
class from RuntimeException
Threading
Threading in Java enables concurrent execution of multiple parts of a
program. Threads are lightweight processes that share the same memory
space, allowing for efficient communication and resource sharing. Java
provides the Thread class and the Runnable interface to create and manage
threads.
Creating Threads
Extending the Thread class: A class can extend the Thread class and override
the run() method to define the task performed by the thread.
Thread Lifecycle
Threads go through different states during their lifecycle:
New: Thread is created but not yet started.
Runnable: Thread is ready to run and waiting for CPU time.
Running: Thread is currently executing.
Blocked/Waiting: Thread is waiting for a resource or condition.
Terminated: Thread has completed execution or has been terminated.
New State
As we use the Thread class to construct a thread entity, the thread is born and is
defined as being in the New state. That is, when a thread is created, it enters a new
state, but the start() method on the instance has not yet been invoked.
Runnable State
A thread in the runnable state is prepared to execute the code. When a new thread's
start() function is called, it enters a runnable state.
In the runnable environment, the thread is ready for execution and is awaiting the
processor's availability (CPU time). That is, the thread has entered the queue (line)
of threads waiting for execution.
Running State
Running implies that the processor (CPU) has assigned a time slot to the thread for
execution. When a thread from the runnable state is chosen for execution by the
thread scheduler, it joins the running state.
In the running state, the processor allots time to the thread for execution and runs its
run procedure. This is the state in which the thread directly executes its operations.
Only from the runnable state will a thread enter the running state.
Blocked State
When the thread is alive, i.e., the thread class object persists, but it cannot be
selected for execution by the scheduler. It is now inactive.
Dead State
When a thread's run() function ends the execution of sentences, it automatically dies
or enters the dead state. That is, when a thread exits the run() process, it is
terminated or killed. When the stop() function is invoked, a thread will also go dead.
Multithreading in Java
In Java, multithreading is the method of running two or more threads at the same
time to maximize CPU utilization. As a result, it is often referred to as Concurrency
in Java. Each thread runs in parallel with the others. Since several threads do not
assign different memory areas, they conserve memory. Furthermore, switching
between threads takes less time.
What is Swing?
In Java, a swing is a light-weighted, GUI (graphical user interface) that is used for
creating different applications. It has platform-independent components and enables
users to create buttons as well as scroll bars.