Basics of System class
According to the specifications of Java Programming Language, the facilities provided by this class are :
a) Standard input, output and error streams
b) Access to the defined "properties"
c) means of loading files and libraries and
d) utility method for quickly copying a portion of an array.
The most common use we do in our programs is to put debug statements on console, using:
System.out.println(....).
Being the static class, the call to an object/method can be made as System.methodName or System.objectName and not by making the object of this class. In System.out.println: "out" is an object of PrintStream and println is the method of that class. One of the important feature to note here is that the "out" and "err" objects are of PrintStream which is the sub-class of OutputStream. But the "in" is the object of the InputStream. The advantages of PrintStream object will be done sometime later.
The next important feature but least commonly used is to determine the System properties. There is a native method called initProperties(). This method guarantees that the following properties are defined always:
| Key | Description of Associated Value | ||
|---|---|---|---|
java.version | Java Runtime Environment version | ||
java.vendor | Java Runtime Environment vendor | ||
java.vendor.url | Java vendor URL | ||
java.home | Java installation directory | ||
java.vm.specification.version | Java Virtual Machine specification version | ||
java.vm.specification.vendor | Java Virtual Machine specification vendor | ||
java.vm.specification.name | Java Virtual Machine specification name | ||
java.vm.version | Java Virtual Machine implementation version | ||
java.vm.vendor | Java Virtual Machine implementation vendor | ||
java.vm.name | Java Virtual Machine implementation name | ||
java.specification.version | Java Runtime Environment specification version | ||
java.specification.vendor | Java Runtime Environment specification vendor | ||
java.specification.name | Java Runtime Environment specification name | ||
java.class.version | Java class format version number | ||
java.class.path | Java class path | ||
java.library.path | List of paths to search when loading libraries | ||
java.io.tmpdir | Default temp file path | ||
java.compiler | Name of JIT compiler to use | ||
java.ext.dirs | Path of extension directory or directories | ||
os.name | Operating system name | ||
os.arch | Operating system architecture | ||
os.version | Operating system version | ||
file.separator | File separator ("/" on UNIX) | ||
path.separator | Path separator (":" on UNIX) | ||
line.separator | Line separator ("\n" on UNIX) | ||
user.name | User's account name | ||
user.home | User's home directory | ||
user.dir | User's current working directory |
Multiple paths in a system property value are separated by the path separator character of the platform.
So, System.getProperty("line.separator") will return the line separator based on which OS ..etc etc.
This class is also used to load the files and libraries, using methods load(fileNameWithFullPathAsString) and loadLibrary(libNameAsString). The standard strategy is to call like:
static { System.loadLibrary("LibFile");
This gets loaded as the class is intialized. These methods can be also called as:
Runtime.getRuntime().loadLibrary(name)
Finally, there is a utility method to copy an array beginnin from the specified array
position to a specified position. The signature of the methods is as:
public static void arraycopy(Object src, int srcPos, Object dest,
int destPos, int length)
The src and dest object here can be same.
Finally, the method exit(int i): a nonzero status code indicates abnormal termination.
0 Comments:
Post a Comment
<< Home