Friday, 13 July 2012

Hazelcast - more then distributed cache

Hazelcast is an open source clustering and highly scalable data distribution platform for Java, which is:
  • Lightning-fast; thousands of operations/sec.
  • Fail-safe; no losing data after crashes.
  • Dynamically scales as new servers added.
  • Super-easy to use; include a single jar.

With its various distributed data structures, distributed caching capabilities, elastic nature, memcache support, integration with Spring and Hibernate and more importantly so many happy users, Hazelcast is feature-rich, enterprise-ready and developer-friendly in-memory data grid solution.

To run it you just run a single jar file!

Presentation is available here: http://www.hazelcast.com/screencast.jsp

JUnitParams - librabry for JUnit

This project adds a new runner to JUnit and provides much easier and readable parameterised tests for JUnit >=4.6.

Main differences to standard JUnit Parameterized runner:

  • more explicit - params are in test method params, not class fields
  • less code - you don't need a constructor to set up parameters
  • you can mix parameterised with non-parameterised methods in one class
  • params can be passed as a CSV string or from a parameters provider class
  • parameters provider class can have as many parameters providing methods as you want, so that you can group different cases
  • you can have a test method that provides parameters (no external classes or statics anymore)
  • you can see actual parameter values in your IDE (in JUnit's Prameterized it's only consecutive numbers of parameters):

More on project page: http://code.google.com/p/junitparams/

Bending the Java spoon - op4j

op4j is a powerful implementation of the Fluent Interface style of code. It allows you to create chained expressions which apply both predefined or user-defined functions to your objects in a fluid and readable way. This improves the way your code looks and greatly reduces the complexity of executing auxiliary low-level tasks in the highly bureaucratic, statically -and strongly- typed language that Java is.
It is a great library for complicated operations on Collections in one line.
More on: http://www.op4j.org/

Tuesday, 10 July 2012

Do not implement/generate getters and setters!

Project lombok is a java library which prevents you from implementing or generating getters and setters for POJOs. You just add annotation on the class or on the individual property. Having such code, that just gets and sets properties is unmaintainable and bad for class clarity.
This library has also some other useful features like f.e. @Delegate - annotation that ease creating classes with delegation methods.

Here you can see examples:http://projectlombok.org/features/index.html

Tomcat startup takes extra 3 minutes. Why?

I have faced a problem of long startup of tomcat 7 that used jvm 7 on the linux server. Tomcat without any application started over 3 minutes. In the catalina.out log there was a message:
May 22, 2012 10:02:48 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation
using [SHA1PRNG] took [131,611] milliseconds.
This problem appears due to Tomcat 7+ usage of SecureRandom class to provide random values for its session ids. You can use non-blocking setup, just set the following system property: -Djava.security.egd=file:/dev/./urandom
You can read more on this subject in tomcat wiki: http://wiki.apache.org/tomcat/HowTo/FasterStartUp

Monday, 9 July 2012

Invoke dynamic in java 7

Recently I have attended Confitura 2012 a Java Conference in Warsaw. One of the most interesting lectures was the one made by Waldemar Kot. He has introduced subject of the new instruction in Java 7: Invoke dynamic.
He has shown that it has a very big impact on the java development, not only on dynamic languages on JVM. Using invoke dynamic in java you can have dynamic behavior with speed comparable to static invocation.
You can see examples and benchmarks here: https://github.com/waldekkot/Confitura2012_InvokeDynamic

Wednesday, 4 July 2012

Let's try implement an algorithm

If you want to train implementing algorithms you can go to the Project Euler.

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.