BACKGROUND IMAGE: iSTOCK/GETTY IMAGES
At the EclipseCon conference, Mark Reinhold, Java platform chief architect at Oracle, laid out the roadmap for Java 9, which could mean better modularity and new value types. Improved modularity could reduce app size and improve startup performance. New value types will make it easier to program arrays.
The principal feature of Java 9 is the introduction of a module system and the application of that to the platform. "This will help us deal with the fact that from the beginning the Java platform has been this huge monolithic thing," said Reinhold. This has created challenges and limitations to running on smaller devices and cloud environments even with the smaller SE versions of Java. Mobile devices are constrained by limited device hardware.
Cloud environments face constraints around startup time and the overhead that must run with each cloud VM or Docker instance. This can add up as organizations try to componentize application infrastructure using design patterns like microservices where the overhead of unused Java functionality takes up a higher percentage of resources. Also, because Java applications are compiled at runtime, all the unused libraries slow down the startup process for new instances. "You want to maximize application density," said Reinhold.
Improving size and startup times
'From the beginning the Java platform has been this huge monolithic thing.'
Mark Reinhold, chief architect, Java platform group at Oracle
The basic Java runtime environment (JRE) consumes about 55 megabytes of memory for a basic Linux ARM build. Java 8 introduced the notion of the compact platform which provides a subset of functionality with far less memory. The smallest Compact 1 profile consumes about 11 megabytes of memory, compared with 17 megabytes for Compact 2, and 30 megabytes for compact 3. Those smaller profiles help but are not flexible for the kinds of applications developers want to create today, said Reinhold.
On the performance side, a more compact and modular JRE will lead to better startup performance. Existing startup performance is frustrating, said Reinhold. This is not such a big deal for applications that run for long periods. But this can create critical delays when an organization wants to spin up new application instances to address peak loads. The longer the delays, the more an enterprise architect has to overprovision cloud services to maintain acceptable performance.
Enforcing good security as a forethought
Building out a modular architecture that can help maintain or improve security is one of the big challenges to making this work. Security has been one of Java's strengths when applications are implemented properly. Unfortunately, many developers seek to call internal classes that were never intended to be called by outside applications. Reinhold said that organizations need to enforce coding practices around only calling public classes. Developers should never write applications that call internal classes like "sun.*" and "*.internal.*"
Many libraries and applications are written to use these internal classes. This not only creates security problems, but is a problem for the team that maintains the JDK and limits this team's ability to evolve the internal classes. When some of these internals were modified to improve security, they broke working applications, so the Java team had to put them back, said Reinhold.
Building a better classpath
The final class of problems that the Java team would like to solve with Java 9 modularity is the classpath. This is a source of startup performance pain, since the Java compiler uses a linear search mechanism to find all the dependent modules. This also creates a problem with internal configurations. It can be difficult to configure applications, because missing components might not be discovered at runtime. In some cases, an application can be deployed with duplicate components when developers use two versions of a popular library in the classpath. Tools like Maven can help a bit but do not solve all the problems.
The long-term goal of the Java team is to eliminate the classpath. In essence this will make it possible for developers to assemble their applications from a box of Lego parts, rather than a monolithic thing. These parts could be assembled in different ways and organized so that developers would not leave any important pieces out of the final application.
Eike Stepper, an independent software architect in Germany, said the idea of modules is not particularly new, because the basic principles have been available in OSGi for some time. Only time and implementation use cases will prove out the importance of Java modularity for building real-world applications.
New types could improve performance
Another big piece that could become part of Java 9 is a new type for representing arrays of values. This will make it easier to specify multiple variable values without using pointers. If programmers want to specify a set of X,Y coordinates today, they need to use pointers, which consumes additional memory overhead and processing time.
The new variable type will allow coders to inline all the points in an X,Y array without losing the expressiveness of individual point value. This new type will make it possible to create arrays consisting of several correlated variable complex numbers. But it will become less efficient as the number of correlated variables grows. These new value types are being defined as part of Project Valhalla and Project Panama.
Developers at EclipseCon were excited but cautious about the potential for new types. "The new array types seem like they could make a lot of use cases easier but developers will have to be careful not to create new problems," said Ivan Inozemtsev, a lead software developer at Xored who leads the Eclipse RCP testing tool project.
Will value types and structured arrays be Java 9's cap feather?
Java pro digs into trends in IoT, mobile, Java 9