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

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) 2014, 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) SE Runtime Environment
sun.boot.library.path=C:\Program Files\java\jdk1.8.0\jre\bin
java.vm.version=25.0-b70
java.vm.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.script=
user.country=US
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=Service Pack 1
java.vm.specification.name=Java Virtual Machine Specification
user.dir=C:\herong\java
java.runtime.version=1.8.0-b132
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\java\jdk1.8.0\jre\li...
os.arch=x86
java.io.tmpdir=C:\Users\herong\AppData\Local\Temp\
line.separator=
java.vm.specification.vendor=Oracle Corporation
user.variant=
os.name=Windows 7
sun.jnu.encoding=Cp1252
java.library.path=C:\Program Files\java\jdk1.8.0\bin;C:...
java.specification.name=Java Platform API Specification
java.class.version=52.0
sun.management.compiler=HotSpot Client Compiler
os.version=6.1
user.home=C:\Users\herong
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=Cp1252
java.specification.version=1.8
user.name=herong
java.class.path=.
java.vm.specification.version=1.8
sun.arch.data.model=32
java.home=C:\Program Files\java\jdk1.8.0\jre
sun.java.command=SysProperties
java.specification.vendor=Oracle Corporation
user.language=en
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.8.0
java.ext.dirs=C:\Program Files\java\jdk1.8.0\jre\li...
sun.boot.class.path=C:\Program Files\java\jdk1.8.0\jre\li...
sun.stderr.encoding=cp437
java.vendor=Oracle Corporation
file.separator=\
java.vendor.url.bug=http://bugreport.sun.com/bugreport/
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.stdout.encoding=cp437
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...

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: 2014.

Table of Contents

 About This Book

 Installing JDK 1.8 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

 Lambda Expressions and Method References

 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

JVM and OS System Properties - Updated in 2014, by Dr. Herong Yang