Why Java Is Still Relevant
Or why it’s not a bad idea learning it even if you hate it
(migrated from https://medium.com/i-m-h-o/da3b2c180e9c)
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:
1. X uses it (where X = Google, Amazon, Square etc…) #
Google is using Java widely, and contributed a lot to the ecosystem (Google [Guava][1], [GWT][2], [Guice][3] 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][4]. [Some known startups also use Java as their main stack such as Square, Yammer etc][5].
Knowing Java will probably be considered a benefit if you want to work for any of these companies, and many others.
2. It’s not your grandmother’s Java anymore #
From Java 8, you’ll be able to use [lambda expressions][6], (and many more cool features) 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. It was just recently released, and has great IDE support (NetBeans, Intellij and Eclipse)
3. 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][7] to [Heroku Java][8] 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][9])
4. Android development #
Although you can write Android apps with [Scala][10] or even [Clojure][11] (and probably other JVM languages), the main language is still Java. If you want to be an Android developer, Java is pretty much mandatory.
5. 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%2B%2B, JavaScript, (and perhaps Python as well) is going to be useful no matter what is your favorite “go-to” language.
6. It’s fast (er than Ruby / Python / JavaScript) #
Java might not be the fastest, but it’s [pretty fast][12] compared to other JIT compiled languages. Specifically for web development (e.g. Servlets), its performance is [on the same level as C][13].
It is much faster than dynamic languages such as Ruby and Python.
7. 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)
8. Spring has improved #
The notorious [Spring][14] with its [AbstractSingletonProxyFactoryBean][15] which was described as “[everything that’s wrong with Java in a single class][16]” 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{
@Query(“from user where firstName = ?1")
List findByFirstName(String name);
}
Controller
Automatic JSON serialization with [Jackson][17], 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.
9. You can use it side by side with Scala / Clojure / JRuby / Jython #
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.
10. 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][18], business casual dress code, [waterfall ][19]and [SDLC][20], 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][21]”, “[pimp my library][22]”, 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.
11. 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][23] / Google [Guava][1], you’ll find that most of the things that are annoyingly missing in Java are to be found there. ([here][24] 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%2B1, or in IDEA press alt%2BEnter / ctrl%2BJ 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.
- Use project lombok to avoid boilerplate code
12. 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][25] for example, you might want learn Java.
[1]: https://code.google.com/p/guava-libraries/
[2]: https://developers.google.com/web-toolkit/
[3]: https://code.google.com/p/google-guice/
[4]: http://www.quora.com/What-kind-of-companies-use-Java-as-their-primary-language-in-software-development
[5]: http://www.quora.com/What-are-the-most-interesting-startups-that-use-Java-for-their-platform
[6]: http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
[7]: http://aws.amazon.com/elasticbeanstalk/
[8]: http://java.heroku.com/
[9]: https://blog.heroku.com/archives/2011/8/25/java
[10]: http://scala-ide.org/docs/tutorials/androiddevelopment/index.html
[11]: http://nightweb.net/blog/clojure-on-android.html
[12]: http://en.wikipedia.org/wiki/Java_performance#Comparison_to_other_languages
[13]: http://www.techempower.com/benchmarks/
[14]: http://www.springsource.org/spring-framework
[15]: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html
[16]: https://plus.google.com/%2Baerotwist/posts/1QhcnQizuPc
[17]: http://jackson.codehaus.org/
[18]: http://en.wikipedia.org/wiki/Big_Design_Up_Front
[19]: http://en.wikipedia.org/wiki/Waterfall_model
[20]: http://en.wikipedia.org/wiki/Software_development_life_cycle
[21]: http://java.dzone.com/articles/duck-typing-scala-structural
[22]: http://alvinalexander.com/scala/scala-2.10-implicit-class-example
[23]: http://commons.apache.org/
[24]: http://codemunchies.com/2009/10/beautiful-code-with-google-collections-guava-and-static-imports-part-1/
[25]: http://hadoop.apache.org/