Home » Java programming language

Java System class nanoTime() method with example

System class nanoTime() method: Here, we are going to learn about the nanoTime() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 15, 2019

System class nanoTime() method

  • nanoTime() method is available in java.lang package.
  • nanoTime() method is used to return the value of the current system time in nanoseconds.
  • nanoTime() method is static, it is accessible with the class name too.
  • nanoTime() method does not throw any exception.

Syntax:

    public static long nanoTime ();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is long, it returns the current system time in nanoseconds.

Example:

// Java program to demonstrate the example of 
// nanoTime() method of System Class

public class NanoTime {
    public static void main(String[] args) {
        System.out.print("The current time is: ");
        System.out.println(System.nanoTime() + " ns");
    }
}

Output

E:\Programs>javac NanoTime.java
E:\Programs>java NanoTime
The current time is: 4254185681871084 ns





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.