Blog / Java

How to print the values of all the fields of an object in Java

August 17, 2011

I was just doing some Java coding and I needed to check the values of a bunch of fields of an object (mostly numbers). Normally I’d just call and print each get() method if I just need to check a few fields, but the class I’m dealing with has over 30 fields and I need to check them all and there’s no way I’m doing over 30 print statements for each get() method!

A quick …

GWT, Django, and JSON (with padding)

August 8, 2011

A couple of months ago I was working on a project where I needed to retrieve data in JSON format from a web service written in Python (using the Django web framework) under GWT. The data is then loaded into GXT/Ext GWT grids and charts.

After looking at a GXT example of loading JSON data to a grid, I thought this would be pretty straightforward, but of course I was wrong. Since the Django …

How to convert a Java keystore (JKS) to PEM format

May 8, 2011

I’m currently working on a new project where I need to write a service to serve static files to users. Our web application currently runs on Tomcat alone as we don’t have many users (internal users only) and most of the content is dynamic. But with this new project it just seems to make sense to put an Apache web server in front of Tomcat and use the mod_xsendfile module to serve the files, which …

How to log to multiple log files with log4j

March 6, 2011

Back to Java coding!

We have a Java application that calls an external application and since it gets called quite often we figured we should probably log its standard output and standard error streams to a separate log file so we could easily locate issues with it later. This would also allow us to create a different message format for it and different handlers.

Luckily, it turned out that this is pretty easy to do …