According to Dutch research firm Tiobe in terms of overall popularity, Java ranked 5th in 1997, 1st in 2007 and 2nd in Sept 2012. At the time of writing there are over 2,000 Java programming books on Amazon in English and there are almost 300,000 threads on Stackoverflow related to Java. However, as George Orwell once said: ‘Whoever is winning at the moment will always seem to be invincible’. But is Java invincible or beginning to die? That’s the question being asked more and more now.
In my humble opinion, the challenges to Java can be split into three categories:
- The rise of alternative languages
- Scalability / Multi-Core processors
- The return of the fat client.
The rise of alternative languages
Alternative languages can be split into two groups: those that run on the JVM (Scala, Groovy etc) and those that don’t (Python, Ruby). One interesting thing is that the first group is pretty large. The languages that run on the JVM aren’t mutual exclusive to Java and in a sense strengthen it reminding us what a remarkable piese of software engineering the JVM is. Development teams can get that extra bit of expressiveness in a niche language like Groovy, but can still call out to Java when they need some cool Java library or just need that extra bit of performance. Remember the advantages in Groovy 2.0 speed it up but it is still not as fast as Java.
As for the features some of these languages provide that are not in Java, well that is the case but it won’t always be the case. Take a look at the roadmap for Java 8 and the features it will include. Just like Java EE 5 and 6 took ideas from Spring / Seam, the Java lanuage in its 8th major release will be taking ideas from other languages. For example literal functions will be facilitated by Lambdas. Java 8 Lamdas will have support for type inference and because they are just literals it will be possible to pass them around (and return them) just like a String literal or any anonymous Object.
That means instead of having to write an implementation of Comparator to pass to the Collections sort utility to sort a list of Strings, in Java 8 we will just do:
Collections.sort(list, (s1, s2) -> s1.length() - s2.length());
So, the alternative JVM languages don’t exactly kick Java out of the party. It is still there, but in a party that has a better selection of music played and in a party where the guests encourages their host to be a better host.
Scaling on the multi-core platforms
As for multi-core and JVM – we all know that with a JVM running on a single core it was possible to spawn threads in the very first release of Java. But these threads weren’t executing in parallel, the CPU switched between them very quickly to create the impression that they were running in parallel. JStack may tell you that 50 threads have state ‘runnable’ on your single core machine but this just means they are either running or eligible to run. With multi-core CPUs it is possible to get true parallelism. The JVM decides when to execute threads in parallel.
So what’s the deal here? Firstly, even though concurrency and threads were a feature of Java from the very beginning the language support was limited meaning development teams were writing a lot of their own thread management code – which could get ugly very quickly. This was alleviated greatly in JDK 1.5 with the arrival of a range of thread management features in the java.util.concurrent package. Secondly, to get better parallelism something else was needed. This came in Java 7 with Doug Lea’s Fork / Join framework which uses clever techniques such as work stealing and double sided queues to increase parallelism. However, even with this Framework decomposing (and re-arranging) data is still a task that is needed to be done by the programmer.
Functional progamming gives us another option to perform computations on data sets in parallel.
In Scala, for example, you just pass the function you wish to operate on the data and tell scala you want the computation to be parallelised.
outputAnswer((1 to 5).par.foreach(i => longComputation))
And guess what? The same will be available in Java 8.
Array.asList(1,2,3,4,5).parallel().foreach(int i ->heavyComputation())
Since scalability and performance are architectural cousins, it is worth stating that in many experiements Java still out performns other languages. The excellent Computer Language Benchmark Game shows Java outperformaning many languages. It hammers the likes Perl, PHP, Python3, Erlang in many tests, beats Clojure, C# in nearly all tests and is only just behind C++ in terms in the performance results. Now, performance tests can’t cover everything and a context will always have some bias which favours one language over another but going by these tests it is not as if Java is a slow coach.
The return of the fat client
In summary, Java has had some bad moments. AWT was a rush job, Swing had performance problems, the early iterations of EJB were cumbersome and JSF was problematic in comparison to other frameworks such as Struts and Spring MVC. But, even today, extremely innovative projects such as Hadoop are built using Java. It still has massive support from the open source community. This support has not only helped Java but also show Java some its problems and things it needs to get better at. Java has shown it has the ability to evolve further and while other languages challenge it I don’t think the game is over just yet. It goes without saying, a lot will of the future of Java will depend on Oracle but let’s hope whatever happens that the winner will be technology.
- Yammer and their migration to scala
- James Gosling taking about the state and future of Java at Google tech talk
- Article from Oracle describingFork and Join in Java 7
- Eric Bruno:Building Java Multi-Core applications
- Edgardo Hernandez:Parallel processing in Java
- IEEE top ten programming languages
- JDK 8 downloads
- Java Code Geeks article on Fork Join
- Good Fork Join article by Edward Harned
- Fork / Join paper from Doug Lea
- Fork / Join Java updates information from Doug Lea
- Scala Java Myths – great article by Urs Peter and Sander van der Berg
Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code
Use Java? If you do, you know that Java software can be used to drive application logic of Web services or Web applications. Perhaps you use it for desktop applications? Or, embedded devices? Whatever your use of Java code, functional errors are the enemy!
To combat this enemy, your team might already perform functional testing. Even so, you're taking significant risks if you have not yet implemented a comprehensive team-wide quality management strategy. Such a strategy alleviates reliability, security, and performance problems to ensure that your code is free of functionality errors.Read this article to learn about this simple four-step strategy that is proven to make Java code more reliable, more secure, and easier to maintain.