Explain how to measure time in nanoseconds - Java

Explain how to measure time in nanoseconds.

Time is measured in nanoseconds by using the method nanoTime() method. This method returns the current value of the most precise system timer available in nanoseconds. It is used for measuring elapsed time.

For example, to measure how long some code takes to execute
long startTime = System.nanoTime();

long estimatedTime = System.nanoTime() - startTime;
The above code snippet returns the current value of the time in nanoseconds.

The value returned by System.nanoTime() is platform dependent.
Java Thread: run() vs start() method
The method start() invokes the run() method. If the run() method of two threads invoked separately, they will execute one after the other...
What is Java Isolates and why do we need it?
Java Isolates is an API. It provides a mechanism to manage Java application life cycles which are isolated from each other. They can potentially share the underlying implementation resources...
What are the system properties that applets are allowed to read by default?
The following are the system properties that Java applets read by default with System.getProperty() method:...
Post your comment