Ask HN: Is it worth to study languages on the JVM without knowing Java?

15 points by oscardelben ↗ HN
I've recently began looking at languages built on the JVM like Clojure and Scala.

I come from a Ruby background mostly, but I deeply appreciate languages like scheme, and even Erlang.

The thing is that both Clojure and Scala assumes that you know Java to get the most out of it. For example in the Scala book from the pragprog, the author says that if you are not experienced with Java, you should complement your study with several Java books.

The fact is that I don't think it's worth for me to learn Java, so I wonder if learning any of these JVM languages is worth it.

26 comments

[ 3.8 ms ] story [ 72.7 ms ] thread
My guess is that it's something similar to knowing Ruby, Python, Tcl, etc... without knowing C. You can certainly get by and even be very productive, but if you want to do deep hacking, or library integration, you're going to need some Java at some point. Over time, it will probably be less necessary.
> library integration

Presumably the whole point of using a language that runs on the JVM is that you can use libraries written in Java.

In an ideal world, you should be able to use libraries written in any jvm-based language. It seems to me this isn't easily possible today with most jvm-based languages but maybe I'm wrong.
Yes, but Java is the middle-man providing the FFI, and implementing bindings to whatever library written in whatever language on top of the JVM is a lot easier. And it will get a lot more easier with the upcoming invokedynamic support (since right now the reflection mechanisms for calling methods are very slow).

Attila Szegedi is also working on a MOP for dynamic languages, which, if integrated by language designers, will make it possible to instantiate classes and call methods from modules written in other languages (much like the DLR, but with a different architecture) ... see here ... http://dynalang.sourceforge.net/

In an ideal world the would be no need for Java being the middle-man.

That project was founded in 2007. The last release is from 2008. Has anybody ever adopted it?

> In an ideal world the would be no need for Java being the middle-man.

Not possible, ideal world or not.

Programming languages have different type-systems. First of all you can't have the VM optimize for all of them, so the priority is always the primary language (Java for the JVM, or C# for .NET).

The second problem is that those type-systems have behaviors defined either at compile-time, or at runtime.

For instance, in Haskell a method is resolved / specialized on the use-site (based on the arguments provided) at compile-time, since by design, all types are known. If you call that same method from Java, you can't use the same interface ... you'll probably call a proxy, that based on the types provided (at runtime this time) it would find the right method and call it (with a call-site cache to optimize future calls).

Another example ... Common Lisp has multi-dispatching. It makes sense for Lisp, but not so much for Ruby. And Java has single-dispatching too. Simulating multi-dispatching on top of the JVM is not easy (it will be easier with invokedynamic and MethodHandles) ... and even if some kind of multi-dispatching was implemented, which one? Asymmetric or symmetric?

The only way to communicate with a language efficiently is trough the standardization of a MOP. But that's also hard to define because of the same reasons ... the author of IronScheme for example was considering dropping support for the DLR because it wasn't a good match.

Progress is going slowly since every

That project was founded in 2007. The last release is from 2008. Has anybody ever adopted it?

If you'll look at the repository, there are regular commits. I'm following the "JVM languages" google group, and the author is communicating regularly with people like John Rose (JVM / invokedynamic) and Charles Oliver Nutter (JRuby) among others, getting feedback, providing feedback, and Charles even attempted an integration of JRuby at some point. I don't really know the state of that.

In the case of such a project you have to please everyone, being a complicated matter from both a political and technical point of view.

If you are truly interested in such things, you can always scratch your own itch ;)

I wouldn't say "not possible". Interoperability between java and groovy is quite good. It's to some degree true for clojure and scala -- two languages I haven't used myself yet. There are example snippets around in the Internet that demonstrate that a combination of groovy/scala/clojure/jruby is possible. So the situation isn't that bad.
Ok, but to create a wrapper for the Java library, you probably need to grok Java enough to read the documentation and create some code that sits on top of it.
With JRuby (and I think scala and clojure as well) you only need to know the API and how to get the class or jar file onto you load path.

There are times when a Java method demands a specific Java type and JRuby does not automatically convert correctly, but mostly the use of Java libs from JRuby is pretty trivial, and the only time I've had to write Java to wrap anything was when I wanted a nicer API for some 3rd-party crypto libs and adding a few methods to the Java source was easier for me.

Regardless of whether it's necessary or not, it's kind of expected knowledge to have as a programmer. Around here you'll find a lot more anti-Java sentiment than in most places (and most of it is probably justified), but I still doubt you could find many expert hackers here that don't know how to code Java. Everyone hates it because everyone has to use it from time to time, kind of like C.

At the moment, the ten most popular languages are (according to http://www.tiobe.com/index.php/content/paperinfo/tpci/index.... and whatever metric they use):

1) Java

2) C

3) PHP

4) C++

5) (Visual) Basic

6) C#

7) Python

