Could you please tell me, what is the "System.
" in this code?
and why they used it?
when we should use "System.
"?
Where can I know I should use System.
for nanoTime()
?
// A class to measure time elapsed.
public class Stopwatch{
private long startTime;
private long stopTime;
public static final double NANOS_PER_SEC = 1000000000.0;
// start the stop watch.
public void start(){
startTime = System.nanoTime();
}
// stop the stop watch.
public void stop()
{ stopTime = System.nanoTime(); }
// elapsed time in seconds.
// @return the time recorded on the stopwatch in seconds
public double time()
{ return (stopTime - startTime) / NANOS_PER_SEC; }
public String toString(){
return "elapsed time: " + time() + " seconds.";
}
// elapsed time in nanoseconds.
// @return the time recorded on the stopwatch in nanoseconds
public long timeInNanoseconds()
{ return (stopTime - startTime); }
}