System.nanoTimer()

I upgraded to JDK 1.5 and I used theSystem.nanoTimer() method to determine the running time of my algorithm sinceSystem.currentTimeMillis() methos was giving odd results.

However when I complie the code it says "cannot find symbol - method nanoTimer()".

Does anyone have any reasons why? Maybe my coding is incorrect?

Here is my coding:

publicclass StopWatch

{

/**

Constructs a stopwatch that is in the stopped state

and has no time accumulated.

*/

public StopWatch()

{

reset();

}

/**

Starts the stopwatch. Time starts accumulating now.

*/

publicvoid start()

{

if (isRunning)return;

isRunning =true;

startTime = System.nanoTimer();

}

/**

Stops the stopwatch. Time stops accumulating and is

is added to the elapsed time.

*/

publicvoid stop()

{

if (!isRunning)return;

isRunning =false;

long endTime = System.nanoTimer() ;

elapsedTime = elapsedTime + endTime - startTime;

}

/**

Returns the total elapsed time.

:@return the total elapsed time

*/

publiclong getElapsedTime()

{

if (isRunning)

{

long endTime = System.nanoTimer();

return elapsedTime + endTime - startTime;

}

else

return elapsedTime;

}

/**

Stops the watch and resets the elapsed time to 0.

*/

publicvoid reset()

{

elapsedTime = 0;

isRunning =false;

}

privatelong elapsedTime;

privatelong startTime;

privateboolean isRunning;

}

[3205 byte] By [Princea] at [2007-10-2 6:02:48]
# 1
Hi ,It is System.nanoTime()notnanoTimer()
rajkumar_srinivasana at 2007-7-16 13:03:13 > top of Java-index,Other Topics,Algorithms...
# 2
oops!Thank you Sir!
Princea at 2007-7-16 13:03:13 > top of Java-index,Other Topics,Algorithms...
# 3
This type of question belongs in "New to Java" forum or "Java Technology" forum.
rkippena at 2007-7-16 13:03:13 > top of Java-index,Other Topics,Algorithms...