Java

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.

How to query the memory usage stats from the JVM

People using Hibernate and Sun's JVM usually face the java.lang.OutOfMemoryError: PermGen space message sooner or later (mostly sooner Smiling ). To track down the source of an OutOfMemoryError problem you've to be able to query the amount of total and free memory within each available memory pool (heap and non-heap pools as well). Here's a short code snippet to demonstrate how to do that ...

The "optimal" String concatenation

I've now read quite a few forum topics on the subject and most people seem to argue for one or the other method (the "+" operator, StringBuffer, StringBuilder or whatever). Only a very few posts reflected my opinion: you use the method that makes your code the most robust and easiest to maintain. Then you create a dataset that resembles real-life application and run some tests. If the code runs outside the expected time limits, then you drive it through a profiler, find what makes it crawl and fix it. There's not much purpose in writing the "ultimate" code (ie. spending a lot of time on overall optimization) if only 10% will be used in 90% of the time. And don't take me wrong: there're good coding practises that you should learn and follow. But as with everything else: they are worth only as much as they help you get home earlier. Smiling The point of all coding is to create software that fits the requirements of the customer/user/etc. If you write code that is superior to that in any way, then it's either just a waste of time or it's only good for its "inner beauty". Smiling Of course the latter can be satisfying too for a developer from time to time ... Eye-wink
I pretty much like what Jeff Atwood had to say on the topic in his blog. And I'm most grateful that somebody else took the time to prove me right. Smiling

Syndicate content