java.util.Properties is a platform-independent generalisation of the DOS (Disk Operating System) SET environment, or the Windows *.INI files. In Java, even each object could have its own list of properties. A program can determine if an entry is missing in the property file and provide a default to using it its place. Even though property names typically have dots in them, there is no matching hierarchical structure like the NT registry, not even sections as with the Win 3.1 INI files. Properties are just glorified Hashtables that can be backed to to disk in human-readable format. You lookup by property name and get a value. Properties also can be used to store other sorts of key=value data on disk. (They will even work with key:value or key value pairs.)
You can interrogate the run-time environment with code like this:
// get a system property String vendor = System.getProperty( "java.vendor" ); System.out.println( vendor );
To discover the entire list of supported system properties and their current values you could use code like this:
Unfortunately that code produces a list in scrambled order. It won’t be either alphabetical or in the order of the original properties file, because underneath, Properties are just old fashioned, non-generified Hashtables, suporting the old fashioned, non-generified Enumeration interface.
The System properties are generated by a magic native method System.initProperties. There is no corresponding jar element or *.properties file on disk. file. You can temporarily add a System property with the -D option on the java.exe line. You can also use the technique to pass the value of a SET variable in as a system property. For Applets, there is a similar PARAM mechanism that generates a properties table.
When you are debugging an Applet, you can see the system properties by typing s on the Applet console. You can dump them in an app with:
// debugging dump System properties on the console System.getProperties().list( System.out );
If you have a property with a space in it quote the whole thing like this:
You get get the properties one at a time (mandatory in unsigned Applets):
System.getProperty( "java.version" );
Or you can get all the properties at once:
System.getProperties().getProperty( "java.version" );so you won’t trigger a security violation in an Applet in the process of getting one of the unrestricted properties. System.getProperties will always raise a security exception in an Applet (since it fetches both everything, both restricted and unrestricted properties) but System.getProperty may or may not, depending on which property you ask for.
Here is how you you can set a property to turn on anti-aliasing.
// turn on anti-aliasing for smooth fonts. System.setProperty( "swing.aatext", "true" );
| System
PropertyName |
Typical Value | Description | accessible
in unsigned Applet? |
|---|---|---|---|
| awt.toolkit | sun.awt.windows.WToolkit | name of AWT (Advanced Windowing Toolkit) implementation | |
| awt.useSystemAAFontSettings | what sort of anti-aliasing to use. | ||
| browser | sun.plugin | name of browser | |
| browser.version | 1.1 | version of browser | |
| deployment.browser.path | F:\Program Files (x86)\Mozilla Firefox\firefox.exe | Browser to use when Java Applet wants to display HTML (Hypertext Markup Language) | |
| deployment.cache.max.size | -1 | Limit on cache size. | |
| deployment.console.startup.mode | SHOW | Whether you want the console to show. | |
| deployment.javaws.concurrentDownloads | 4 | Max number of simultaneous downloads. | |
| deployment.javaws.home.jnlp.url | http://java.sun.com/products/javawebstart | Home page for Java Web Start | |
| deployment.max.output.file.size | 10 | ?? | |
| file.encoding | Cp1252 | default encoding e.g. Cp1252 | |
| file.separator | \ | File separator (e.g.,\ for Windows, / for Unix) | |
| java.class.path | wassup.jar | Java classpath | |
| java.class.version | 51.0 | Java class file format version number | |
| java.ext.dirs | C:\Program Files\Java\jre6\lib\ext; C:\Windows\Sun\Java\lib\ext | Path of extension directory or directories | |
| java.home | C:\Program Files\java\jre7 | Java JRE (Java Runtime Environment) installation directory. Note this does not typically match your JAVA_HOME environment variable. | |
| java.io.tmpdir | C:\Users\roedy\AppData\Local\Temp\ | Default temp directory | |
| java.library.path |
.; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; F:\Program Files (X86)\jet7.6-pro\bin; E:\Program Files\Java\jdk1.7.0_21\bin; E:\env; E:\sys; F:\Program Files (x86)\JPSoft\TCMD13; F:\Program Files\vslick\win; F:\Program Files (x86)\apache-ant-1.8.2\bin; F:\Program Files\PostgreSQL\9.0\bin; E:\com\mindprod\reorg; F:\Program Files (x86)\asm; F:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE (Integrated Development Environment)\; F:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN; F:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools; C:\Windows\Microsoft.NET\Framework\v4.0.30319; C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin; C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\; C:\Program Files\Microsoft SQL Server\100\Tools\Binn\; C:\Program Files\Microsoft SQL Server\100\DTS (Digital Theater Systems)\Binn\; F:\cygwin\bin; C:\Program Files (x86)\QuickTime\QTSystem; F:\Program Files\TortoiseSVN\bin |
List of paths to search when loading libraries.
Contains the exe path. On Linux and Mac, legs will be separated by : not ; . |
|
| java.protocol.handler.pkgs | package prefixes to search for custom protocol
handler classes.
Packages separated by |. |
||
| java.runtime.version | 1.6.0_16-b03 | Java Runtime version. | |
| java.specification.name | Java Platform Specification | Java Runtime Environment specification name | |
| java.specification.vendor | Oracle Corporation | Java Runtime Environment specification vendor | |
| java.specification.version | 1.7 | Java Runtime Environment specification version | |
| java.vendor | Oracle Corporation | JRE vendor | |
| java.vendor.url | / | JRE vendor URL (Uniform Resource Locator) | |
| java.version | 1.7.0_21 | JRE version number | |
| java.vendor.url.bug | http://bugreport.sun.com/bugreport/ | Where to report bugs | |
| java.vm.name | Java HotSpot(TM) Client VM | Java Virtual Machine implementation name | |
| java.vm.specification.name | Java Virtual Machine Specification | Java Virtual Machine specification name | |
| java.vm.specification.vendor | Oracle Corporation | Java Virtual Machine specification vendor | |
| java.vm.specification.version | 1.0 | Java Virtual Machine specification version | |
| java.vm.vendor | Oracle Corporation | Java Virtual Machine implementation vendor | |
| java.vm.version | 22.0-b10 | Java Virtual Machine implementation version | |
| line.separator | [hex chars: 0x0d 0x0a i.e. CrLf, \r\n] | Line separator, e.g. \r\n on Windows, \r on Mac, \n on Unix | |
| os.arch | x86 | Operating system architecture, e.g. x86, amd64 for 64 bit mode. | |
| os.arch.data.model | 32 | 32 or 64-bit addressing | |
| os.name | Windows 7 | Operating system name, e.g. Vista, Windows 7 | |
| path.separator | ; | Path separator (e.g., ; for Windows; : for Unix) | |
| sun.boot.class.path |
C:\Program Files\Java\jre7\lib\resources.jar; C:\Program Files\Java\jre7\lib\rt.jar; C:\Program Files\Java\jre7\lib\sunrsasign.jar; C:\Program Files\Java\jre7\lib\jsse.jar; C:\Program Files\Java\jre7\lib\jce.jar; C:\Program Files\Java\jre7\lib\charsets.jar; C:\Program Files\Java\jre7\classes |
Classpath with all of Sun and browser jars. | |
| sun.boot.library.path | C:\Program Files\java\jre7\bin | where DLLs (Dynamic Link Libraries) are. | |
| sun.io.unicode.encoding | UnicodeLittle | endian, UnicodeLittle or UnicodeBig | |
| sun.cpu.isalist | amd64 | Using 64-bit addressing. | |
| swing.aatext | true | turns on anti-aliasing for smooth fonts in Java version 1.5 or later | |
| user.country | US | two-letter country code, upper case. This is broken. It will say US for counries such as Canada. Oracle is telegraphing imperialistic plans. | |
| user.country.format | CA | two-letter country code, upper case. I am not sure if setting this property is sufficent to select a different locale, unless the app looks at this field. | |
| user.dir | C:\Windows\system32 | User’s current working directory | |
| user.home | C:\Users\roedy | User home directory | |
| user.language | en | two-letter language code, lower case. I am not sure if setting this property is sufficent to select a different locale, unless the app looks at this field. | |
| user.name | Roedy | User account name. | |
| user.region | CA | two-letter country code, upper case, used for DVD (Digital Video Disc) region code digital rights enforcement. | |
| user.timezone | America/Los_Angeles | time zone name e.g. America/Los_Angeles for PST (Pacific Standard Time).
not always available. Use TimeZone. getDefault() instead. |
There are a number of other less commonly used properties I did not list. See Wassup for a list of them. Applications and Jet compiled applications will see the most properties. Signed Applets will see somewhat fewer, and unsigned Applets will see only a few. The policy file controls which you will see.
The only way I know of to determine which properties are safe in unsigned Applets and which are restricted to applications and signed Applets is to write test Applet to fetch the properties and see which ones raise an Exception.
I used an unsigned version of Wassup to create this table. There are even more properties I did not list, especially if you run in a browser or under Jet.
There are also system properties for proxies that you are not present when there are no proxies.
There are no system properties to tell you about the JDK (Java Development Kit).
There is no system property to tell you how many cpus there are. However, you can get it with Runtime.availableProcessors.
You can also dynamically set the system properties with System. setProperty, but of course the Security Manager will be on your case if you do this in an unsigned Applet.
In Windows, a dot in the environment PATH means search the current directory. Normally you leave it out and one is presumed at the head of the PATH.
In all OSes, in the classpath, a dot means search the current directory. If you leave it out, the current directory will not be searched for class files.
Java creates the java.library.path from the environment PATH, adding to it. If it finds no dot in the PATH, it adds one at the end of the java.library.path.
In the Mac dot in automatically included in the java.library.path.
| os.name |
|---|
| AIX (Advanced Interactive eXecutive.) |
| Digital Unix |
| FreeBSD |
| HP (Hewlett Packard) UX |
| Irix |
| Linux |
| Mac OS (Operating System) |
| Mac OS X |
| MPE/iX |
| Netware 4.11 |
| OS/2 |
| Solaris |
| Windows 2000 |
| Windows 7 |
| Windows 95 |
| Windows 98 |
| Windows NT |
| Windows Vista |
| Windows XP |
Look at any *.properties files file to see an example. It will look something like this example:
In Java version 1.5 or later, there is an alternate XML (extensible Markup Language) format that lets you use encodings to handle awkward characters.The key thing to understand is that, in RAM, Properties are just glorified Hashtables. The documentation, at first reading, makes them sound as if they are much more complicated than they really are. Unlike ordinary Hashtables, they can be backed up to flat files that look like a bit like *.INI files. These files are loaded as a whole into RAM Hashtables for searching. The files are never linearly searched on disk to look up keys. Searching is always done with the RAM-resident Hashtable. You could access a property in a sample.properties file like this:
Since Properties are Hashtables, they scramble the order of the elements. If you want to preserve order, and don’t need key lookup, you can parse the file yourself with a StreamTokenizer and put it in an array. See how com.mindprod.business.Misc.loadProprerties code used by Learn To Count loads its ordered list of languages and classes from a properties file. Learn to Count keeps its properties file in the jar file. It accesses the file with:
then later uses a StreamTokenizer to process it.To create a new Properties file from scratch programmatically, remember that java.util.Properties is a subclass of java.util.Hashtable. Just create a new Properties object, add the elements to it as if it were a Hashtable and finally save it with Properties.store() or the JDK 1.2-deprecated Properties.save() in old Javas.
Here is some typical code to access properties:
There is another set of properties you can access with java.security.Security. getProperty. Beware, unused properties will return null, not the default. Mainly they are used to configure proxies.
| Important Networking Properties | |
|---|---|
| Property | Notes |
| networkaddress.cache.ttl | time in seconds to cache a successful DNS (Domain Name Service) lookup. Oddly the default is -1 to default forever. So if the DNS changes, Java will not never notice until you shutdown and restart. |
| networkaddress.cache.negative.ttl | time in seconds to cache a unsuccessful DNS lookup. 0=never cache, -1=forever, 10=default. |
| http.proxyHost | http proxy |
| http.proxyPort | http proxy |
| ftp.proxyHost | ftp proxy |
| ftp.proxyPort | ftp proxy |
|
|
available on the web at: |
http://mindprod.com/jgloss/properties.html |
optional Replicator mirror
|
J:\mindprod\jgloss\properties.html | |
![]() |
Please email your
feedback for publication,
letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear
wording, broken/redirected link reports, suggestions to improve this page or comments to
Roedy Green :
| |
| Blog | Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[50.16.132.180] |
|
| Feedback | You are visitor number 271,977. | |