Why Java is (Still) Very Relevant

The Java coffee is still hot.

The Java coffee is still hot.

Every now and then new articles come up about how some other shiny language does the job better than Java. It is possible for one to be blinded by them and discard Java as a yesteryear’s technology. This article shows why Java is still highly relevant and a strong candidate for developing new enterprise applications (web/ mobile/ desktop).

In this longish article, we shall cover:

  1. 4 technical advantages
  2. 3 business advantages
  3. 4 common perceptions examined
  4. Conclusion

 

The Technical Advantages

We present a few salient features of the Java technology and explain in simple terms how they help.

Advantage 1: JVM Technology – the Middleman Approach

The Java language was born as the default language with the Java technology, which is fundamentally different from what existed before. Java code is compiled not for any given operating system but for an abstraction of the operating systems called as the JVM (Java Virtual Machine). The JVM plays a middle man and translates the program instructions to the instructions that the operating system would recognize. The most well-known advantage of Java — the platform independence — comes from this fact. The JVM is already available for all popular operating systems, which means that Java programs would run on these system out of the box.

The need to provide platform independence in desktop applications is not at all trivial, given that different platforms use vastly different technologies for UI components, UI layouts and graphics handling. Sun put in a lot of effort in developing the AWT and Swing technologies (for Java) for this reason, and IBM later added SWT to this mix. Java also offers a web start technology by which the latest version of a desktop application is be downloaded from the web (if it does not exist or is of lower version) and launched with a single click. Today we see desktop applications being less and less used in enterprise computing, but if business needs a desktop application, then Java is very strong in this area.

As a side note, let me add that platform independence can be claimed by several other languages too. For example, the interpreters of many interpreted languages such as Ruby, Python, PHP are available across various platforms and they can claim platform independence. Similarly, C and C++ compilers are available for various platforms and therefore even these languages can claim platform independence for the source form (but not for the binaries – as the compiled outputs will be specific to the platform). Although this article is about why Java is relevant, we want to caution that Java has company there and hence using Java purely for platform independence does not make sense.

JVM is a smart middleman and that’s where it has impressive credentials. It adds a great value in a couple of important areas:

  • It does an efficient memory management, or resource management in general. For example, instead of going to the operating system every time the program requests for memory, it grabs the memory in larger chunks and handles the requests internally. JVM has an inbuilt garbage collector which automatically frees up the memory as a resource is freed up. It is true that in good old days (when Java was in version 1.2) it was dreadfully slow; but over the years the JVM has become blazingly fast – arguably the fastest platform.
  • Apart from performance, JVM adds security to applications. Since all the resource requests that a Java application makes have to go through JVM, JVM can act as a watch guard to make sure that unauthorized access does not happen. One can configure this access at the JVM level.

Although Java was born for JVM and remains the default language for the JVM, it is not the only JVM language any more. Many languages (such as Python and Ruby) are ported to JVM, and there are a whole set of new languages that are supported on JVM (including Groovy and Go). I remember reading that there are 200+ languages supported on JVM today. They share with Java the benefit of better resource management and security, though all may not work as efficiently as Java does.

Another important technology that rivals JVM on the same lines is the CLR (Common Language Runtime) from Microsoft, which takes the center stage of the .Net technology. Like JVM, CLR acts as a smart middleman for binary bytecode. This bytecode could be compiled through several languages like C#, VB.Net. At the time when Java was the only language supported by JVM, Microsoft .Net boasted of multiple languages being used for .Net development. Here are couple of comparison points between the two:

  • Java is open source whereas .Net is a proprietary technology. Being open source, Java enjoys wider acceptance.
  • While CLR can be available cross platform (and indeed the non-Microsoft platforms are supported by the mono project), it’s more at home on the Microsoft platforms. The support for non-Microsoft platforms is expected to be far lower. Also, the CLR for non Microsoft platforms is always expected to lag a couple of versions behind that on Microsoft platforms. For these reasons, .Net is used for development on Microsoft OS and not for cross platform applications.

 

Advantage 2: Compilation Pre-empts Problems and Prevents Them from Happening

Java gets compiled to a bytecode. C or C++ get compiled to native machine code instructions. Contrast these with languages such as Ruby, Python, PHP or Groovy which do not get compiled to any binaries but are read line by line and executed at run time. The later languages are therefore called interpreted languages.

Many modern interpreted languages support some interesting programming constructs which not only shorten the lines of code but also eases out the expression. These constructs are really enviable by programmers using compiled languages, and are heavily touted as productivity gainers. In recent times, Scala – a modern compiled JVM language – has stirred this area by providing some similar constructs.

