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.