Java Reference
In-Depth Information
file (see
Storing Strings in Properties and Preferences
)
. You can have more than one
-D
definition between the
java
command and your class name on the command line. At the
Unix or Windows command line, type:
java -D"pencil_color=Deep Sea Green" environ.SysPropDemo
When running this under an IDE, put the variable's name and value in the appropriate dialog
box, typically in the IDE's “Run Configuration” dialog.
The
SysPropDemo
program has code to extract just one or a few properties, so you can run it
like:
$
java environ.SysPropDemo os.arch
os.arch = x86
Which reminds me—this is a good time to mention system-dependent code.
Learning About
the Current JDK Release
talks about release-dependent code, and
Dealing with Operating
System-Dependent Variations
talks about OS-dependent code.
See Also
Storing Strings in Properties and Preferences
lists more details on using and naming your
own
Properties
files. The javadoc page for
java.util.Properties
lists the exact rules
used in the
load()
method, as well as other details.
Learning About the Current JDK Release
Problem
You need to write code that looks at the current JDK release (e.g., to see what release of Java
you are running under).
Solution
Use
System.getProperty()
with an argument of
java.specification.version
.