Notes
Notes
4. stop():
o Called when the applet becomes inactive or hidden.
These methods are called in a specific sequence to manage the applet's execution
from loading to termination.
2) Explain thread life cycle.
A thread in Java goes through the following states during its life cycle:
1. New (Created):
o A thread is in the "New" state when it is created using the Thread class
but hasn't started yet.
o Created by calling Thread t = new Thread();.
2. Runnable:
o The thread enters the "Runnable" state after calling start().
o It is ready to run but waits for the CPU to schedule it.
3. Running:
oWhen the CPU assigns time to the thread, it enters the "Running" state.
oThe run() method executes in this state.
4. Blocked/Waiting:
o The thread enters the "Blocked" or "Waiting" state when waiting for a
resource or a signal.
o Methods like sleep(), wait(), and join() can cause this state.
5. Terminated (Dead):
o The thread enters the "Terminated" state after the run() method
completes.
o Once terminated, the thread cannot be restarted.
These states manage a thread's execution from creation to termination.
3) a) Why Applets are not being used today? Explain. What is the order
of method invocation in an Applet?
b) How will you communicate between two Applets? Can Applet
have constructors?
c) What is the difference between panel and frame? What is the
default layout of the panel and frame?
1. Security Issues: Applets pose significant security risks, as they can access the local
system's resources. Modern browsers have disabled support for applets to prevent
security vulnerabilities.
2. Browser Support: Popular browsers like Chrome, Firefox, and Edge no longer support
the Java Plugin required to run applets.
3. Outdated Technology: With the rise of modern web technologies like HTML5, CSS,
and JavaScript, applets have become obsolete for web-based applications.
4. Performance Issues: Applets often suffer from poor performance and compatibility
issues across different browsers and platforms.
5. Alternative Technologies: JavaFX and other frameworks have replaced applets for
developing GUI applications.
The life cycle methods of an applet are invoked in the following sequence:
Two applets can communicate with each other by sharing information through the browser. The
communication process involves the following steps:
The constructor will be called when the applet instance is created, but applet initialization
should be done in the init() method because it is guaranteed to be called by the
browser.
Using constructors may lead to inconsistent behavior across different browsers.
Default Layouts:
Panel: The default layout is FlowLayout.
Frame: The default layout is BorderLayout.
The Java Virtual Machine (JVM) is a core part of the Java platform that enables Java programs
to be platform-independent. It is responsible for executing Java bytecode, which is generated
by the Java compiler. The JVM acts as a virtual processor that abstracts the underlying hardware.
1. Loading: The JVM loads .class files containing bytecode into memory.
2. Verification: It verifies the bytecode to ensure it is secure and adheres to Java standards.
3. Execution: The JVM interprets or compiles bytecode into machine code using Just-In-
Time (JIT) compilation for faster execution.
4. Memory Management: JVM handles memory through the Garbage Collector, which
automatically removes unused objects to free up memory.
5. Security: Provides a secure runtime environment by running programs in a sandbox to
prevent unauthorized access to system resources.
Components of JVM:
Importance of JVM:
Makes Java Write Once, Run Anywhere (WORA) by ensuring portability across
different platforms.
Ensures secure execution of Java programs with robust memory management.