Java Applet Life Cycle: Initialization, Execution and Termination
Learn the legacy applet callback model per instance, then trace exact field values across repeated start, paint, stop and destroy events.
KnowledgeGate Team
Exam prep & CS education

The mnemonic init() -> start() -> paint() -> stop() -> destroy() hides that start() and stop() can repeat for a retained instance, while paint() can run any number of times. For one instance, score changes 10 -> 13 -> 11 -> 14 -> 12 -> 0, start() runs twice, and paint() runs three times. Applets are legacy Java lifecycle material, not browser technology to deploy. Revise the broader class and inheritance context in Object Oriented Technology Explained: Four Pillars in Java.
Build the per-instance life cycle before memorising methods
A legacy browser or applet viewer creates an Applet subclass instance and controls its callbacks; there is no main(). For one instance, init() precedes the first start(). An active phase may receive any number of paint requests. stop() ends it, and a later start() may reopen it if the host retains the instance. Reclamation follows stop() with destroy().
The useful invariant is:
new instance -> init once -> [start -> paint zero or more times -> stop] one or more active cycles -> destroy once
The bracketed cycle repeats only when the stated host events retain the instance.
The host calls init(), start(), stop() and destroy(). AWT invokes paint(Graphics) when needed. Code may request rendering with repaint(), but paint() is not a mandatory fifth milestone.

