Java - Print system properties

by
Jeremy Canfield |
Updated: August 25 2022
| Java articles
The following class will print all of the system properties.
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Properties properties = System.getProperties();
System.out.println(properties);
}
}
Or, you can return a specific system property.
import java.util.Properties;
public class Main {
public static void main(String[] args) {
String properties = System.getProperty("java.runtime.name");
System.out.println(properties);
}
}
Or you can loop through each property, printing the key value pair.
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Properties properties = System.getProperties();
for (Map.Entry<Object, Object> set : properties.entrySet()) {
System.out.println( set.getKey() + " = " + set.getValue() );
}
}
}
Did you find this article helpful?
If so, consider buying me a coffee over at