tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Core > Integer > Get Integer System Property

Get Integer System Property 

The following example shows how to access an integer value set using system property.

File Name  :  
com/bethecoder/tutorials/core/integer/GetInteger.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.core.integer;

public class GetInteger{

  public static void main (String [] args) {
    
    /**
     * Integer.getInteger method reads the given system property
     * and returns the result as integer.
     
     * If the queried system property is not found it returns default value
     */
    int DEFAULT_THREAD_COUNT = 6;
    int maxThreadCount = Integer.getInteger("MAX_THREAD_COUNT", DEFAULT_THREAD_COUNT);
    System.out.println("Max Thread count : " + maxThreadCount);
    
    //Set the system property either through application
    //startup parameters (-DMAX_THREAD_COUNT=20) or System.setProperty
    System.setProperty("MAX_THREAD_COUNT""20");
    
    maxThreadCount = Integer.getInteger("MAX_THREAD_COUNT", DEFAULT_THREAD_COUNT);
    System.out.println("Max Thread count : " + maxThreadCount);
    
  }
}
   

It gives the following output,
Max Thread count : 6
Max Thread count : 20



 
  


  
bl  br