However, if we look beyond these programming constructs, compiled languages have certain solid advantages over interpreted languages:

  • With an interpreted language, if there is an error in line #48, by the time it is caught the first 47 lines have already run. Further, consider that in today’s complex programs, there are so many different flow conditions that it is challenging that testing has covered every path. This means that a problem that could go unnoticed with an interpreted language is easily detected by the compilation process. Compilation can therefore be seen as a guarantee that all the problems that are caught by compilation errors will not exist in a code that passes compilation successfully. Such a guarantee does not exist for runtime checks. Naturally, compiled programs will be more robust. This is really a huge advantage.
  • Compilation opens the door to certain flow optimizations. This is not a possibility with an interpreted language.
  • The compilation creates binary code that is closer to the machine instructions. Therefore the compiled programs will always execute faster by at least a factor of 3-4 times.

Java has these advantages of being a compiled language over the interpreted languages, However, remember that the Java bytecode is interpreted by the JVM at runtime and hence it has a disadvantage in performance in front of C / C++ which generated binary machine code on compilation. However, the smart memory management that JVM provides out of the box compensates for this performance loss. Java programs have been reported to beaten their C/ C++ equivalents in certain cases. Note that a C / C++ program can always implement efficient memory management (and beat Java), but that would take a lot of effort by skilled programmers; so in practice Java’s out-of-the-box memory management wins. Native compilers for Java are available too.

 

Advantage 3: Static Typing Makes Programs Robust

Java has roots in C and C++ and it implements static typing just like them. It means that the type of every variable has to be specified when the variable is declared. The alternatives are zero typing (a variable value is tried to interpret based upon its context) or dynamic typing (variable can take value of any type and behaves according to the value).

Because the type of a variable is clearly specified, the compiler can find out if a variable of some wrong type is passed where it is not supposed to. The compiler gives errors in these cases, and a programmer has to fix them before he can run the program. As we saw before, these compilation checks result into a guarantee that such problems will be completely absent in the code.

As the software testing theory says, no amount of testing is enough to certify that a program is completely bug free. Given this fact, it’s really a great help to get immunity from certain kind of coding errors, since no amount of runtime testing is going to do that for us. The combination of static typing and compilation give this guarantee, and hence they are invaluable especially for enterprise apps.

 

Advantage 4: Ample Choice of Frameworks

Java has the largest choice of frameworks available. This is a direct outcome of Java community being one of the largest and Java being open source, Name a programming paradigm or a technology (such as XML parsing, Aspect oriented programming, Templates, Image manipulation) and you will see that there is a Java version. Often, it started out with the Java version. So unless it got ported, it is available only with Java.

This gives Java developers the widest choice among these technologies and choose a combination that fits the project needs the best. Indeed, Java has a good number of sophisticated technologies even for most rudimentary program functions such as:

  • Logging: log4j, java.util.logging, slf4j, logback
  • Build and Deploy: ant, maven, ivy, gradle

 

The Business Advantages

Advantage 5: Developer Availability

Considering the life of a software, the development is the first and most important step, there is a longer life span beyond it over which the software gets maintained and enhanced (unless it dies prematurely for some reason) at a lower burn rate. The longer this life span is, the more return on investment the software has delivered, and hence it’s good for business.

While choosing a technology, one has to keep in mind the availability of programmers not only for developing but also for maintaining and enhancing it over this long life span. Java fares extremely well in this respect.

Java is a mainstream language, and it has been the most widely known programming language. The Tiobe index shows that Java has been at number 1 position over many years and recently come as the close 2nd next to C. Most modern languages trail far behind.

Many colleges and IT training institutes churn out Java programmers in good quantity, and hence it’s relatively easy to recruit Java programmers as opposed to other languages. If you choose Java, you can rest assured that you will not have a problem in finding people to maintain your application.

It is worth noting the other side of the coin, popularly known as the Python Paradox. Paul Graham talked about Python and Java, but it can be safely generalized as follows: if you choose a non-mainstream language (Python) over a mainstream programming language (Java) for doing your project, then you will get a far lesser choice of developers; but those will always be high quality developers (since the average developers will not spend their time in looking at a non-mainstream language), so your project will always be in safe hands.

In our opinion, be it mainstream languages or non-mainstream languages, good quality programmers are always in great demand. Considering the long life span of a software, it is highly likely that your original developers who develop the software are not around as it matures. It is a business risk if you are not able to replace any leaving developers quickly, and Java is your best bet today to guard against this risk.

 

Advantage 6: Moderate Requirements on Developer Skills

Java alleviates a programmer from doing the memory management. Memory leaks was a big problem before Java (in the C/C++ era) and good programming tricks were needed to get it right. The task of freeing up the memory is outsourced to the JVM’s garbage collector, which makes this need obsolete in the Java world.

Java comes with one of the richest libraries of reusable code out of the box, and it keeps increasing with every release. In addition, many third party libraries are also available to complement this functionality. As a result, your Java program can make use of advanced techniques such as highly efficient input / output, caching, concurrency as long as the programmer can just call these libraries (which requires much less skill as opposed to writing this functionality).

 

Advantage 7: Availability of Community Support

Because of the large community that Java enjoys, if you are stuck, help is always around the corner. There are Java developer groups across all the major programming destinations in the world. Originally, Sun Microsystems and later Oracle (after it acquired Sun) have consciously helped develop this community. They also put in place a Java community process by which the community has a say on the features that go in Java.

