Getting and Adding System Properties

This section provides a tutorial example on how to access system properties provided by the JVM instance and how to add your own properties.

The java.lang.System class also allows you to manage a collection of properties stored at the JVM instance level. Whey your application is started, JVM will add many built-in properties into the collection. While your application is running, you can add, retrieve, and remove any properties.

You can also reset or add any properties when invoking the JVM using the -D command line option.

Here is tutorial example program showing you how to manage system properties:

 * Copyright (c) 2010,, All Rights Reserved.
class SystemJvmProperty {
   public static void main(String[] a) { out = System.out;

      // adding my own entries to JVM properties

      // copying all JVM properties into a Properties object
      java.util.Properties props = System.getProperties();
      java.util.Enumeration e = props.propertyNames();
      out.println("JVM Properties:");
      while (e.hasMoreElements()) {
         String k = (String) e.nextElement();
         String v = props.getProperty(k);
         out.println("   "+k+" = "+v);

When executed on my Windows 7 system with JDK 1.7.0, I got this result:

C:\herong\jvm>java SystemJvmProperty
JVM Properties: = Java(TM) SE Runtime Environment
   sun.boot.library.path = C:\Program Files\java\jdk1.7.0_45\jre\bin
   java.vm.version = 24.45-b08 = HP
   java.vm.vendor = Oracle Corporation
   java.vendor.url =
   path.separator = ; = Java HotSpot(TM) Client VM
   file.encoding.pkg =
   user.script = = US = SUN_STANDARD
   sun.os.patch.level = Service Pack 1 = Java Virtual Machine Specification = Black
   java.runtime.version = 1.7.0_45-b18
   java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
   os.arch = x86 = C:\Users\herong\AppData\Local\Temp\
   line.separator = 

   java.vm.specification.vendor = Oracle Corporation
   user.variant = = Windows 7
   sun.jnu.encoding = Cp1252
   java.library.path = C:\Program Files\java\jdk1.7.0_45\bin;... = Java Platform API Specification
   java.class.version = 51.0 = Windows = HotSpot Client Compiler
   os.version = 6.1
   user.home = C:\Users\herong
   user.timezone = 
   java.awt.printerjob =
   java.specification.version = 1.7
   file.encoding = Cp1252 = herong
   java.class.path = .
   java.vm.specification.version = 1.7 = 32
   java.home = C:\Program Files\java\jdk1.7.0_45\jre = SystemJvmProperty
   java.specification.vendor = Oracle Corporation
   user.language = en
   awt.toolkit = = mixed mode, sharing
   java.version = 1.7.0_45
   java.ext.dirs = C:\Program Files\java\jdk1.7.0_45\jre\lib\ext;...
   java.vendor = Oracle Corporation
   file.separator = \
   java.vendor.url.bug =
   sun.cpu.endian = little = UnicodeLittle
   sun.desktop = windows

The test result tells me that:

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

java.lang.System Class - The Operating System

 What Is java.lang.System?

 Standard Input, Output, and Error Streams

 Current Time in Milliseconds and Nanoseconds

 Accessing System Environment Variables

Getting and Adding System Properties

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 Outdated Tutorials


 PDF Printing Version