Find Time for Java and more!

31 May, 2009

Thank You for Your Interests!

Filed under: Java, News — karussell @ 21:45

Thanks for your attention and comments the last months! Hope you will enjoy the next months …

I started my blog in November 2007.  Now, May 2009 was the first month with more than 5 000 users (and even over 6000 -> 6080).

The monthly statistics looks a bit like the physical phenomena called ‘Maker-fringes’:

Stats:

stats-2009

Maker-fringes:

maker-fringes-gemessen

In my diploma thesis 2 years ago I studied this phenomena in detail.
BTW: this fancy ;-) picture I got with my performant Java genvlin plotter.

24 May, 2009

Code Quality Tools in Java

Filed under: Java, Maven — karussell @ 15:53

There are several tools to measure the code quality. The one I tried with a lot of success are:

  • FindBugs (latest version 1.3.8) – uses static analysis to look for bugs in Java code. This is a great tool, it discovered possible NullPointerExceptions and a lot more bugs in my projects. Sometimes I asked myself how this program could have discovered this ‘complicated’ bug.With the maven plugin you can do:
    mvn findbugs:findbugs

    which will use version 1.3.8 out of the box

  • PMD (latest version 4.2.5) – scans Java source code and looks for potential problems. The rules are configurable, but at the beginning you will only need the provided one (and spend a lot of time to choose your favourites ;-) )In NetBeans 6.5 this tool is well integrated and works like a charme (CTRL+ALT+P).

    With the maven plugin you can do:

    mvn pmd:pmd

    after you specified the following in the pom.xml under<reporting> <plugins> :

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pmd-plugin</artifactId>
      <version>2.3</version>
      <configuration>
        <targetJdk>1.5</targetJdk>
      </configuration>
     </plugin>

Other tools could be

  • JarAnalyzerIs a dependency management utility for jar files. It’s primary purpose is to traverse through a directory, parse each of the jar files in that directory, and identify the dependencies between the jar files.
  • HammurAPIa code quality governance platform

but I didn’t tried them so far.

For Findbugs  and pmd there is a NetBeans plugin (SQE … software quality environment) which looks promising, but fails with a NullPointerException after I installed it via the update center and tried it on my project. Maybe I should use one of the snapshots. (BTW: I successfully used the pmd-plugin and findbugs in the standalone version).

Sonar is another interesting approach to use several code quality tools at a time. With Sonar it is possible to see the violations or possible bugs over das or weeks  – so, you are looking at the improvements and you will not get lost in the mass of bugs at the beginning. Another “multi-tooling” project is XRadar.

A little bit offtopic, but a great tool is proguard, which shrinks, optimizes, obfuscates and preverifies Java class files. There is even a maven plugin for that.

21 May, 2009

JavaOne 2009 Timetable – Update of TimeFinder Documentation

Filed under: Java, Timetabling — karussell @ 23:15

Microbenchmarking Java – Compare Algorithms

Filed under: Java, News — karussell @ 15:51

There are a lot microbenchmark tips out in the www. The intent of them differs from author to author.

Today I want to show how you could compare e.g. different algorithms. You could simply do:

int COUNT = 1000000;
long firstMillis = System.currentTimeMillis();
for(int i = 0; i < COUNT; i++) {
  runAlgorithm();
}
System.out.println("Mean runtime of algorithm in seconds:"+(System.currentTimeMillis()-firstMillis) / 1000.0 / COUNT);

There are several problems with this approach, which results in very unpredictable results:

  1. Make sure the variable COUNT is high enough (if runAlgorithm() is unexpensive). Then make sure you run this code several times. Additionally you should measure the RMS either for each runAlgorithm call or at the end of this code snippet for a better comparison with other algorithms.
  2. You should turn off the JIT-compiler with specifying -Xint as a JVM option, otherwise your outcome could depend on the (unpredictable) JIT and not on your algorithm.
  3. You should start with enough memory, so specify e.g.-Xms64m -Xmx64m. Because JVM memory allocation could get time consuming.
  4. Quit all other applications or at least you should use
    long firstNanos = mx.getCurrentThreadCpuTime();
    ThreadMXBean mx = ManagementFactory.getThreadMXBean();

    instead of

    long firstMillis = System.currentTimeMillis();
  5. Avoid that the garbage collector runs while your measurement: -Xnoclassg
    But make sure you have enough memory!

After this I got relative stable results: The difference of maximal and minimal value for the result is less then 4% after 10 runs.

16 May, 2009

Further with Maven and WebStart (jnlp)

Filed under: Java, Maven — karussell @ 22:16

If you want no server side setup for webstart all your clients must have a java version greater than java6 update 10 (the naming convention gets too complicated now, mr. sun! …)

For ubuntu 8.04 see my last blog entry how to install this java version.

All you need to do in our maven set-up of this post is to add the following 2 lines to our pom.xml:

