What is an applet

Source: Internet
Author: User

An applet is a Java program. It is typically run inside a Java-enabled web browser. Because it has full Java API support, the applet is a full-featured Java application.

The important differences between standalone Java applications and applet programs are as follows:

    • The Applet class in Java inherits the Java.applet.Applet class
    • The applet class does not define main (), so an applet program does not call the main () method,
    • Applets is designed to be embedded in an HTML page.
    • When the user browses to the HTML page containing the applet, the applet's code is downloaded to the user's machine.
    • A JVM is required to view an applet. The JVM can be a plug-in for a Web browser, or a standalone runtime environment.
    • The JVM on the user's machine creates an instance of an applet class and invokes various methods in the applet life cycle process.
    • Applets has strict security rules enforced by web browsers, and the security mechanisms of applets are known as sandbox security.
    • Other classes required by the applet can be downloaded in the form of a Java archive (JAR) file.
Second, the working principle Java Applet can greatly improve the interactive ability of web pages and dynamic execution ability. Pages that contain applets are called java-powered pages, which can be referred to as Java-supported web pages. Whenapplet When a user accesses such a Web page, the applet is downloaded to the user's computer for execution, but only if the user is using a Java-enabled web browser. Because the applet is executed on the user's computer, its execution speed is not limited by the network bandwidth or modem access speed, the user can better appreciate the multimedia effect produced by the applet on the webpage. The implementation of applet applets relies primarily on the applet classes in the Java.applet package. Unlike a typical application, an applet application must be embedded in an HTML page to be interpreted and executed, while an applet can get parameters from a Web page and interact with the Web page. An applet is a Java applet that is run by a Java-enabled web browser by using the applet's HTML file. It can also be run through the appletviewer of Java development tools. The applet program cannot be separated from the HTML file that uses it. The information about the applet in this HTML file should contain at least the following three points: 1) The bytecode file name (the compiled Java file, with a. class suffix) 2) The address of the bytecode files 3) The way the applet is displayed on the Web page. An HTML file that increases the content of an applet simply makes the page more animated, such as adding sounds, animations, and other appealing features that do not alter the HTML file's irrelevant elements. Security restrictions in order to prevent such problems, in the default situation, most browsers are subject to many restrictions on the security of applets, almost no "read" or "write" operation of the system: 1. Applets are not allowed to access local file system 2. Applets cannot perform any program 3 on the local computer. Applets are not allowed to attempt to open the Socket4 of any system other than the server that provides the applet. Applets are not allowed to access information about the local system, such as user names, e-mail addresses, etc. 5. For applets, some standard system properties in the Java environment are read-only 6. The applet cannot create or load the network connection for the applet's machine 7. Applets cannot act as a network server, listening to or receiving connection requests from remote systems 8. Applets are not allowed to load dynamic libraries or to define local method call 9. Applets cannot manipulate any thread that is not in their own thread group 10. Applets cannot shut down the JVM.

Iii. converting applications into applets

Converting a graphical Java application (that is, an application using AWT and a program launched using the Java Program Launcher) to an applet embedded in a Web page is straightforward.

Here are a few steps to convert an application into an applet:

    • Write an HTML page with a label that can load the applet code.
    • Write a subclass of the JApplet class and set the class to public. Otherwise, the applet cannot be loaded.
    • Removes the main () method of the application. Do not construct a frame window for your application, because your application will appear in the browser.
    • Moving the initialization code in the construction method of the frame window in your application to the applet's init () method, you do not have to display the construction applet object, and the browser will instantiate an object by calling the Init () method.
    • Remove the call to the SetSize () method, and for the applet, the size has been set by the width and height parameters in the HTML file.
    • Removes the call to the Setdefaultcloseoperation () method. The applet cannot be closed, and it terminates with the browser's exit.
    • If the application calls the Settitle () method, the call to the method is eliminated. Applets cannot have a title bar. (You can, of course, name the page itself by the title tag of the HTML)
    • Do not call setvisible (true), the applet is automatically displayed.

Iv. Summary

Applet programs can only be embedded in the HTNL Web page through the browser to run, the purpose is to enhance the performance of the Web page and interactive mode.

What is an applet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.