Java Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 6.20

JVM and OS System Properties

This section provides a tutorial example on how to list all properties from the JVM and the OS that are accessible by your Java application.

Java application programs are executed inside a Java Virtual Machine (JVM), which is in turn executed inside an Operating System (OS). From the Java application program point of view, the JVM, together with the OS, represents the computer system. The properties of the JVM and the OS are all called system properties.

A Java application program can:

  • Use System.getProperty(String propertyName) to get the value of a specific system property.
  • Use System.getProperties() to get all available system properties.

Here is an example program that displays the values of all available system properties:

/**
 * SysProperties.java
 * Copyright (c) 2012, HerongYang.com, All Rights Reserved.
 */
import java.util.*;
public class SysProperties {
   public static void main(String[] a) {
      Properties sysProps = System.getProperties();
      sysProps.list(System.out);
   }
}

Output:

-- listing properties --
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=C:\j2sdk1.4.1_01\jre\bin
java.vm.version=1.4.1_01-b01
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.os.patch.level=Service Pack 2
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\herong\java
java.runtime.version=1.4.1_01-b01
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\j2sdk1.4.1_01\jre\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\HERONG\LOCALS~1\Temp\
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows 2000
sun.java2d.fontpath=
java.library.path=C:\j2sdk1.4.1_01\bin;.;C:\WINNT...
java.specification.name=Java Platform API Specification
java.class.version=48.0
java.util.prefs.PreferencesFactory
   =java.util.prefs.WindowsPreferencesFac...
os.version=5.0
user.home=C:\Documents and Settings\herong
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.4
user.name=herong
java.class.path=.
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\j2sdk1.4.1_01\jre
java.specification.vendor=Sun Microsystems Inc.
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.4.1_01
java.ext.dirs=C:\j2sdk1.4.1_01\jre\lib\ext
sun.boot.class.path=C:\j2sdk1.4.1_01\jre\lib\rt.jar...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=pentium i486 i386

Note that:

  • The value of property "line.separator" contains a new line character '\n', which produces a blank line on the output window.
  • The Properties.list() truncates values after 37 characters while sending them to the output stream.

Last update: 2012.

Table of Contents

 About This Book

 Installing JDK 1.7 on Windows

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 StringBuffer - The String Buffer Class

System Properties and Runtime Object Methods

JVM and OS System Properties

 System.setProperty() - Setting Your Own Properties

 Runtime.getRuntime() - Getting the Runtime Object

 freeMemory() - Getting JVM Free Memory Information

 Calculating Memory Usage of an Array

 exec() - Executing Operating System Commands

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Outdated Tutorials

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2012
JVM and OS System Properties