Java category archives

Java stack trace with line numbers

Often in Java program stack trace, you will see some stack frames include a source line number, while some only say “compiled code”. This is because the stack frames without line numbers have been compiled by the JIT compiler, and the JIT compiler obliterates line number information when it compiles code.

Spy on a Java program

While a Java program is running in a console window, you can can get a stack dump of the program at any time, while it is running. This is very useful for debugging, especially for heavily multithreaded programs.

Java versus Daylight savings time

Depending on the version of the Java runtime and the location of the host, the Java Date and Calendar routines may take daylight savings time into account. For example:

java.sql.Date is not a real date

java.sql.Date stores only date information, not times. Simply converting a java.util.Date into a java.sql.Date will silently set the time to midnight. So, to store date/times to be manipulated as java.util.Date objects, don’t do this:

// BUG: loses time of day
preparedStatement.setDate(1, new java.sql.Date(date.getTime()));

do this instead:

preparedStatement.setTimestamp(1, new java.sql.Timestamp(date.getTime()));

java.sql.Timestamp extends java.util.Date, but it should not be used as a [...]

Close
E-mail It