Archive for category java
Weak References in Java
Ever heard of Weak References in Java? Well, me neither. But it really sounds useful and you should give it a try.
FOP: Embedding fonts from classpath
If you’re using Apache FOP to create PDF/A you’re forced to embed all fonts (even the base 14 fonts). Generally there are two options how to embed the fonts:
- Let FOP auto-detect the fonts
- Create a font metrics file and tell FOP where to find it
String concatenation
One of the first things developers learn about String concatenation in Java is that the “+” operation does the magic. In this case the magician is the compiler. Lets look how the following code snippet gets translated by the compiler.
// Sample.java
String buffer = "";
for (String string : listOfStrings)
{
buffer += string;
}
// Sample.class
String buffer = "";
for (String string : listOfString)
{
buffer = new StringBuilder(buffer).append(string).toString();
}
Every time the String concatenation is invoked a new StringBuilder instance is created and but never assigned. Hence it is immediately eligible for Garbace Collection. What a waste of Memory. If you really need to concat Strings in a loop you better do it directly with a StringBuilder.
Google Collections Library 1.0 available
Last year on Dec, 30th Google released version 1.0 of it’s Collections framework. Although Apache Commons Collections provide a rich set of enhancements to the standard Collections framework Google’s implementation has two big advantages:
- Based on Java 1.5 and hence using Generics
- More standard compliant (Commons Collections occasionally break standard behavior)
Closures in Java
One of the most discussed (and most controversial) topics in the last years concerning the future of Java was the introduction of Closures. After 2008′s Devoxx Closures were off the Java7 release. One year later at the same event Mark Reinhold revoked it and announced that Closures will be in Java7 (and hence delaying Java 7 for a few months). Read the rest of this entry »
Be aware: Constants get inlined at compile time
Most books tell you that new String(“value”) should not be used since it creates two objects although only one is needed. But what the books almost never tell you is that there is one case in which you should use it: Java constants aka “public static final”. Read the rest of this entry »
Authentication via LDAP
Yesterday I was looking for a neat and clean solution for authenticating a user via LDAP. Most of the solutions I found read the user from LDAP and compared the credentials with each other. This might be useful if yohave to do other stuff with the User but just for authenticating its to bloated.
JSR-303: Bean Validation
In the last few days I created some JPA entities which are used in a Web Application and filled by the user. So what’s next? Input validation. I don’t like JSF’s f:validator tag since it displays only one error message which might be useful if you put the error message next to the input filed. But if you display all error messages bundled on the top of the main content the messages are non-sense for the user. Read the rest of this entry »

Recent Comments