Trying to measure elapsed time in Java
<p>I was unable to get the Java clock to measure the time elapsed in milliseconds from the beginning to the end of a simple program.</p>

<p>I've copied the program below.  You will see that I used the utility Calendar, then printed the time before and after the loop.  No matter how long the loop takes, the time shown by the print command before and after the loop does not change.</p>

<p>Can you suggest a solution?</p>

<p>I use DrJava.</p>

<pre><code>import java.util.Calendar;

class time
{
  public static void main(String[] args)
  {

    int sum=0;
    int i=0;
    int j=0;
    int n=300;

    Calendar cal = Calendar.getInstance();

    System.out.println("Current milliseconds since 13 Oct, 2008 are :" + cal.getTimeInMillis());

    for (i=0;i &lt; n; i++)
    {
      sum++;
      System.out.println("ROW " + i);  
    }

    System.out.println(" Current milliseconds since 13 Oct, 2008 are :" + cal.getTimeInMillis());
  } 
}
</code></pre>
