Welcome to TheGillis.net

Consider this site a collection of random notes about a variety of topics. I hope this information helps you in some way.

21 August 2004 - 15:23Java Application Logging With Log4J

One problem that I have always faced with creating robust Java Applications has been logging the state of the program. In some cases it’s important to know about debug information, while other times it can get in the way. Even solutions that initially appear simple, can turn out to cause problems. One example is using System.out.println statements. This can cause problems when the application is no longer attached to a console such as in a Servlet. Other times having a console open with a Swing application can be difficult. Then to remove the output, it is necessary to comment out all of the print lines in a final release, taking even more time. One very good solution I’ve run across is using the Jakarta Log4J project.

No Comments | Tags: Programming

18 August 2004 - 5:58Java and Assert

I am a big fan of assertions in C++, and I always thought it would be great if Java had such a feature. I have known about the JUnit assertTrue() and assertFalse() statements, but they don’t act the same as the C++ equivalents. Exceptions are a decent option, but they have the drawback that non-RuntimeExceptions must be explicitly caught. Not only that but the logic to check simple things like pre and post conditions can be intrusive with if statements that usually take up at least three lines. Fortunately I have learned of a new feature to Java 1.4; the assert keyword. This shows where to learn the syntax as well as how to use them with javac, Apache Ant, and Eclipse.

No Comments | Tags: General