Skip to main content

Java 7

So Java 7 was released yesterday. Here are a few things I found interesting taken from the release guide. Some very nice features that I have been waiting for for a long time - my favorites are the Stings in switch and catching multiple exceptions but that is just me. For the full story http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html or  http://download.oracle.com/javase/7/docs/

Language
  • Binary Literals - 0b or 0B. 
    • Ok but I wont be using it so much.
  • Underscores in Numeric Literals - Any number of underscore characters (_) can appear anywhere between digits in a numerical literal.
    • This may be quite confusing for my brain 52 == 5___2 weird but I suppose it helps with grouping
  • Strings in switch Statements - You can use the String class in the expression of a switch statement.
    • FINALLY been waiting for this.
  • Type Inference for Generic Instance Creation - You can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context.
    • Bit hard to read but I will get used to it.
  • Improved Compiler Warnings and Errors - The Java complier generates a warning at the declaration site of a varargs method or constructor with a non-reifiable varargs formal parameter. Java SE 7 introduces the compiler option -Xlint:varargs and the annotations @SafeVarargs and @SuppressWarnings({"unchecked", "varargs"}) to supress these warnings.
  • The try-with-resources Statement - A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. java.lang.AutoCloseable, java.io.Closeable interface can be used as a resource. The classes java.io.InputStream, OutputStream, Reader, Writer, java.sql.Connection, Statement, and ResultSet have been retrofitted to implement the AutoCloseable interface and can all be used as resources in a try-with-resources statement.
  • Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking - A single catch block can handle more than one type of exception. 
    • Nice this will help a lot with repeated code bloat. 
NIO
More comprehensive support for accessing file system.


Swing
Create Translucent and Shaped Windows 


Concurrency
The fork/join framework, which is based on the ForkJoinPool class, is an implementation of the Executor interface. It is designed to efficiently run a large number of tasks using a pool of worker threads. A work-stealing technique is used to keep all the worker threads busy, to take full advantage of multiple processors.

Networking
URLClassLoader.close
This method effectively eliminates the problem of how to support updated implementations of the classes and resources loaded from a particular codebase, and in particular from JAR files.

JDBC
  • try-with-resources automatically close resources : Connection, ResultSet, Statement
  • RowSet 1.1: The introduction of the RowSetFactory interface and the RowSetProvider class, which enable you to create all types of row sets supported by your JDBC driver.
VM
Garbage-First Collector replaces the Concurrent Mark-Sweep Collector - targeted for multi-processors with large memories,.
Java HotSpot Virtual Machine Performance Enhancements

Comments

Popular posts from this blog

ADF sort of generic screen for tables with the same structure

We have a couple (about a hundred) of tables with the same structure (Code, Description, Create Date, Update Date). So I wanted to do something simple so that I did not have to create all these screens 1) EO   I created the EO based on one of the tables I had that had the above columns. I then Added a transient attribute called table name to my EO based on a groovy expression. (the expression needs to change as I am reading web tier stuff from the model layer but I will fix this later) I then generated a java class for my EO. And added the following overriden method to my newly created java class. protected StringBuffer buildDMLStatement(int i, AttributeDefImpl[] attributeDefImpl,   AttributeDefImpl[] attributeDefImpl2, AttributeDefImpl[] attributeDefImpl3, boolean b) {   StringBuffer statement = super.buildDMLStatement(   i, attributeDefImpl, attributeDefImpl2, attributeDefImpl3, b); return new StringBuffer(StringUtils.replace(statement.to...

Util code

public static MethodExpression getMethodExpression( String expr, Class returnType, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); return elFactory.createMethodExpression( elctx, expr, returnType, argTypes); } public static javax.faces.el.MethodBinding getMethodBinding( String expr, Class[] argTypes){ FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); return fc.getApplication().createMethodBinding(expr, argTypes); } SetPropertyListener listener = new SetPropertyListener( ActionEvent.class.getName()); listener.setFrom(link.getRoute()); listener.setValueExpression("to", JSFUtils.getValueExpression("#{pageFlowScope.route}", String.class)); action.addActionListener(listener); AdfFacesContext.getCurrentInstance().getPageFlowScope() .put("route", lin...

MANIFEST.MF merge JDeveloper for an executable jar

Goto your project > properties. Then click on deployment in the menu. Edit or add a jar deployment profile. Fill in the details under jar options (select Include manifest and give it a main class name) Also remember that the merge functionality only works with a BLANK line at the end of the merge file. REALLY this caught me. My merge file contents: Class-Path: commons-codec-1.3.jar [...empty line here CRLF...]