Java - Property (Properties)

Java Conceptuel Diagram

Java - Property (Properties)

About

Key Value - Properties (Property file) in Java.

Properties are values managed as key/value pairs of string datatype. The key identifies, and is used to retrieve, the value.

The implementation of the property class (java.util.Properties) extends java.util.Hashtable

Type

System

The Java platform itself uses a Properties object to maintain its own configuration.

See the property method of the system class.

Access to system properties can be restricted by the Security Manager.

To set a system property when starting the jvm

java -D<name>=<value>

Application

Properties extends java.util.Hashtable. Some of the methods inherited from Hashtable support the following actions:

  • testing to see if a particular key or value is in the Properties object,
  • getting the current number of key/value pairs,
  • removing a key and its value,
  • adding a key/value pair to the Properties list,
  • enumerating over the values or the keys,
  • retrieving a value by its key, and
  • finding out if the Properties object is empty.

Java Property

Management

Load Property Files

// create and load default properties
Properties defaultProps = new Properties();
FileInputStream in = new FileInputStream("defaultProperties");
defaultProps.load(in);
in.close();

// create application properties with default
Properties applicationProps = new Properties(defaultProps);

// now load properties 
// from last invocation
in = new FileInputStream("appProperties");
applicationProps.load(in);
in.close();

Get

applicationProps.getProperty(String key, String default)

Loop

for (String key: properties.stringPropertyNames()){
     System.out.println ("The key ("+key+") has the value ("+properties.getProperty(key)+")";
}

Documentation / Reference





Discover More
Card Puncher Data Processing
JMeter - Property

How to define a property in JMeter. Properties are global to a JMeter instance. This uses the value of the property “loops”, defaulting to 10 if the property is not found. The “loops”...
Java Conceptuel Diagram
Java - JavaBean (Bean)

A JavaBean is java class conforming to the below convention. A bean is an Java Object that: is serializable, has a nullary constructor, has public properties, allows access to this properties...
Java Conceptuel Diagram
Java - System Property

The Java platform uses a Properties object to maintain its own configuration. Access to system properties can be restricted by the Security...
Weblogic Scripting Tool Windows Menu
WLST - Getting Started (Hello World)

The execution of a Wlst Script can happen in the following three modes: interactive: on the command line scripting: in batch scripts that are supplied in a file (Script Mode, where scripts invoke...



Share this page:
Follow us:
Task Runner