我想了解小程序是如何工作的。
我知道类文件是字节码,是 JVM 可以理解和执行的东西。当小程序在用户系统上运行时,字节码通过网络传输到用户系统。
现在,当有多个类文件时会发生什么?例如,如果具有小程序的 init() 方法的类(A 类)具有我的另一个类(B 类)的对象,该怎么办? html 文件的 APPLET 标记中仍然包含 classA.class。在这种情况下,classB.class 是否也会通过网络传输?
另外,jar 文件如何放在这里?它们只是类文件的压缩集合,不是吗?
如果能清楚地了解其工作原理,我们将不胜感激。
谢谢,
I am trying to understand how applets work.
I understand that a class file is bytecode, something that a JVM can understand and execute. When an applet runs on the user's system, the bytecode is transferred to the user system over the network.
Now, what happens when there are more than one class files? For example, what if the class that has the applet's init() method (class A) has an object of another of my classes (Class B)? The html file still contains classA.class in the APPLET tag. In such a scenario, does the classB.class also gets transferred over the network?
Also, how do jar files fit in here? They are just a compressed collection of class files, isn't it?
Any clarity about how this works would be greatly appreciated.
Thanks,
发布评论
评论(4)
jar 文件是包含类的文件,它使用 zip 压缩。当浏览器找到引用小程序的标签时,它会将 jar 文件下载到客户端并运行它。
A jar file is the file that the classes are contained in, it uses zip-compression. When the browser finds a tag referring to an applet it downloads the jar file onto the client and runs it.
您的小程序所依赖的任何依赖项都将转移到客户端。这包括单个类和 jar 文件。
然而,许多 Java 开发人员现在更喜欢使用 Java Web Start小程序。 Web Start 应用程序不在浏览器内部运行,这有助于缓解不同浏览器的 Java 插件的兼容性问题。此外,Web Start 沙箱不像小程序在其中运行的沙箱那样受到限制。如果您已经以 Applet 形式编写了代码,它仍然可以作为 Web Start 应用程序启动。
Any dependencies that your applet relies on will be transferred to the client. This includes both individual classes and jar files.
However, many java developers now prefer using Java Web Start instead of applets. Web Start applications don't run inside the browser, which helps alleviate compatibility problems with different browsers' Java plugins. Furthermore, the Web Start sandbox is not as restrictive as the sandbox that applets run inside. If you have already written your code in Applet form, it can still be launched as a Web Start application.
我认为您上面描述的关键事实是,jar 文件在小程序运行之前由 JVM 传输和解释,因此知道并可以访问整个类层次结构。
I think the key fact from what you describe above is that the jar files get transferred and interpreted by the JVM before the applet runs and therefore knows and therefore can access the entire class hierarchy.
HTML 中已弃用
JAR 文件(在
我希望所有文件都是从小程序所在的 URL 的基部获取的;档案馆当然是。
我会查看 Java 教程来自太阳。他们有一个小程序,包括通过 Java Web Start 启动。
The
<APPLET>
tag is deprecated in HTML; the<OBJECT>
tag is supposed to be prefered. However, Sun (Oracle?) says that<APPLET>
is to be preferred as<OBJECT>
support is spotty. Take that for what it's worth.JAR files (in the context of
<APPLET>
) are specified with thearchive
parameter.I would expect that all files are fetched from the base of the URL that the applet was in; archives are certainly.
I'd check out the Java Tutorials from Sun. They have one on applets, including launching via Java Web Start.