Why Java Is Still Relevant
Or why it’s not a bad idea learning it even if you hate it
Java is probably one of the most “love to hate” languages out there. According to this HN poll it is the 2nd most hated language among the poll participants (statistically insignificant, but still noteworthy), only 2 points behind PHP. Certainly not a great place to be.
There are many reasons why not to like Java, but there are also quite a few good reasons to learn it, even if you don’t like it. Actually there is an increasing number of reasons to start trying to like it again, or at least to hate it less.
So here are a few reasons why I think Java is still relevant for learning:
X uses it (where X = Google, Amazon, Square etc…)
Google is using Java widely, and contributed a lot to the ecosystem (Google Guava, GWT, Guice etc). So if you want to work for Google, knowing Java will not be a hindrance.
The same applies for other big names, such as Amazon, Netflix, EBay, Linkedin etc. Some known startups also use Java as their main stack such as Square, Yammer etc.
Knowing Java will probably be considered a benefit if you want to work for any of these companies, and many others.
It’s not your grandmother’s Java anymore
From Java 8, you’ll be able to use lambda expressions, for example:
Stream.of(1, 2, 3, 4, 5, 6, 7)
.map(x -> x * x).filter(x -> x % 2 == 0)
.reduce(0, (sum, x) -> sum + x);
Yep, this is Java above. Coming soon to a theater near you.
Hosting it is not as bad as it was few years ago
I believe that hosting costs and lack of hosting options for Java apps were a major drawback in the past.
This is not the case for some time now: from Amazon Elastic Beanstalk to Heroku Java to Google app engine it is as easy to deploy a Java Servlet / Spring application as it is to type:
$ git push heroku master
(well, almost)
Android development
Although you can write Android apps with Scala or even Clojure (and probably other JVM languages), the main language is still Java. If you want to be an Android developer, Java is pretty much mandatory.
You’ll probably end up needing to read it
Although this argument holds true for many other languages, it is doubly so for Java. You are very likely to encounter Java during your career as a developer: in open source code, in code written by a coworker / collaborator, in academic books, usage examples etc.). Knowing Java, C / C++, JavaScript, (and perhaps Python as well) is going to be useful no matter what is your favorite “go-to” language.
It’s fast (er than Ruby / Python / JavaScript)
Java might not be the fastest, but it’s pretty fast compared to other JIT compiled languages. Specifically for web development (e.g. Servlets), its performance is on the same level as C.
It is much faster than dynamic languages such as Ruby and Python.
The JVM is pretty awesome
Many admit that as much as Java is not much fun to write code with, the JVM is a different story. Great garbage collection, thread management, monitoring and debugging services, make it a great target for many languages (Clojure, Scala, Groovy, JRuby, Jython etc)
Spring has improved
The notorious Spring with its AbstractSingletonProxyFactoryBean which was described as “everything that’s wrong with Java in a single class” has gone a long road and was influenced by other frameworks (such as Rails). It can be quite decent for writing web apps. For example:
Model
CRUD operations are implicit, and you can add custom ones as needed
@Transactional
public interface UserRepository extends JpaRepository<User, Long>{
@Query(“from user where firstName = ?1")
List<User> findByFirstName(String name);
}
Controller
Automatic JSON serialization with Jackson, calling implicit “findOne”
@Controller
public class UserController {
@Autowired private UserRepository userRepository;
@RequestMapping(value=“/users/{id}”, method=RequestMethod.GET)
public @ResponseBody User getUser(@PathVariable(“id”) Long id) {
return userRepository.findOne(userId);
}
}
No huge XML files (well, some XML required, but just to turn on the Annotations mode). Perhaps it’s still not as productive or as elegant as Rails, Django, Node, or even Play framework, but it had come a long way since the “dark days” and it can almost be fun again to write applications with.
You can use it side by side with Scala
For my part, I think Scala is indeed “a better Java”.
Twitter, Yammer, Foursquare and numerous other startups have chosen it as a central part of their development strategy, due to its expressiveness, relative performance, and development productivity.
Scala shares the Java Technology Stack, and knowing Java is a big plus when learning Scala, especially due to the common library ecosystem, and the insights into the JVM workings.
Enterprises still use it
It is not something I have hard data on, but we can safely assume that it is not the first preference of hackers to go and work for a gray old enterprise. With it’s BDUF, business casual dress code, waterfall and SDLC, cubicles, old school management style, Lenovo laptops, and windows software, and no sight of technological innovation.
As much as this might seem the case in many enterprises, there is always a little bit more to the truth than the stigma. Software Engineers (this is how the enterprise hackers like to call themselves) in big companies like HP, Oracle, SAP, IBM and many other smaller enterprise software vendors have some really interesting problems to solve, and they are using really interesting technologies to solve them. If you know it well, JEE 6, Spring, ESBs, CXF, SOA, JPA and other Enterprise Java technologies are not all 100% pure evil and over-complicated bloatware. There are very interesting technologies, and the DRY / Rails world had major impact on the way things can be done in boring old Java. from Grails (a rails knock off), to Roo (as well, but with less magic) - both of which are based on the notorious Spring framework, to Play framework (Scala based rails inspired web framework), or Lift that with Scala’s expressive power can allow you to do dynamic languages tricks like “duck typing”, “pimp my library”, and more. Spring MVC is not too terrible as well if you get to know it, and you can create pretty impressive light weight web apps with as much ease as you would with Rails, Django or Node.js.
So whether you want to disrupt an enterprise industry, do a banking startup for example, or if you are looking to extend your possible job pool, then Java is not a waste of time.
It can be productive
One key argument for Ruby and Python is that even though they are admittedly slower in run-time, the developer productivity is so much higher, that it pays for whatever cost the performance issues claim, with lots of dividends. In other words, you save so much money on development happiness and productivity, that you’ll be able to spend it on scaling out and up, and still have change (if you actually make money from the code written). However Java is not that unproductive if you take some simple steps to boost developer productivity in Java.
- Use Apache commons / Google Guava, you’ll find that most of the things that are annoyingly missing in Java are to be found there. (here are some examples)
- Give up and use an IDE. Writing Java in VIM, Emacs, Sublime Text 2 etc. can be done, but let’s face it, the one nice thing about Java (and statically typed languages) is that you can have auto completion, automatic refactoring etc. With its fast compilation, using tools like Eclipse you don’t even feel it (it does a differential compilation on save) and if you don’t like Eclipse (it’s great but might have “some” performance aspects of using it…) then spend those dollars and get yourself an Intellij IDEA, it’s fast, has a great JavaScript, Ruby, Python support, and top notch Java / Scala support. How does it save you time? you simply write less code, in eclipse press ctrl+1, or in IDEA press alt+Enter / ctrl+J and you’ll see you are writing less and less code, and more modeling code to fit your goals. It might be a downside for some people, but you can always go back and write Java in notepad if you want the language to “fit in your head”.
- Switch / combine with Scala. You’ll have fun coding again.
Open Source community
Although it’s losing its glamour in favor of Ruby, JavaScript and Python, Java is still a relevant member of the open source community. If you want to contribute to Hadoop for example, you might learn Java.
Job openings
Perhaps the weakest argument for Java, but still a valid one, is that there are a lot of Java openings out there, so knowing Java will not hurt.
Conclusion
Java is still around, live and kicking, and still evolving. Writing it off completely as obsolete is not something that will benefit any developer. You don’t have to like it in order to learn it, but there are more and more reasons that help you even like it a little.
Also sometimes knowing how things are done the wrong way might help you know how to do it right.
You should follow me on twitter here
Edit: see the discussion on hacker news (thanks for the great feedback!)