Java

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. Smile 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. Smile 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 Smile ). 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. Smile 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". Smile Of course the latter can be satisfying too for a developer from time to time ... 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. Smile

Strange behaviour in Java compilers' string concatenation (caused by compile-time constants)

I'm sure thousands have stumbled on this before me, but still, it's weird and I cannot explain why it works as it works. Shock At first glance it appeared that if you define a variable in a public class as public static final (ie. a constant) and the variable has a primitive type, then other classes referencing this variable will somehow "cache" the variable value in their own .class file. Looking deeper into the problem I've discovered that the situation is not as bad as I feared: I just crossed javac compiler's string concatenation optimization and it seems it does a bit "too much" for my taste.
Update: Jeff provided a reference to sections of the Java Language Specification that explain why and how this is working. The relevant term is: compile-time constants.

Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, etc)

"This is a tale of two approaches to regular expression matching. One of them is in widespread use in the standard interpreters for many languages, including Perl. The other is used only in a few places, notably most implementations of awk and grep. The two approaches have wildly different performance characteristics ..."
A very interesting article on regular expression matching algorithms.

WebScarab - another debugging proxy in Java

WebScarab is a framework for analysing applications that communicate using the HTTP and HTTPS protocols. It is written in Java, and is thus portable to many platforms. WebScarab has several modes of operation, implemented by a number of plugins. In its most common usage, WebScarab operates as an intercepting proxy, allowing the operator to review and modify requests created by the browser before they are sent to the server, and to review and modify responses returned from the server before they are received by the browser. WebScarab is able to intercept both HTTP and HTTPS communication. The operator can also review the conversations (requests and responses) that have passed through WebScarab.

Paros Proxy - a Fiddler-like debugging proxy in Java

I have been looking for a cross-platform replacement for Fiddler for some time now. Today I stumbled upon Paros, which was written in Java and therefore should run on most Java-capable platforms without modification. Paros is not on par with Fiddler's feature set (and its development has been stalled for the last two years), but it's good enough for capturing/monitoring HTTP traffic on both Linux and Mac OS X.

Syndicate content