I saw an article listing the Top 8 features in Java 7 and realized a number of them were already present in Oxygene for Java.
Strings in Case Statements
In Java they are Switch statements, but in Oxygene we call them a case statements. Instead of a series of ifstatements, you can use a single case statement to evaluate multiple values of a string.
This is much more elegant and easy to maintain. Hard to believe a lot of languages still don’t have that feature.
## Using Statements
In Java 7 this is called the try-with-resources statement, but the idea is to have a try block to catch exceptions and also close resources that need to be closed. Just like on .NET, the Java virtual machine supports a garbage collecting memory manager, but also just like on .NET there are unmanaged resources, like handles. These resources still need to be closed manually in your code, even when you encounter an exception. In Oxygene we make this really easy with the [**using** statement](http://wiki.oxygenelanguage.com/en/Using_(keyword)).
|method TestApp.ProcessStatus(status: String);begincase status of'urgent': DoUrgent;'high': DoHigh;'low': DoLow;else DoNormal;end;end;
|This is equivalent to a [**with** statement](http://wiki.oxygenelanguage.com/en/With_(keyword)) combined with a [**try-finally** statement](http://wiki.oxygenelanguage.com/en/Try_(keyword)). If you combine it with a **try-except**, you can handle exceptions and be sure your resources are also closed.
|using f :=new java.io.File(...)dobegin...end;
|This really gives you the ultimate control of handling the exception without needing to add extra code to close the resources.
One note about the using statement. In .NET the object instance that is manged by using must implement IDisposable. In Java the required interface is [Closable](http://docs.oracle.com/javase/1.5.0/docs/api/java/io/Closeable.html "Interface Closeable"). A class that implements Closable is a class that needs to be closed when you are done with it, and it is a class that using will close automatically for you.
## Binary Integral Literals
Java 7 adds support for binary literals using binary notation. Oxygene has that, and hexadecimal too!
|tryusing f :=new java.io.File('...')dobegin // use fend;// f always gets closedexcept// handle exceptionend;
|var bin := %10101010;var hex :=$DEADF00D;
This is another spot where Oxygene actually beats Java. With Java 5 & 6 you had to declare the type and the constructor completely, which got quite verbose for generic types. With Java 7 it introduced a left to right type inference, but you still have to specify a partial type on the right, and this feature only works with generic types.
In Oxygene you have a full right to left type inference. Just declare the variable using the var keyword on the left, and create a new instance on the right.
Of course the real beauty of this code is two-fold: The variable is always of the correct and best type, and if you later need to change the constructor, the type is updated automatically.
|var m :=new HashMap, List>;
Most of the rest of the new features were either added to the Java Framework, so Oxygene gets those automatically, or they are features that don’t really make sense to Java. Keep in mind there are still quite a few features in Oxygene that Java doesn’t even touch!