Showing posts with label Sytem properties. Show all posts
Showing posts with label Sytem properties. Show all posts

Wednesday, 10 September 2014

Retrive System properties Java

Accessing system properties can be an important part of the code/ J2EE application . Some of the system properties and their corresponding description are given below .

Java system propertyMeaning
file.encodingThe encoding used in text files on the system.
file.separatorThe file separator character. This is usually \ for windows and / for UNIX like systems
java.io.tmpdirThe directory in which temporary files can be created on the local system. System environment variable %TEMP%
line.separatorThe character or sequence of characters that generally mark a "new line" in a text file on the local operating system. On UNIX-like systems, this is typically a single ASCII character 10, whereas on Windows systems, this is typically a two-character sequence (ASCII 10 and ASCII 13).
os.nameThe name of the local operating system, such as "Linux" or "Windows 7".
os.versionA version number of the local operating system, such as "6.0" or "2.6.18-stab02".
path.separatorThe separator generally used to separate lists of paths on that operating system, for example a colon (":"). Note that this is not the directory separator used inside paths.
user.countryThe ISO code of the operating system's (or local user's) configured country.
user.dirThe local directory from which the Java process has been started, and from which files will be read/written by default unless a path is specified.
user.homeThe current user's "home" directory, such as C:\Users\Fred on Windows systems, or /home/sandesh/ on UNIX-like systems.
user.languageThe ISO code of the operating system's (or local user's) configured language, such as "en" for English.
user.nameThe local user's system user name. On Windows systems, this is typically close to a "real life" name. On UNIX-like systems, it is common for user names to be all lower case letters.

 import java.util.Map;  
 public class ReadSystemProperties {  
      public static void main(String[] args) {  
           Map envVars = System.getenv(); // Gives the environment variable values.  
           System.out.println(envVars);  
           String osVersion = System.getProperty("os.version"); // Retrives the version of os you are working on.  
           System.out.println("OS Version - \t" + osVersion);  
           String osName = System.getProperty("os.name"); // Retrives the os you are working on.  
           System.out.println("OS Version - \t" + osName);  
           String fileEncoding = System.getProperty("file.encoding"); // Retrives the os you are working on.  
           System.out.println("File Encoding - \t" + fileEncoding);  
           String fileSeparator = System.getProperty("file.separator"); // Retrives the os you are working on.  
           System.out.println("File Separator - \t" + fileSeparator);  
      }  
 }