The difference between the Java runtime Environment and the Java applet's operating environment

Source: Internet
Author: User

Java applets, the Java applet, can be run in a Web browser. Java applets must be embedded in an HTML page as a <applet> script in order to run in a Web browser.

It was always thought that the JDK was installed locally, the Java_home and PATH environment variables were specified, and all the Java programs were ready to run, and then a colleague asked me to help him solve the Gantt chart in a Web browser that doesn't run a project management software. Applets and general Java applications are not configured to run the same environment.

Running Java applications on Windows, as long as there is a binary directory of the JDK, and specify a good java_home and path can be used directly, do not need to be installed through the JDK installation program. Therefore, the installed JDK directory can be compressed to backup, and later reinstall the system or to other machines to install the Java environment, the JDK will directly copy the binary compression package, after decompression can be used directly.

However, in Windows, configuring the Java applet's operating environment, specifying only the JDK directory is not possible and must be met:

    1. Installing with the JRE installer package
    2. The JRE version provides a Java Plugin for Web browsers
    3. The JRE is consistent with the Web browser's bit length, such as 32-bit, or 64-bit software version
This is because when the JRE is installed, Java-related information is written to the registry and Java Plugin is installed for the Web browser. The Java plugin of the Web browser, when running the applet, reads the Java information into the Windows registry before executing the applet.   Note here that the version of the JRE is different, and the supported Web browsers and versions are different. My native web browser has IE8, Firefox16, CHROME19, after installing JRE6U11, only IE8 can run applet;firefox16 down through About:plugins can see there installed Java Plugin, However, the applet cannot be run, while CHROME19 does not show Java Plugin. After installing JRE7U9, all browsers will be able to run applets. So the simplest thing to do is just install the latest version of the JRE. Usually if the browser does not have Java Plugin installed, when running the Web page with applets, users will be prompted to install plug-ins, generally directly after installation.  java Tester This site to check for locally installed JRE versions and software vendors, and to check if the Web browser can run applets: Java Tester- what version of Java is you using?  for general users, the installation applet runtime environment is very simple, but sometimes it is the Java Developer's browser instead of running the applet, which is a bit shabby. Java developers often install multiple Java versions on this machine, sometimes moving or deleting the JDK directories directly, without uninstalling through the Windows Control Panel, resulting in residual Java installation information in the Windows registry and running Java applications. In a Web browser, however, Java plugin cannot find the JRE to execute the applet.   After installing the JRE, a Java icon appears on the Java Control Panel, and if you find that the Java icon does not appear, you cannot find the program when you click, such as the Java icon that cannot be displayed on the:  . Indicates that the JRE environment on Windows has not been found and requires the JRE to be reinstalled. A normally available JRE environment, such as:   click on the Java icon, opens the Java Control Panel (JAVACPL), stating that the JRE on Windows is already available.   In summary, Java applications and Java applets have different requirements for the operating environment. When the Java application runs,You do not need to find the registry, as long as you specify a good JDK directory to run. For applet applets, Java plugin in a Web browser is going through the registry to find the JRE environment and run Java applets.   Therefore,recommended local Java environment:
    • install a high-version JREto support newer Web browsers running applet applets
    • The JDK required for Java applications is directly copied from the JDK binaries , does not need to be installed, multiple JDK can coexist, and the JDK version is determined at execution time.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------- Appendix 1: If you cannot reinstall the JRE, you can follow the steps in the following article to clear the Java residue installation information in the registry before you run the JRE installer:How do I clear the Java installation information in the registry? Appendix 2: How do I enable Java in a Web browser? (You must meet the prerequisites that the JRE is installed and the Web browser has Java plugin installed)

Http://www.java.com/zh_CN/download/help/enable_browser.xml

Appendix 3:hello applets

1. Write applets applet, inherit the applet base class:

Java code
  1. Public class Helloapplet extends Applet {
  2. private Static final long serialversionuid = 5511892956119084309L;
  3. @Override
  4. public void init () {
  5. Graphics g = this.getgraphics ();
  6. Paint (g);
  7. }
  8. public void Paint (Graphics g) {
  9. g.DrawString ("Hello applet!", 45);
  10. }
  11. }
public class Helloapplet extends Applet {    private static final long serialversionuid = 5511892956119084309L;    @Override public    void init () {        Graphics g = this.getgraphics ();        Paint (g);    }    public void Paint (Graphics g) {        g.drawstring ("Hello applet!", "a");}    }

2. Compiling applets

Java code
    1. Cmd>javac Helloapplet.java
Cmd>javac Helloapplet.java

3. Embed applet applets in the Index.html Web page

HTML code
    1. ...   
    2. <applet alt=code= "Cn.david.applet.HelloApplet.class"  archive= "Applet-1.0.0-snapshot.jar"   width="  height= "$"     
    3. codebase=>  
    4. </applet>  
    5. ...   
... <applet  code= "Cn.david.applet.HelloApplet.class" archive= "Applet-1.0.0-snapshot.jar"  width= "200" Height= "codebase=". ></applet>, .....

Attention:

    • Applet applets must be embedded in a Web page to run, embed applets with <applet></applet> tags
    • The Code property specifies the applet class
    • The Archive property specifies the jar package where the applet is located, if not packaged to omit
    • The CodeBase property specifies the root directory that is used to find the Applet class and Jar package, which is relative to the directory in which the Web page resides, specifying a relative directory. Codebase= ".", means to find applets applet in the Web directory.
    • You want to use the <applet></applet> tab in your Web page, and the <applet/> is working in the Web page, but you cannot display the applet window in Appletviewer.

4. Test applet applets with Appletviewer

Java code
    1. Cmd>appletviewer index.html
Cmd>appletviewer index.html

5. Running applet applets in a Web browser

Drag the Web page to the browser to view it, or deploy the Web page and applets applet to the Apache HTML document directory for access via URL.

Original Address http://yyjlinux.iteye.com/blog/1702514

The difference between the Java runtime Environment and the Java applet's operating environment

Related Article

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.