Java cafe (11): Java Plug-in technology

Source: Internet
Author: User

1. Java Plug-in technology

Java Plug-in technology is a magical design that builds popular browsers (including Internet Explorer, Internet Explorer, and Netscape Navigator, the bridge between NN and Mozilla and the Java platform. That is to say, you only need a browser. It does not have to have a built-in Java Virtual Machine (such as IE 6, which is bound to Windows XP) or install the Java Runtime Environment. When you open a webpage containing a Java Applet, you only need to follow the browser prompts to install the Java Plug-in before you can run the Applet, and the installation process is as simple as installing plug-ins such as Macromedia Flash and 3721.

You know, the Java Plug-in technology is essentially different from the method we introduced in the last cafe to run the Applet.

In the last Java cafe, I introduced the Applet compilation process and the method for running the Applet in IE. Recall that we implemented it by embedding the <applet> tag in an HTML webpage. In fact, if you have installed the Java Runtime Environment in your system, when the browser encounters the <applet> label, the browser starts the Java Virtual Machine, download the Applet class file from the Internet and execute it. This method has two obvious disadvantages: first, if there is no Java Runtime Environment in the system, the browser will say it is easy and refuse to execute the Applet; second, if the system's Java Runtime Environment version is too low, and the Applet uses the new technology in the new version, this will also cause the Applet to run abnormally.

The Java Plug-in technology can solve these two problems well. Essentially, Java Plug-in technology is a technology that uses the browser plug-in mechanism to install or update the Java Runtime Environment on the client. Currently, popular browsers have plug-ins, such as Mozilla and NN plug-in technology and IE ActiveX component technology. When these browsers encounter Java Plug-in labels on the webpage, they will automatically connect to Sun's server to download or update the Java Runtime Environment and then run the Applet. This saves the inconvenience of installing the Java Runtime Environment on your own.

2. Using Java Plug-in technology to call the Applet

Java Plug-in technology cannot rely on the <applet> label to call the Applet. You must call the Java Plug-in just like calling other NN plug-ins or ActiveX components of IE.

Let's take an example. The original sample.htm webpage calls the Applet as follows:

<applet code="NewsApplet.class" codebase="." width=480 height=384>
<param name="from" value="Prince Charming">
<param name="to" value="Cinderella">
</applet>


The Java Plug-in corresponding to NN needs to be written as follows:

<embed type="application/x-java-applet;jpi-version=1.5"
code="NewsApplet.class"
width=480
height=384
pluginspage = "http://java.sun.com/products/plugin/index. html#download"
from="Prince Charming"
to="Cinderella">
</embed>

The Java Plug-in corresponding to the ActiveX component technology of IE needs to be written as follows:

<object classid="clsiD:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-Windows-i586.cab#Version=1,5,0,0"
width=480 height=384>
<param name="code" value="NewsApplet.class">
<param name = "type" value = "application/x-java-applet;jpi-version=1.5">
<param name="from" value="Prince Charming">
<param name="to" value="Cinderella">
</object>

Of course, if you want to write code that can adapt to all browsers calling Java Plug-ins, you can use NN to ignore the <object> and <comment> labels, and IE ignores the fact that the <embed> label is nested, similar

<object ...>
<comment>
<embed ...>
</embed>
</comment>
</object>


In this way, both IE and NN will execute the Applet and let the prince say that word to Cinderella.

3. Upgrade the Valentine's Day Applet

Now, we need to upgrade the style appletprogram, which is very simple. However, we need to modify the following part of the original index.htm code:
...

document.write(<applet code="NewsApplet.class" codebase="."width=480 height=384>);
document.write( <param name="from" value=" + from + ">);
document.write( <param name="to" value=" + to + ">);
document.write(</applet>);

...
The modified code is as follows:
...
document.write(<object classid="clsiD:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-Windows-i586.cab#Version=1,5,0,0" width=480 height=384>);
document.write( <param name="code" value="NewsApplet.class">);
document.write( <param name = "type" value = "application/x-java-applet;jpi-version=1.5">);
document.write( <param name="from" value=" + from + ">);
document.write( <param name="to" value=" + to + ">);
document.write(</object>);

...
Note: To save space, only the ActiveX Code corresponding to IE is provided here.

When she enters a URL containing you and her name in the IE Address Bar, her browser will prompt 1 to install the plug-in (see figure 1 ). Select "yes ". After receiving the license agreement, the plug-in Automatically downloads the latest Java Runtime Environment from Sun's website (see figure 2 ).

Figure 1

 

Figure 2

After the installation is complete, she will be able to see the gift you carefully prepared, isn't it a little trouble? You can use http://www.cfan.com.cn/11program/200504/index.htmto directly experience the appletaskof this new website.

4. Strength of Java Plug-in technology

The Java Plug-in technology is an important part of the Java Runtime Environment. With its help, the Applet finds its best partner, in the future, the Applet may be more inclined to use this browser-based plug-in technology than the <applet> label.

In addition, the Applet function added to the Swing Technology is richer, as shown in Figure 3 is an Applet interface added to the Swing Technology (see figure 3 ).

Figure 3

You know, you only need a browser to get this function, and it is an XP interface style! If a Blog can provide such powerful functions, we believe it will be the best choice for Blogger.

In short, the emergence of Java Plug-in technology largely makes up for the shortcomings of Java in desktop applications. Although Java continues to rise in application trends, the <applet> tag in HTML is slowly forgotten, largely due to Microsoft's monopoly in the desktop system market. If the desktop system is more open, Sun can say with confidence that "Sun is angry and has serious consequences". I believe that Java and. the result of fair competition of Net technology will create two more perfect systems, rather than limiting competition technology through market means. This is a major concern.

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.