java.lang.Long getLong(String nm)


The Long.getLong(String nm) java method determines the long value of the system property with the specified name.

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 a long value using the grammar supported by decode and a Long object representing this value is returned.

If there is no property with the specified name, if the specified name is empty or null, or if the property does not have the correct numeric format, then null is returned.

In other words, this method returns a Long object equal to the value of:

getLong(nm, null)

Make a note that the getLong(String nm) method of Long class is static thus it should be accessed statically which means the we would be calling this method in this format:

Long.getLong(method args)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java compare method non statically.


  • This method throws SecurityException, for the same reasons as System.getProperty.

Method Syntax

public static Long getLong(String nm)

Method Argument

Data Type Parameter Description
String nm property name.

Method Returns

The getLong(String nm) method of Long class returns the Long value of the property.


Requires Java 1.0 and up

Java Long getLong(String nm) Example

Below is a simple java example on the usage of getLong(String nm) method of Long class.


import java.util.Properties;

 * This example source code demonstrates the use of 
 * getLong(String nm) method of Boolean class.

public class LongGetLongExample {

	public static void main(String[] args) {
		// call a method to set a property
		// check if the property is existing
		// and get the value
		Long testLong = Long.getLong("test.long");		
		// print the result
	 * This is a method to set a property
	 * to test out the getLong() method
	public static void setProperty(){
		// instantiate a new Properties
		// equal to system properties
		Properties prop = System.getProperties();
		// set a property with key as test.long
		// and value is "Test String"
		prop.setProperty("test.long", "123");


Sample Output

Below is the sample output when you run the above example.

Java Long getLong(String nm) example output