</sign>
<pack200>true</pack200>
<gzip>true</gzip>

<verbose>true</verbose>

Then do:
mvn clean install webstart:jnlp
again and add one line

<j2se version=”1.6+” initial-heap-size=”32m” max-heap-size=”128m”/>
<property name=”jnlp.packEnabled” value=”true”/>

to our jnlp template.

And as it is described here you could even use the versioning feature
<property name=”jnlp.versionEnabled” value=”true”/>
with a specific naming convention, too:
foo__V1.0.jar

But all only if the clients have java > java6 update 10 …

Start here the latest TimeFinder version to try a servlet-free-packed200 application out. With jars it was approx 9 MB. Now all pack.gz files in sum are 3.3 MB! And the download time was approx 160 seconds, where now I downloaded und unpacked it within 40 seconds with the same internet connection. You can try it for yourself via switching the java version e.g. from java6_10 to 6_7 or to java5 (in ubuntu this is relative easy with ’sudo update-alternatives –config javaws’) But before you have to remove the application from cache: start javaws -viewer, search TimeFinder’s shamrock and remove it. Otherwise TimeFinder would start nearly instantaneous.

Java6 update10 on Ubuntu 8.04

Filed under: Java — karussell @ 22:14

For ubuntu 8.04 there is no Java6 update10 supported
But you can download the .deb file here (- no WARRANTY for the files and not for this tip …)

Then install them via -I used the lasted 13:

 sudo dpkg -i sun-java6-bin_6-13-1_i386.deb sun-java6-jre_6-13-1_all.deb
 sun-java6-plugin_6-13-1_i386.deb sun-java6-jdk_6-13-1_i386.deb

Verify your installation via:
java -version
javac -version
javaws -version
=> 1.6.0_13

You can switch java versions (e.g. between openjdk and sun) via:
sudo update-alternatives –config java
or
sudo update-alternatives –config javac

You should now be able to download the latest alpha version of timefinder, where I used pack200 without a special server set-up! See more details in the next post.

5 May, 2009

Maven and WebStart (jnlp)

Filed under: Java, Maven — karussell @ 13:50

If you plan to deploy your maven application via webstart you are a lucky man, because this is easy if you know how to do it ;-)

I tried it without success, but then Geoffrey with his networktools came to my rescue. Now TimeFinder is jnlp-enabled. The following steps were necessary:

  1. create a new folder ‘jnlp’ under src/ (where main and test live)
  2. put the file template.vm there with:
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://timefinder.sourceforge.net/jnlp2" href="$outputFile">
     <information>
        <title>TimeFinder</title>
        <vendor>TimeFinder Team</vendor>
        <homepage href="http://timefinder.sourceforge.net/"/>
        <description kind="one-line">TimeFinder</description>
        <description kind="short">TimeFinder - the automatic timetabling generator for universities and schools</description>
        <description kind="tooltip">TimeFinder - the automatic timetabling generator for universities and schools</description>
        <icon href="http://timefinder.sourceforge.net/jnlp/shamrockwhite.jpg" kind="default"/>
        <shortcut online="false"><desktop/><menu submenu="TimeFiner"/></shortcut>
     </information>
     <security>
     <all-permissions/>
     </security>
     <resources>
        <j2se version="1.6+" initial-heap-size="32m" max-heap-size="128m" />
        <property name="jnlp.versionEnabled" value="true"/>
        $dependencies
     </resources>
     <application-desc main-class="$mainClass">
     </application-desc>
    </jnlp>
  3. create a keystore:
    keytool -genkey -alias timefinder -keystore timefinder.jks
    be sure that you use keytool from the same JDK-PATH as you use for maven!
  4. add the following to your pom.xml:
    <build>
      <plugins>
        <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>webstart-maven-plugin</artifactId>
           <version>1.0-alpha-1</version>
       </plugin>
     </plugins>
     <pluginManagement>
        <plugins>
           <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>webstart-maven-plugin</artifactId>
             <!-- do not bind to install phase
              <executions>
               <execution>
                 <goals>
                   <goal>report</goal>
                 </goals>
               </execution>
              </executions>
              -->
            <configuration>
               <jnlp>
                <mainClass>de.timefinder.core.Startup</mainClass>
               </jnlp>
              <sign>
               <keystore>/home/peterk/Dokumente/quell/timefinder/trunk/timefinder-core/timefinder.jks</keystore>
               <keypass>unsecpwd</keypass>
               <storepass>unsecpwd</storepass>
               <storetype>jks</storetype>
               <alias>timefinder</alias>
               <verify>true</verify>
             </sign>
            <verbose>true</verbose>
          </configuration>
         </plugin>
       </plugins>
      </pluginManagement>
     </build>
    </project>
  5. Now you should be able to execute:
    mvn install webstart:jnlp
    which will create a zip file with all the signed jars
  6. See my next post for versioning and pack200!

Blog at WordPress.com.