Give each callback one clear responsibility
The Java SE 8 Applet API guarantees init() before the first start(), and stop() before destroy().
Method | Typical job | Frequency for one instance | Do not confuse it with |
|---|---|---|---|
| One-time setup after the host environment exists | Once | The constructor |
| Start or resume active work; return quickly | One or more times | Initialization |
| Draw current state when AWT requests it | Zero or many times | A cycle counter |
| Pause work; release activity-only resources | Per ended active phase | Final deletion |
| Final cleanup before reclamation | Once | Lengthy essential work |
Oracle warns that a long destroy() may not finish, so essential state should not depend on lengthy shutdown. Constructors create objects; applet-environment work belongs in init(). As an AWT callback, paint() cannot measure starts, visits or active cycles.
Work the counter applet through two active cycles
This is historical Java SE 8 lifecycle code, not current-browser or current-JDK code. paints changes only to expose callback count.
import java.applet.Applet;
import java.awt.Graphics;
public class ScoreApplet extends Applet {
private int score;
private int starts;
private int paints;
private boolean active;
public void init() {
score = 10;
starts = 0;
paints = 0;
active = false;
}
public void start() {
starts++;
score += 3;
active = true;
}
public void paint(Graphics g) {
paints++;
g.drawString(
"score=" + score + ", starts=" + starts
+ ", paints=" + paints + ", active=" + active,
10, 20
);
}
public void stop() {
score -= 2;
active = false;
}
public void destroy() {
score = 0;
active = false;
}
}Apply only the listed events, in order:
Event | score | starts | paints | active | visible text if painted |
|---|---|---|---|---|---|
| 10 | 0 | 0 | false | None |
| 13 | 1 | 0 | true | None |
| 13 | 1 | 1 | true |
|
| 13 | 1 | 2 | true |
|
| 11 | 1 | 2 | false | None |
| 14 | 2 | 2 | true | None |
| 14 | 2 | 3 | true |
|
| 12 | 2 | 3 | false | None |
| 0 | 2 | 3 | false | None |
Score is 10 + 3 = 13, 13 - 2 = 11, 11 + 3 = 14, 14 - 2 = 12; destroy() assigns 0. Only painting changes paints.
![Event strip showing nine applet lifecycle stages from init [10,0,0,F] through two starts, three paints, two stops, and destroy [0,2,3,F].](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1784738001385_ec9l7r.jpg)
Understand why paint() breaks the five-method mnemonic
AWT may request paint(Graphics) for first display, exposure, resizing or repaint. Two paints between one start() and stop() still belong to one active cycle. The safer model has four lifecycle milestones plus AWT rendering.
Trace A is init, start, paint, paint, stop. Its counts are init=1, start=1, paint=2, stop=1, destroy=0. Trace B is init, start, stop, start, paint, stop, destroy. Its counts are init=1, start=2, paint=1, stop=2, destroy=1. Both are legal because their stated host schedules contain different numbers of active phases and paint requests.
repaint() requests future painting. It does not synchronously prove that paint() has completed. Normal application design keeps data updates outside rendering; this example increments paints only as instrumentation. For related revision on mutable and immutable state, read String Handling in Java: Pool and Immutability. Applet fields are not automatically persistent.
Distinguish pause, return, reload and final termination
Host scenario | Callback consequence |
|---|---|
Page inactive, instance retained |
|
Instance reclaimed |
|
Reload creates a fresh instance | Old |
Redraw while active | Another |
If the instance is retained after stop #1, its second start adds 3 to score=11 and reaches 14. If it is destroyed and replaced, the new init() resets score to 10, then its first start() reaches 13. This distinguishes resumption from construction.
The Java SE 8 API supplies the method rules. Oracle's Java 8 applet lifecycle tutorial illustrates reload and new-instance behaviour, but does not establish universal browser caching. OpenJDK JEP 504, closed and delivered for JDK 26, records the Applet API's removal after browser and JDK execution support had disappeared.
Repair the common lifecycle mistakes
Treating
init()as a constructor → it is a host callback after construction.Expecting
main()→ applet execution is host-controlled.Assuming
start()runs once → it may run again for a retained instance.Assuming one
paint()follows every start → painting may run zero or many times.Using
stop()as final deletion → it pauses activity and may be followed bystart().Doing all cleanup only in
destroy()→ suspend active work instop()and keep final cleanup short.
Order drill: init, start, paint, stop, start, paint, stop, destroy is valid for a retained instance. start before init breaks initialization order. destroy before the final stop breaks termination order. A second init breaks the once-per-instance rule. Two paints cannot force two starts because painting is zero-or-more work inside an active phase.
Java Applet Life Cycle practice on KnowledgeGate reinforces callback order and state tracing. Practice availability does not establish official recurrence or topic weightage.
How exam-style questions test applet life-cycle reasoning
Use these practice formats: arrange callbacks; match their roles; count calls from a schedule; distinguish retained and fresh instances; predict fields across cycles; and explain repeated paints.
Use this 20-second routine: mark the instance boundary; put init before the first start; bracket each start ... stop; insert every stated paint but invent none; place stop before destroy; update fields once per event. The result is 10 -> 13 -> 13 -> 13 -> 11 -> 14 -> 14 -> 12 -> 0, with init=1, start=2, paint=3, stop=2, destroy=1.
Fresh check: init() sets value=4, each start() doubles it, each stop() subtracts 3, and destroy() sets 0. For init, start, stop, start, stop, destroy:
init:value = 4.First
start:4 x 2 = 8.First
stop:8 - 3 = 5.Second
start:5 x 2 = 10.Second
stop:10 - 3 = 7.destroy: assignvalue = 0before reclamation.
Short version and the next Java study step
One
init()runs per instance.start()begins or resumes active work.paint()renders whenever AWT asks.stop()pauses and always precedesdestroy().destroy()performs final cleanup.A fresh instance restarts at
init(), while a retained instance resumes with its fields.
Under the explicit nine-event schedule, one instance reaches score=14 on its second start, receives three paints across two active cycles, then moves through 12 at the final stop to 0 at destroy.
Use Java Programming for the wider language sequence, DSA using Java for implementation practice, or Coding & DSA Courses for Placements for broader navigation. None advises applet deployment.
Keep learning
Software Development Life Cycle MCQs: 12 Solved Questions on SDLC Stages
Solve 12 published SDLC MCQs with direct explanations, stage cues, and a worked campus clinic portal that connects requirements, design, testing, and maintenance.
JRE and JVM Explained: How Java Loads and Executes Bytecode
Trace one Java program from source to bytecode and execution, then use the exact output to separate compilation, loading, linking, initialization and JIT.
Linked List Problems in Java: Reversal, Cycle Detection, and the Interview Classics Traced
Trace the pointers behind in-place reversal and Floyd's cycle algorithm, then reuse the same habits for other linked list interview problems.
Mental Health and Life Skills for Teaching Exams: Complete Notes, Examples and Traps
Revise mental health, ten life skills and counselling approaches through clear contrasts, classroom examples and fast option-elimination rules.





