Select Page

Author: Erlend Ødegård

Java 10 is out!

About six months after the Java 9 release, Oracle has as promised delivered the new Java 10 version. JDK 11 is scheduled for September. The biggest news in the spring release is type inference for local variables. We are now able to write: var list = new ArrayList<String>();. Inference only means that the compiler will assume the type. In the example above the inference is based on the initialization of the local variable. No worries: Java will still be a statically typed language. Other news in the release include further support for Docker images. The JDK is available for...

Read More

Constructors with too many parameters

Constructors have a tendency to grow in size as code matures. Deciding to use a normal constructor or using a builder mechanism is dependent on the number of attributes you need to set when instantiating objects. If you have only 3-4 parameters to the constructor there is no need to go for a builder. The default setting in checkstyle is a maximum of 7 parameters before it complains. Turning on checkstyle on the code below gives the following message: More than 7 parameters (found 10). [ParameterNumber]. A builder is a good way to improve the code and avoid difficult...

Read More

Java 9 is finally here!

The long due final version of Java 9 has been relased. It is available for download from Oracle: Java 9 is a major release that it will take some time to get in to for most of us. So far I have started using the new JShell which is a command line tool for running code – a so called REPL. I’ve started using it for playing with legacy code:

Read More

Using jshell in Java 9 to understand old legacy code

One of the new and I think my favorite feature of the Java 9 SDK is the new tool called JShell. I have found the tool very useful in playing with legacy code. Legacy Java code can be very complex and I find it useful to be able to experiment with snippets of it without having to recompile and run the full project from an IDE or application server. This blog post will cover the basics of getting up and running with JShell. I will also use the technique in other blog posts. Three steps to get jshell started:...

Read More

How to replace Hashtable in old Java code

As a Java programmer around the turn of the century I used Hashtable all over the place. It should now be considered legacy code and be replaced for instance by HashMap when you are upgrading old code. This post will cover how to get rid of Hashtable, some warnings, and simplify the code. Opening a Java file from 2002 I find code similar to the lines below. Hashtable cache = new Hashtable(); cache.put( "key1", "Chached 1" ); cache.put( "key2", "Chached 2" ); String firstValue = (String) cache.get( "key1" ); System.out.println( firstValue ); Pasting the legacy code in to JShell I...

Read More
  • 1
  • 2

Recent Tweets

About This Site

Refresh Java – the blog dedicated to modernizing Java code.