System.setProperty() - Setting Your Own Properties

This section provides a tutorial example on how to modify system properties provided by the JVM, and set your own properties into the system property map.

The system properties are actually stored in a map structure, which can also be used by your application program to store your own properties. For example, the following program stores two non-system properties at the beginning, and uses them later in the program:

 - Copyright (c) 2014,, All Rights Reserved.
public class PropertyTest {
   public static void main(String[] a) {
   public static void setProgramInfo() {
      // Modifying a system property
      // Adding my own properties
      System.setProperty("","Property Test");
   public static void printMessage() {
      String userName = System.getProperty("");
      String programName = System.getProperty("");
      String programVersion = System.getProperty("program.version");
      String ioTempDir = System.getProperty("");
      System.out.println("Hello "+userName+",");
      System.out.println("Welcome to \""+programName+", "
      System.out.println("Note that the Java I/O "
         +" temporary directory is located at "+ioTempDir+".");


Hello herong,

Welcome to "Property Test, 3.01".
Note that the Java I/O  temporary directory is located at c:\var\tmp.

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


 PDF Printing Version