Get Property by Name

In this Tutorial we want to describe you a code that helps you in understanding to get Property by Name. For this we have a class name "Get Property By Name".

Get Property by Name


In this Tutorial we want to describe you a code that helps you in understanding to get Property by Name. For this we have a class name "Get Property By Name". Inside the main method  we have the list of method that help you to get the Properties of  System-

1)System.getProperties ( ) -  This Method returns you current system properties by assigning an instance of properties class and store the current system properties in it.

2)stringPropertyNames( ) -   This Method returns you the current system properties in a Set object  set (Collection interface).

3)Iterator ( )   -   This allow you to traverse the list of element in a collection.

We declare a String variable name key inside the main method followed by while loop, that  is used to evaluate or check more element present in a iterator .If more element is present, the iterator call next( ).to string returns you the next element in the iterator, convert it into a string and store in a String variable key. The System.out.println is used to print the properties of the system by calling properties.getProperty( key).

import java.util.*;

public class GetPropertyByName {

  public static void main(String args[]) {

  Properties properties = System.getProperties();
  Set set = properties.stringPropertyNames();
  Iterator iterator = set.iterator();

  String key;
  while (iterator.hasNext()) {
  key =;

  System.out.print(key + " : ");

Output : Java(TM) SE Runtime Environment
sun.boot.library.path : C:\Program Files\Java\jdk1.6.0_01\jre\bin
java.vm.version : 1.6.0_01-b06
java.vm.vendor : Sun Microsystems Inc.
java.vendor.url :
path.separator : ; : Java HotSpot(TM) Client VM
file.encoding.pkg : : SUN_STANDARD : US
sun.os.patch.level : Service Pack 4 : Java Virtual Machine Specification
user.dir : C:\Documents and Settings\Administrator\
My Documents\NetBeansProjects\GetExample
java.runtime.version : 1.6.0_01-b06
java.awt.graphicsenv : sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs : C:\Program Files\Java\jdk1.6.0_01\jre\lib\endorsed
os.arch : x86 : C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
line.separator :  
java.vm.specification.vendor : Sun Microsystems Inc.
user.variant : : Windows 2000
sun.jnu.encoding : Cp1252
java.library.path : C:\ProgramFiles\Java\jdk1.6.0_01\jre\bin;
C:\WINNT;.;C:\Program Files\Java\jdk1.6.0_01\bin;
C:\Program Files\Apache Software
Foundation\Tomcat 6.0\bin;
C:\Program Files\apache-ant-1.7.1\bin;
C:\baadshah\GNUstep\GNUstep\System\Tools : Java Platform API Specification
java.class.version : 50.0 : HotSpot Client Compiler
os.version : 5.0
user.home : C:\Documents and Settings\Administrator
user.timezone :  
java.awt.printerjob :
file.encoding : Cp1252
java.specification.version : 1.6 :

C:\Documents and Settings\Administrator\
My Documents\NetBeansProjects\

java.class.path : Administrator
java.vm.specification.version : 1.0 : C:\Program Files\Java\jdk1.6.0_01\jre
java.home : 32
java.specification.vendor : en
user.language : Sun Microsystems Inc.
awt.toolkit : : mixed mode, sharing
java.version : 1.6.0_01
java.ext.dir :

C:\Program Files\Java\jdk1.6.0_01\jre\lib\ext;

sun.boot.class.path :

C:\Program Files\Java\

C:\Program Files\Java\

C:\Program Files\Java\

C:\Program Files\Java\

C:\Program Files\Java\

C:\Program Files\Java\

C:\Program Files\Java\

java.vendor : Sun Microsystems Inc.
file.separator : \
java.vendor.url.bug :
sun.cpu.endian : UnicodeLittle : little
sun.desktop : windows
sun.cpu.isalist :  

Download code

Share on Google+Share on Google+

Get Property by Name

Posted on: November 5, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Get Property by Name  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image