Systems Java Help


The System class holds a collection of static methods and variables. The standard input, output, and error output of the Java run time are stored in the in, out, and err variables. The methods defined by System are shown .Notice that many of the methods throw’a Unexceptionably if the operation is’not permitted by the security manager. One other point: Java 2 deprecated the method run Finalize On Exit( ). This method was added by Java 1.1, but was determined to be unstable. ‘ Let’s look at some common uses of System.

Using current Time Millis( ) to Time Program Execution

One use of the System class that you might find particularly interesting is to use the current Time Mill is( ) method to time how long various parts of your program take to execute. The current Time Mill is() method returns the current time in terms of milliseconds since midnight, January I, 1970. To time a section of your program, store this value just before beginning the section in question. Immediately upon completion, call current Time Mill is( ) again. The elapsed time will be the ending time minus the starting time. The following program demonstrates this

Here is a sample run (remember that your results probably will differ):

Timing a for loop from 0 to 1,000,000

Elapsed time: 10

Using array copy( )

The array copy( ) method can be used to copy quickly an array of any type from one place to another. This is much faster than the equivalent loop written out longhand in Java. Here is an example of two arrays being copied by the array copy ) method. First, a is copied to b. Next, all of a’s elements are shifted fount by one. Then, b is shifted lip by one.

  • Feel free to send us an inquiry, we will reply back in hours.


Posted on September 17, 2014 in Exploring java.lang

Share the Story

About the Author

Back to Top