Timothy E. Archer

System.out.println("Hello World!");

Browsing Posts in Programming

Have you ever had the requirement to compress or uncompress files or byte streams from within your java applications? This requirement seems to be a common need for me in all sorts of applications from B2B data feeds to my client applications. Within my client applications I allow users to attach files to records and I compress them to conserve space before storing them on the server. Once I compress the byte stream, I usually do one of two things. I will either store the byte stream representing the compressed file directly into a BLOB column in my database, or I will write it to a file in a common file system location.

Below I will present my simple ZipUtil java class which allows us to easily compress and uncompress files. My class consists of two convenience methods that take a byte array and call either the java.util.zip.Deflater or java.util.zip.Inflater objects to compress/decompress the byte array, and then it returns the new byte array. These java classes provide support for general purpose compression/decompression using the ZLIB compression library.

This class is not designed to create Zip files per se, but rather to just compress and uncompress byte streams. I will present the class to you below: continue reading…

While I was writing an EMR application, I quickly realized that my framework needed a class with static methods to help me perform measurement conversions. Namely I needed to convert pounds to kilograms and inches to centimeters.

I searched the web for a while and didn’t find a stock Jakarta Commons utility, so I decided I would build my own class named MeasurementUtil. In the future, when I come up with a new measurement conversion requirement it will be placed within this class in my framework package. You’ll probably look at my code and say, “well that’s extremely simple, why not just do calculation using the logic inline”. The answer is simple: I wanted a basic utility class that encapsulates all of my measurement conversion logic. In reality this could probably be turned into its own package with a suite of classes, but since I only started off with the requirement for two measurement conversions, we ended up with one class for now. This is in an effort to keep it simple. continue reading…

In the Swing based java applications I write, the requirement usually exists to allow the app to open up other files such as Word Documents, PDF’s, HTML pages, etc. Since I try not to limit myself to just the file types defined in requirements gathering, I looked for a more general solution that will allow my apps to open any file type. After all, if on my Windows or Linux desktops I can double click on a file name to open the appropriate program, then why can’t my java applications?

My first take at this was to just use the java runtime, and assume my code would only run on windows 2000 or greater. The code at that point to open a file looked like this:

String cmd = "cmd /c \"" + fileName + "\"";
log.debug("Opening file with command: "+cmd);
java.lang.Runtime.getRuntime().exec(cmd);

Well, after that was in place for a few months, we wanted allow our application to also run on Linux. Uh oh, now the code above no longer works… continue reading…

One useful tool for web applications is a simple calendar control that you can call from your date input form fields. Having the ability to popup a calendar and select the date makes it easier for users who have to enter dates for future appointments, tasks, and reminders. By doing this the user doesn’t have to look at a separate calendar outside of your web application. Years ago I spent hours writing my own calendar control to do this, and quite frankly, I lost the code and didn’t want to have to rewrite it for my most recent project. So off to Google I went to begin my search. Within a few minutes I had found a control that does exactly what I want from Matt Kruse’s Javascript Toolbox.

Matt Kruse’s examples are very easy to follow, and I think his JavaScript tools are top notch material. I intend to integrate his JavaScript table sorting code into my application next. Below I will detail the steps I performed to get the calendar control working: continue reading…

One of the things I incorporate into all of my Java Swing applications is the JGoodies Look and Feel. I feel that it gives my Swing apps a much cleaner interface, especially when run under MS Windows. The applications will feel a little bit more like a standard Windows Application to the end user.

Furthermore, incorporating the JGoodies Look and Feel is EXTREMELY easy. I feel that may be it’s best feature! You can literally download the JGoodies Looks package and integrate it into your application in less that 15 minutes. I will explain how below. continue reading…

Most developers quickly realize that being notified of errors within their applications as soon as they happen is a great way to proactively fix problems. This approach has a few benefits. First, the developer does not have to spend time each day scouring logs looking for errors, and then trying to recreate the state of the system at that time to determine what happened. Secondly, the admin can actually call the end user almost immediately after being notified of the error, making them seem omniscient. Imagine being able to call your users as they are encountering the error. They will literally think you are superhuman and be amazed that you knew they needed help.

So how do we do this? Fortunately, if you are developing your application in the java programming language, most of the hard stuff is already done if you use the Apache Log4j logging framework. continue reading…

Powered by WordPress Web Design by SRS Solutions © 2012 Timothy E. Archer Design by SRS Solutions