The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
You can set certain Java Virtual Machine arguments and secure properties for your rich Internet application (RIA) in the RIA's Java Network Launch Protocol (JNLP) file. For applets, you can also set arguments in the java_arguments
parameter of the <applet>
tag. Although there is a predefined set of secure properties, you can also define new secure properties by prefixing the property name with "jnlp.
" or "javaws.
". Properties can be retrieved in your RIA by using the System.getProperty
method.
Consider the Properties and Arguments Demo applet. The following Java Virtual Machine arguments and properties are set in the applet's JNLP file, appletpropsargs.jnlp
.
-Xmx
– A secure argument set equal to "256M"sun.java2d.noddraw
– A predefined secure property set equal to "true"jnlp.myProperty
– A user-defined secure property set equal to "a user-defined property"<?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="" href=""> <information> <title>Properties and Arguments Demo Applet</title> <vendor>Dynamic Team</vendor> </information> <resources> <!-- Application Resources --> <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" <!-- secure java vm argument --> java-vm-args="-Xmx256M"/> <jar href="applet_PropertiesAndVMArgs.jar" main="true" /> <!-- secure properties --> <property name="sun.java2d.noddraw" value="true"/> <property name="jnlp.myProperty" value="a user-defined property"/> </resources> <applet-desc name="Properties and Arguments Demo Applet" main-class="PropertiesArgsDemoApplet" width="800" height="50"> </applet-desc> <update check="background"/> </jnlp>
The PropertiesArgsDemoApplet
class uses the System.getProperty
method to retrieve the java.version
property and other properties that are set in the JNLP file. The PropertiesArgsDemoApplet
class also displays the properties.
import javax.swing.JApplet; import javax.swing.SwingUtilities; import javax.swing.JLabel; public class PropertiesArgsDemoApplet extends JApplet { public void init() { final String javaVersion = System.getProperty("java.version"); final String swing2dNoDrawProperty = System.getProperty("sun.java2d.noddraw"); final String jnlpMyProperty = System.getProperty("jnlp.myProperty"); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(javaVersion, swing2dNoDrawProperty, jnlpMyProperty); } }); } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); } } private void createGUI(String javaVersion, String swing2dNoDrawProperty, String jnlpMyProperty) { String text = "Properties: java.version = " + javaVersion + ", sun.java2d.noddraw = " + swing2dNoDrawProperty + ", jnlp.myProperty = " + jnlpMyProperty; JLabel lbl = new JLabel(text); add(lbl); } }
The Properties and Arguments Demo applet is shown next. You can also see the applet running in AppletPage.html
.
Download source code for the Properties and Arguments Demo Applet example to experiment further.
See System Properties for a complete set of system properties that can be accessed by RIAs.