Date
Class
Calendar
and GregorianCalendar
Classes
Date
Class
Date
with no arguments, to represent
the current moment.
Date
Constructor (year, month, day, hour, etc.) to say "build me a Date that
represents this date/time." However, that use is now deprecated (officially
disapproved) and you should use the class GregorianCalendar
instead.
Date
class has been criticized for its poor design and
many of its features are now deprecated, the class itself is still used to
represent an instant in time.
Date
representing the current point with:
Date d = new Date();
getTime()
method.
Date d = new Date(); long m = d.getTime();
Calendar
and GregorianCalendar
ClassesCalendar
translates between an instant in time, and
individual fields like year, month, hour, etc.
Calendar
holds dates internally in two forms: the
"milliseconds since the epoch" (unfortunately held in a long int, rather than a
Date
object) form, and the "several ints individually representing
day, month, year, hour, etc." form.
Calendar
also knows about time zones.
TimeZone
.
DateFormat
class that provides elementary
date formatting.
java.util.GregorianCalendar
extends
Calendar
and provides more methods.
Calendar
is an abstract class, and the parent of
GregorianCalendar
, you should simply use GregorianCalendar
all the time.
GregorianCalendar g = new GregorianCalendar(61, 7, 13);
TimeZone z_ect = TimeZone.getTimeZone("ECT"); GregorianCalendar g = new GregorianCalendar(z_ect); g.set(61, 7, 13);
GregorianCalendar
defaults
to the time zone the where the program is running.
java.util.TimeZone.java.
int year = g.get(Calendar.YEAR); int month = g.get(Calendar.MONTH); int day = g.get(Calendar.DAY_OF_WEEK);
Date
and GregorianCalendar
to determine the running time.
java.lang.System
class.
import java.util.*; // user-defined exception class BadRange extends Exception {} public class time { public static void main(String args[]) { time T = new time(); long start, end; double totalseconds; // instantiate a GregorianCalendar object GregorianCalendar cal = new GregorianCalendar(); // instantiate a Date object Date date = new Date(); // refresh date cal = (GregorianCalendar)cal.getInstance(); // getTime() is a method of class Calendar (and therefore // GregorianCalendar). It returns a Date class with the // current time since the epoch date = cal.getTime(); // get current milliseconds from the Date object start = date.getTime(); /* place whatever code you want to time execution of in here... */ // refresh date cal = (GregorianCalendar)cal.getInstance(); date = cal.getTime(); //get current milliseconds from the Date object end = date.getTime(); // calculate the total seconds from milliseconds totalseconds = (double)(end - start) / (double)1000; return; } }
java.lang.System
class
called currentTimeMillis()
.
import java.util.*; class BadRange extends Exception {} public class time2 { public static void main(String args[]) { time2 T = new time2(); long start, end; double totalseconds; // get current milliseconds from java.lang.System start = System.currentTimeMillis(); /* place whatever code you want to time execution of in here... */ //get current milliseconds end = System.currentTimeMillis(); // calculate the total seconds from milliseconds totalseconds = (double)(end - start) / (double)1000; return; } }
jdb
for java
in the command line.
$ jdb myclass
$ jdb -classpath $INSTALL_DIR/classes myclass
-debug
option.
-debug
option, the Java interpreter
prints out a password for jdb's use.
$ jdb -host <hostname> -password <password>
$ jdb -host cunix.cc.columbia.edu -password 4tmc2b
-g
option.
$ man jdb
!!
This a shorthand command that is replaced with the text of the last command entered. It may be followed by additional text that is appended to that previous command.
catch [ exception class ]
Cause a breakpoint whenever the specified exception is thrown. If no exception
is specified, the command lists the exceptions currently being caught. Use
ignore
to stop these breakpoints from occurring (see below).
classes
List all classes that have been loaded.
clear [ class:line ]
Remove the breakpoints set at the specified line of the specified class. Typing
clear
or stop
with no arguments displays a list of
current breakpoints and the line numbers that they are set at (see below).
cont
Resume execution. This command should be used when the current thread is stopped at a breakpoint.
down [ n ]
Move down n frames in the call stack of the current thread. If n is not specified, move down one frame.
dump id(s)
Print the value of all fields of the specified object or objects. If you
specify the name of a class, dump
displays all class (static)
methods and variables of the class, and also displays the superclass and
list of implemented interfaces.
exit
(or quit
)
Quit jdb.
help
(or ?
)
Display a list of all jdb commands.
ignore exception class
Do not treat the specified exception as a breakpoint. This command turns off a
catch
command (see above).
load classname
Load the specified class into jdb.
locals
Display a list of local variables for the current stack frame. Java code must
be compiled with the -g
option in order to contain local variable
information.
print id(s)
Print the value of the specified item or items. Each item may be a class,
object, field, or local variable. The print
command displays an
object's value by invoking its toString()
method.
run [ class ] [ args ]
Run the main()
method of the specified class, passing the
specified arguments to it. If no class or arguments are specified, use the
class and arguments specified on the jdb command line.
step
Run the current line of the current thread and stop again.
stop [ at class:line ]
stop [ in class.method ]
Set a breakpoint at the specified line of the specified class or at the
beginning of the specified method of the specified class. Program execution
stops when it reaches this line or enters the method. If stop
is
executed with no arguments, then it lists the current breakpoints.
up [ n ]
Move up n frames in the call stack of the current thread. If n is not specified, move up one frame.
where [ thread ] [ all ]
Display a stack trace for the specified thread. If no thread is specified,
display a stack trace for the current thread. If all
is specified,
display a stack trace for all threads.
-g
option, instance and
local variables can be printed to determine the cause of the exception.
catch
command
(see above), for example:
catch FileNotFoundException catch mypackage.BigTroubleException
ignore
command (see above) removes exception classes from
this list.
ignore
command does not cause the Java interpreter
to ignore specific exceptions, only the debugger.