Java has also strictly followed the practice of backward compatibility. This means that your programs continue to run on newer versions of Java, without needing much, if any, change. This also means that the answer you find on internet for a particular programming query is going to work in almost all cases. Contrast this with most other languages where the programs need to make considerable changes to be able to run on a newer version.

 

Common Perceptions Examined

Being number 1, Java has been the reference point of any technology that comes up. The propaganda always targets Java, which is instrumental in creating certain perceptions around Java. Here we examine some popular ones of them.

Perception 1: Java is Slow

While this was indeed true once upon a time, it is no more a reality. Sun Microsystems created Java. They retained the ownership of Java specifications and not the product. (Anyone could create his own Java as long as it adhered to the Java specification.) Sun’s implementation of Java was meant to be a reference implementation of the specification, and initially they hardly cared how it performed.

But the users did, and so did the competition. Microsoft .Net, when it arrived on the scenes, showed benchmarks of being a few hundred times faster than Java. Sun had to take note as it lost thousands of developers crossing over to .Net. However, over the years, Sun’s engineers did a great job with the performance and made it blazingly fast — to the extent that in some benchmark studies, Java programs turned out to be faster than equivalent native programs (C/C++).

Perception 2: Java Hogs Memory

This is true to some extent. Every Java program needs JVM to run, which means that JVM has to be loaded into the memory for executing even the smallest of Java programs. For small programs, Java can be seen to load slower than an equivalent non-Java program.

However, once loaded, Java programs are fast enough. Also, on modern machines, the loading time is not very significant, so this is not a problem anymore.

But the JVM more than compensates for this on other fronts. Especially with multi-threaded applications (like web applications). Java’s web technology is superior to the CGI technology (typically employed by PHP, Perl and others) precisely because the JVM caches variables across requests and user sessions. Not only that, the bytecode can keep serving web requests after being loaded only once. This makes JVM based web applications not only fast but also more scalable (gracefully handling high load). Indeed, Java applications have reported performing under high load without degrading much, which is not possible with CGI applications.

Thus, while for small programs the JVM being loaded into memory degrades performance, for larger scale applications, the JVM makes more efficient use of resources and achieves a great performance and scalability.

Perception 3: Java is Verbose

This is true. Some modern languages have shown an impressive reduction in the number of lines of code by a factor of 4 or 5 from an equivalent Java program. Java’s verbosity comes from two reasons:

  1. Type declarations: Java’s static typing comes with a price that the developer has to specify this type at multiple places (just like in C/C++). With the advent of generics (which enhances the type system further), the types have become even longer,
  2. Boilerplate code: Classic example is the infamous getters and setters, or the exception handling

The verbosity is believed to affect negatively in three ways:

  1. Slow speed of development: We will talk about this more in the next perception
  2. More to maintain: The more the code, more is the maintenance effort.
  3. Developer preference: Experienced developers love to get more done with less code, and therefore they consider languages which deliver compact code as cool languages

However, note that verbosity is not completely bad. Java is certainly not extraneously verbose as something like COBOL. Java is verbose enough to make Java programs easily readable (which makes it easier for developers to understand code written by other developers). The languages which boast of impressive code compressions also tend to make the code obscure i.e. difficult to read. In a way, in a tradeoff between developer comfort and business needs, Java leans towards the later.

Perception 4: Developing a Java Application is Slow

This seems to be a natural fallout of several factors, but interestingly, there seem to be antidotes to each one of them.

Java development is slow because Antidote
Java is verbose Modern editors take up most of the heavy-lifting. They make use of static typing to intelligently suggest functions / variables to use, which is not possible with dynamically typed languages. Boilerplate code is generated by editors.
Java needs to be compiled. You save a PHP file (or any interpreted language for that matter), and the changes are available instantaneously. But in Java, you have to compile your source code first. Eclipse editor team (originally from IBM) came up with an incremental compiler using which a file is compiled in the background as soon as it is saved. This approach was later borrowed by other tools as well. Further, technologies such as JRebel are available to enable JVM to load the changed classes. The combined effect is equivalent to the PHP development.

Our experience suggests that once a developer is able to rise above these hurdles, she can be pretty close to a PHP developer in terms of productivity. However, in practice, most Java developers still spend more time in evaluating various alternative ways of implementation (this is because of the rich choice available) and refactoring the code (creating constants etc). However, these indicate more maturity and system thinking and the rewards are much higher than the amount of time spent in these activities. So this is not really a disadvantage.

 

Conclusion

To conclude, it would be a mistake to discard Java as yesteryear’s technology. Java is still highly relevant not only from the technology angle but also from the business angle.

Java is a business language. In a tradeoff between developer comfort and business needs, it tends to lean towards the later.

Java is strong in Web and Mobile, and a great choice for cross platform desktop applications. It has proven its mettle in terms of many industrial strength applications being written in Java over the years.

Post Tagged with , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *