Java 7 features



Preparing myself here for some interviews and reading about Java, I came to review some features that were added to Java 7 and Java 8. First, let start with J7:

Java 7 features

Diamond operator

The diamond operator is a way to facilitate the declaration of variables, saving time and makes the code less confusing.

Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> ();
Map<String, List<Trade>> trades = new TreeMap<> ();


String in the switch statement:

switch(status) {
    caseX:  x();
    caseY:  y();

try optimization

No need to use the finally mandatorily as before we can do only:


} catch(Exception){


Exception handling at the same time


} catch(Exception1 | Exception2 | Exception3){



It’s so useful just use path, get the file and use it.


I didn’t know about this feature, which is quite interesting btw. You can basically look at the file changes modification and be notified by it. Cool. But you actually need to create a service to watch the file.

WatchKey key = watchService.take();

invokedynamic Feature

Called Java secret weapon [2]. Interestingly to learn about this I watched [3], describing the use of invokevirtual – which you can see it on bytecode.

This is a feature that is explored much more in J8[4]

It enables the use of dynamic languages above the JVM. I will create a separated article about it later.








Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s