Java Integer getInteger() MethodThere are three different types of Java getInteger() methods which can be differentiated depending on its parameter. These are:
1. Java Integer getInteger(String nm) Method:The getInteger(String nm) method is a method of Integer class under java.lang package. This method determines the integer value of the system property with the specified name of method argument. If there is no property with the specified name of method argument, if the specified name is empty or null or if the property does not have the correct numeric format, it will returned null. Syntax:Following is the declaration of getInteger(String nm) method: Parameter:
Returns:The getInteger(String nm) method will returns the value of the property specified as method argument as an Integer object. Exceptions:NA Compatibility Version:Java 1.2 and above Example 1Output: sun.arch.data.model is the Java System property which determines the version of the JVM is used - 32 or 64bit. Value = 64 Value = null Example 2Output: Default property: 64 Custom Property: 100 Example 3Output: Enter the desired input string: sun.arch.data.model Default Value = 64 Custom Value = null 2. Java Integer getInteger(String nm, int val) Method:The getInteger(String nm, int val) method is a method of Integer class under java.lang package. This method determines the integer value of the system property with the specified name of method argument. The first argument is treated as the name of a system property. The string value of this property is then interpreted as an integer value and an Integer object representing this value is returned. The second argument is the default value. An Integer object that represents the value of the second argument is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null. Syntax:Following is the declaration of getInteger(String nm, int val) method: Parameter:
Returns:The getInteger(String nm, int val) method returns the value of the system property name specified as method argument as an Integer object and if not found, the default value will be returned as specified by the user. Exceptions:NA Compatibility Version:Java 1.2 and above Example 1Output: 102 999 Example 2Output: System Property: 123 Default property: 64 Custom Property:100 Custom Property: 124 Example 3Output: Enter the desired system property: sun.arch.data.model Default Value: 64 Custem Value: 25 3. Java Integer getInteger(String nm, Integer val) Method:The getInteger( String nm, Integer val ) method is a method of Integer class under java.lang package. This method determines the integer value of the system property with the specified name of method argument. The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value and an Integer object representing this value is returned.
The second argument is the default value. This value is returned if there is no property of the specified name, if the property does not have the correct numeric format, or if the specified name is empty or null. Syntax:Following is the declaration of getInteger(String nm, Integer val) method: Parameter:
Returns:The getInteger(String nm, Integer val) method returns the value of the system property name specified as method argument as an Integer object and if not found, the default value will be returned as specified by the user. Exceptions:NA Compatibility Version:Java 1.2 and above Example 1Output: 133 Default property:64 Custom Property: 100 Custom Property: 105 Example 2Output: Enter the desired System Property name: sun.arch.data.model System Property Value: 64 Custom Value: 25 Example 3Output: 102 950 Next TopicPackage-class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India