Java 7 is here…..it’s about time

2011/07/29 1 comment

Finally after a long time Java 7 is finally here. It has many features.

The most interesting features in my opinion are:

  • NIO 2, which is a real revolting to Java IO
  • Syntax extensions: Automatic resource cleanup(instead of close in finally), String in switch, binary literals, literals separator and shorter generic write
  • new Garbage Collector as default

You can download it from oracles download site for developer:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

The default user download site java.com still points to Java 6.

Categories: News Tags: , ,

[Off Topic] Iron the iPhone App

Usually I don’t talk about apple products apps. But this app is just amazing. It’s a bridge building app in 3D!

Check it out at http://www.ironapp.de or here is the direct itunes link.

Categories: Uncategorized

Simple LRU or FIFO Cache

There is a very simple way to make a FIFO or LRU cache with the existing LinkedHashMap implementation of the default Java VM made by Joshua Bloch.

The LinkedHashMap already has a method you can override, which defines when to remove the “oldest” entry. With the default constructor this is already a FIFO cache, because it is internal sorted after the insertion order.

To Change to LRU cache you have to change the order of the LinkedHashMap to use the access order. You do this with the other constructor new LinkedHashMap(MAX, 0.75, true). ’0.75′ is the default value taken from the LinkedHashMap code itself.

The serialVersionUID is only a proposal of FindBugs, because it is a anonymous inner class now with a changed behavior.

    private final Map cache = Collections.synchronizedMap(
            new LinkedHashMap(MAX) {

                /** Serial UID. */
                private static final long serialVersionUID = 2546245625L;

                @Override
                protected boolean removeEldestEntry(Map.Entry eldest) {
                    return size() > MAX;
                }
            });

Categories: Uncategorized Tags: , , , ,

JaCoCo – the new and revolting Java Code Coverage tool

I’ve stumpled across JaCoCo while searching for a possibility to have the code coverage of a multi modul project merged.

JaCoCo is made from the same developer, which made the eclipse plugin EclEmma.

The big advantage (and disadvantage maybe) is that JaCoCo uses a JavaAgent to instrument the classes on the fly. That means no extra instrumentation step is needed beforehand. The disadvantage is, you need to specify the JavaAgant as a JVM parameter.

But imho it’s a far better solution of the instrumentation problem as the old instrument the classes you want coverage for step.

JaCoCo is available for Sonar 2.2. Sadly there doesn’t exist a stable maven2 plugin yet (there is one for sonar and on mojo/sandbox). But it should only be a matter of time :)

http://www.eclemma.org/jacoco/

Java 8 contains similar JodaTime API

Java 8 will finally have a new time/date API (It’s about time).

The new API is similar to the Jodatime API (one of the best APIs available).  http://joda-time.sourceforge.net/

Categories: News Tags: , , ,
Follow

Get every new post delivered to your Inbox.