Question: The Java API Calendar class contains a method called getTimeInMillisec, which enables you to retrieve the absolute time (in milliseconds) at which any Calendar object
The Java API Calendar class contains a method called getTimeInMillisec, which enables you to retrieve the absolute time (in milliseconds) at which any Calendar object was created. You can use this capability to measure the runtime of any chunk of code. All you have to do is create a Calendar object before the test code starts, create another Calendar object right after the code ends, and print out the difference in those two objects’ times. You can create a Calendar object by calling the Calendar class’s static method, getInstance. For this exercise, you need to implement a class named MeasureRuntime that measures the runtime for the following statement (which displays a Charles de Gaulle quote):

System.out.println( "Patriotism is when love of your own people comes first;" + " nationalism, when hate for people other than your own" + comes first."); 11 Sample session: Patriotism is when love of your own people comes first; nationalism, when hate for people other than your own comes first. Time consumed = 31 milliseconds
Step by Step Solution
3.31 Rating (157 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
