The Integer.getInteger()
methods allows us to easily read system property and convert it directly to Integer
object. This method call the System.getProperty()
method and then convert it to integer by calling the Integer.decode()
method.
package org.kodejava.lang;
public class IntegerProperty {
public static void main(String[] args) {
// Add properties to the system. In this example we create a
// dummy major and minor version for our application.
System.setProperty("app.major.version", "2021");
System.setProperty("app.minor.version", "9");
// In the code below we use the Integer.getInteger() method to
// read our application version from the value specified in the
// system properties.
Integer major = Integer.getInteger("app.major.version");
Integer minor = Integer.getInteger("app.minor.version");
System.out.println("App version = " + major + "." + minor);
}
}
The output of the code snippet:
App version = 2021.9
Latest posts by Wayan (see all)
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023