0% found this document useful (0 votes)
5 views

Java Applet Notes Cleaned

Java applets are small programs that run in web browsers, providing dynamic and interactive content. They have advantages such as client-side execution and platform independence, but face drawbacks including the need for a Java plugin and deprecation in modern browsers. The document outlines the features, types, lifecycle, development process, and limitations of applets, along with common use cases.

Uploaded by

Feysel Kasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Applet Notes Cleaned

Java applets are small programs that run in web browsers, providing dynamic and interactive content. They have advantages such as client-side execution and platform independence, but face drawbacks including the need for a Java plugin and deprecation in modern browsers. The document outlines the features, types, lifecycle, development process, and limitations of applets, along with common use cases.

Uploaded by

Feysel Kasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Detailed Notes on Java Applets

1. Introduction to Java Applets

- Applets are small programs designed to run in a web browser or an applet viewer.

- Divided into:

- Java Applet: Requires embedding in an HTML file.

- Java Application: Runs as standalone programs with a main() method.

2. Features of Java Applets

- Dynamic and interactive content for web pages.

- Allows animations, computations, graphical displays, and sound.

- Runs securely within a sandbox environment in the browser.

3. Types of Applets

- Local Applets: Created and stored locally, no internet connection needed.

- Remote Applets: Hosted on a remote server, downloaded and run via the internet.

4. Advantages of Applets

- Executes on the client side, reducing response time.

- Platform-independent; works on Linux, Windows, MacOS, etc.

- Secure, as applets are sandboxed and limited in accessing system resources.

5. Drawbacks of Applets

- Requires a Java plugin in the client browser.

- Applet support has been deprecated in modern browsers.


6. Applet vs. Application

- Applets:

- Require a browser or applet viewer to run.

- Do not use a main() method.

- Restricted in accessing files and network resources.

- Applications:

- Run independently using Java interpreter.

- Use a main() method for execution.

- Can access files, network servers, and libraries.

7. Life Cycle of an Applet

- Initialization (init()):

- Called once when the applet is loaded.

- Used to set up initial values, load resources like images or fonts.

- Running (start()):

- Called after init() or when returning from an idle state.

- Can be called multiple times.

- Idle/Stopped (stop()):

- Called when the applet is paused, e.g., user navigates away from the page.

- Dead/Destroyed (destroy()):

- Called when the applet is permanently terminated.

- Display (paint(Graphics g)):

- Used to draw and display the applet content on the screen.

8. Developing and Running an Applet

- Steps:

1. Write Java source code and compile it (javac command).


2. Embed compiled .class file in an HTML page using <APPLET> tag.

3. Run the applet using a browser or the appletviewer tool.

- Example of embedding in HTML:

<APPLET CODE="HelloJava.class" WIDTH=400 HEIGHT=200></APPLET>

9. Graphics and Interaction

- Graphics Class:

- Methods for drawing shapes, lines, and strings:

- drawLine(x1, y1, x2, y2)

- drawRect(x, y, width, height)

- drawString(String text, x, y)

- Color Class:

- Create custom colors or use predefined ones:

- setBackground(Color.RED)

- setForeground(new Color(r, g, b))

- Font Class:

- Define font styles and sizes:

- Font f = new Font("Arial", Font.BOLD, 14);

- g.setFont(f);

10. Key Methods in Applet Class

- init(): Called for initialization.

- start(): Activates the applet.

- stop(): Pauses the applet.

- destroy(): Terminates the applet.

- paint(Graphics g): Handles drawing content.


11. Applet Limitations

- Cannot access the file system or communicate with servers other than the host.

- Restricted from using external libraries outside the Java sandbox.

12. Steps to Build an Applet

- Write and compile the applet Java file (HelloJava.java -> HelloJava.class).

- Create an HTML file with the <APPLET> tag referencing the .class file.

- Test using:

- A Java-enabled browser.

- appletviewer for simple testing.

13. Common Use Cases

- Embedding interactive graphics.

- Performing dynamic updates (like animations or small computations) on web pages.

- Providing platform-independent web content.

These notes provide a comprehensive overview of Java applets, suitable for reference or study.

You might also like