8) Perl

9) JavaScript

10) Ruby

Given that Java is #1 on that list, I'd find it hard to call some time spent learning it wasted, you're just going to run across it too much, at conferences, in papers, in code that you inherit, in libraries you have to interact with or debug, etc.

Besides, if you know C or C++ it won't take very long to learn the syntax, and the libraries are worth learning because you'll use them in any JVM language anyways. If you don't know C/C++...well, um, add another one to your list, every programmer should have at least a basic understanding of some flavor of C for the same reasons they should know some Java.

If you do start with Java, make sure you actually use Java tools for the job, though, at least once you have the basics down; if you're coding Java in a text editor, even a good one, you're making things far more difficult than they need to be, because it's a language where tools are absolutely crucial if you don't want to drive yourself crazy. Whether it's Eclipse, Netbeans, or IntelliJ, you haven't really learned Java if you haven't learned how to use one of them well.

Errm... if you're going to quote me programming language statistics, please use my own: they're better than TIOBE's:-)

http://www.langpop.com

I agree though, that a cursory knowledge of Java is probably helpful in this day and age.

What do you mean by "knowing java"? Learning the language syntax will take you a couple hours at most (if you already know e.g. python or ruby).
I mean being familiar with the api, and thinking in java when something is not possible to do with the language.
The JDK is where a lot of the power of running on the Java platform comes from. It is an enormous library and you will never know it all thoroughly. It will, however, definitely be worth your while learning the parts most relevant to you.
Java really isn't that difficult (I assume that you know OOP, otherwise you might need to study that first), there isn't that much to it (in fact Java is pretty famous for not having much syntactic sugar).

What you will properly need to learn to use is the class hierarchy, Swing programming (if you want GUIs, you should take a look at MIGLayout) and the classpath (which you will have to deal with, regretfully).

What you need to know of Java in order to use the libraries with Clojure and Scala can be picked up as necessary while you are learning those languages. Depending on your field and interest, though, it can't hurt to know Java anyway.
JVM languages bootstrapped themselves from Java and for integration sooner-or-later you will run into situations where you must understand the underlying concepts. For example, writing web apps requires you to understand Servlets which is Java based. I come from Java background, have coded in Clojure and I speak from experience - you should learn Java if you are going to be on the JVM.
You can get by without having to learn much directly about Java - just by picking bits and pieces up as you need them. But the value in learning the underlying platform, and indeed a key reason why these languages target the platform, is the wealth of libraries available.

The question is really if it is worth writing your own libraries from scratch as opposed to learning and using the vast amount of (usually commercially-friendly licensed open source) code that is already out there. Most of the time this is a pretty simple choice.

It depends on the level of proficiency you want to gain in Clojure and Scala.

At this point in time,to make the most of either language and to develop a "real" application you should know Java and not just Java but the tool, library and the infrastructure support of the Java ecosystem that comes with it.

Having said that, if you just want to "learn" the language i.e. the Type System, really grok STM , the API's and how to do something in it - then there can be no better substitute than to start building the libraries,tools etc. that do not exist in Clojure and Scala. Pick up something that you currently can't do in Scala without dropping into Java and build it. Of course this is not an easy undertaking but you will learn lots.

Approach it like you're probably approaching learning the actual language you are interested in (Scala/Clojure): you learn a bit, write some code, find a gap in your knowledge, learn what you need to know to fill that gap, write more code etc. i.e. bootstrap
I knew nothing of the Java API's but am able to use Clojure quite successfully. There are oodles of Java API documents and discussions online. I also use several Apache projects from Clojure, and haven't had too much trouble getting to know how to interface with them.
The JVM is a platform, much like x86/linux or PPC/mac. It's always advantageous to have a better understanding of the platform your code will be working on, but it's not strictly required to be an effective programmer.

With that aside, I think it's certainly worthwhile to take the time and get a basic understanding of Java, as well as survey what is available in terms of libraries (both standard and 3rd party libraries). Some of the biggest appeal of these languages comes from the fact that they're able to leverage all this existing Java code.

http://mitpress.mit.edu/sicp/ You should check this book out and contemplate the generalities of programming languages. Java is the most popular example of a whole class of programming languages - object oriented, automatic garbage collection, no lambda functions :[, single inheritance, runs in a VM etc. etc. If you know C++ really well then moving to Java is easy and if you know Java really well then moving to C# is easy etc. There's no reason to hate on Java just because it's not sexy anymore. Also, there are a hell of a lot of libraries already written in Java and a hell of a lot of jobs for Java programmers out there.
Having gone from Ruby to JRuby, I think it's worth learning enough Java so you can truly benefit from the JVM platform. You may not write much Java, but you'll want to use all the wonderful libraries available to you.

I do, however, know C++ well so Java isn't much of a problem. But it's not a difficult language, especially as it's designed to stop people making mistakes. (!)