Tag Archives: java

log4j performance

      No Comments on log4j performance

Log4J is the current de facto standard not only in open source development. It claims to be fast and flexible: speed first, flexibility second. But there are some pitfalls when it comes to the crunch. The costs of a log request consists of a method invocation and an integer comparison. This is typically about 1-20ns (depending on your processor) per… Read more »

FileWriter, XML and UTF-8

      1 Comment on FileWriter, XML and UTF-8

Deep down in the Java-API: http://java.sun.com/javase/6/docs/api/java/io/FileWriter.html Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream. So, if you want to write you XML-Document to a file, for the love of god, don’t use the… Read more »

Quickly zooming a BufferedImage

      No Comments on Quickly zooming a BufferedImage

If you don’t need a scaled instance of your BufferedImage in the memory, you can use “on-the-fly scaling”. For example, this custom JComponent can be used to display a BufferedImage and zoom it with the setScaleFactor(..)-method For some benchmarking on the different RenderingHints values see Chris Campbell’s great article The Perils of Image.getScaledInstance() Resources: http://java.sun.com/docs/books/tutorial/2d/advanced/quality.html http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html

Changing default Look’n’Feel for Netbeans (and the GUI builder)

Netbeans’ GUI builder is great. It’s one of the essential features that made me drop eclipse. But designing accurate GUIs can be a pain in the arse. Especially, when you use the GUI builder with a certain preview Look and Feel (e.g. GTK+) but you application later runs with a completely different L’n’F (e.g. Nimbus). It’s almost certain, that your… Read more »

Java Generics and Comparables

      No Comments on Java Generics and Comparables

When designing a generic class which needs a parameter that is comparable you will probably end up with something like this: Unfortunately, using Comparable isn’t as “easy”. The Page interface described above can’t be instantiated for a type like java.sql.Time, which is not Comparable to itself, but to a supertype (i.e., java.sql.Time implements Comparable<java.util.Date>). David Hall suggests: “If you’re going… Read more »

Using a ResourceBundle for localization

      No Comments on Using a ResourceBundle for localization

There is a nice java tutorial from Sun how to use ReseouceBundle for localization: http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html. It’s actually rather simple: Just create a new ResourceBundle object by invoking the getBundle method, specifying the base name and Locale: The getBundle method first looks for a class file that matches the base name and the Locale. If it can’t find a class file,… Read more »

Syntax highlighting reloaded

      1 Comment on Syntax highlighting reloaded

Recently (well, yesterday to be exact) I was really sold on a a syntax highlighting plugin for WordPress called WP-Syntax. Basically, I am still. It is still easy to use, looks good and comes with a huge variety of supported languages. But if you ask the WordPress-guys it isn’t first choice. In their FAQ they point you to Alex Gorbatchev’s… Read more »

Syntax highlighting ftw!

      1 Comment on Syntax highlighting ftw!

I just ran into WP-Syntax which is a syntax highlighting plugin for WordPress using GeSHi. It supports a wide range of popular languages (including of course Java!). Examples? Here we go: 1 2 3 4 5 public class Hello { public static void main(String[] args) { System.out.println("Hello world!"); } }public class Hello { public static void main(String[] args) { System.out.println("Hello… Read more »