Java

Thread Weaver

"Thread Weaver is a framework for writing multi-threaded unit tests in Java. It provides mechanisms for creating breakpoints within your code, and for halting execution of a thread when a breakpoint is reached. Other threads can then run while the first thread is blocked. This allows you to write repeatable tests for that can check for race conditions and thread safety."

tcpmon: an open-source utility to monitor a TCP connection

"tcpmon is an open-source utility for monitoring the data flowing on a TCP connection. tcpmon is used by placing it in-between a client and a server. The client is made to connect to tcpmon, and tcpmon forwards the data to server along-with displaying it in its GUI."

Theoretically the above link takes you to the most recent version of tcpmon. However the project started as an Apache tool. At tcpmon.dev.java.net you can get v1.1 and at ws.apache.org v1.0. But the two are not identical featurewise! The new version lacks the ability to switch between horizontal and vertical layout and more importantly it lacks the XML rendering mode. The latter displays XML content structured, ie. the various nodes are indented based on their level in the XML tree. Unfortunately the old version uses some fixed size font which gets pretty much unreadable at higher resolutions.

Building Ecplise from source

It took me a few minutes to find so it might be useful for others if I share. There are indeed pre-packaged source bundles for every Eclipse release available and theoretically you should be able to compile your own eclipse build fairly easily.

How to specify the class to use with JAXP (Java API for XML Processing)

The method of discovering a suitable XML Parser is pretty well described in the javadoc of the newInstance function of the javax.xml.parsers.DocumentBuilderFactory class.

How to query network interfaces and MAC addresses in Java

It's not a big deal, really. However the MAC address is only available since Java6 and to create a Java5 compatible class for working with network interfaces, you've to use the Java reflection API. My demo class might be of help to those who have not yet used reflection. See the attachment for the source of my ListNetworkInterfaces class which will print MAC and IP addresses of all available network interfaces. It'll print MAC addresses only if invoked in a JRE6 (or later). Compilation and invocation is as usually:
javac ListNetworkInterfaces.java
java ListNetworkInterfaces

How to convert an integer or a long value to a byte array (and vica versa) in Java

There're a lot of ways to do this right and a lot of ways to do it wrong. Smiling Here's one method that I've found to be both correct (ie. for all possible integer values the following is true: value == byteArrayToInt(intToByteArray(value))) and efficient.

How to find class duplications in Java webapps' libraries

While creating a Java web application you'll most probably use various libraries pre-packaged into JAR files. And of course you'll create several JARs for your own code as well. However some of these JARs might share the same classes and most of the time there's no guarantee on from which JAR a class is loaded. Your best bet is to make sure that each class (that you need) is present only in one JAR in you lib folder. To find classes that occur more than once in a webapp library folder, I've written a short shellscript.

Angelika Langer's Home Page (good FAQ on Java generics)

I've found Angelica's page (the "Under The Hood Of The Compiler" section in her Java Generics FAQ) by googling for possible workarounds/solutions for the various "unchecked" warnings we get in all sorts of Java code.

I'm very impressed. Smiling Both with the clarity and quaility of her website (there's quite some work in it), the FAQ she published on it and her career as well. She resembles quite a lot of what I'd like to achieve in my professional life.

Java exception handling, aka. the try-catch-finally workflow

I was not completely sure about the order that try-catch-finally blocks are executed in (eg. if an exception occurs in a catch block, then is the immediatly following finally block executed next or the catch block that catches the exception?), so I made a small test case that demostrates workflow (order of execution) of the various blocks.

Debugging Tomcat class loading issues

Tomcat's class loading can be tricky some times. If you search on class loading problems, you'll find myriads of posts on blogs, forums, etc. And it's not just because people don't know how it works (which is actually well documented), but because it sometimes doesn't work. Smiling There've been bugs in Tomcat's class loading and even if it's working as expected, it can give you a hard time to track down what's actually happening behind the scene.

Syndicate content