adelbertc
adelbertc

Reputation: 7320

What should a Scala developer know about Java and/or the JVM?

So up until about 6 months ago, most of my work (big graph processing) consisted of Python and C++. Up to that point, and even now, I had not written any Java whatsoever.. I had seen the language and was familiar with the syntax (having come from a C/C++ background), and liked the idea of the JVM, but never actually written any substantial amount of Java.

When I picked up Scala, I loved it, OOP and functional programming features all in one, and it being on the JVM was great. I've been constantly striving to improve my Scala and have been playing with Akka, and still loving it. However, at times, perhaps it is just me overthinkng it, but I feel I should learn some more about Java and/or the JVM.

I've heard from many that Scala should be considered a separate language from Java, much like C++ to C. Perhaps you may feel the same way, and perhaps learning Java is more or less disjoint from learning Scala, but I'm feeling learning more about the JVM (e.g. JIT compilation, type erasure) would be helpful?

Thoughts?

Upvotes: 18

Views: 1165

Answers (6)

ziggystar
ziggystar

Reputation: 28690

  1. The JVM executes Bytecode and it is definately helpful to know how this works, just as it is sometimes helpful to know how C/C++ method invocations work or how classes are initialized; because sometimes it matters and cannot be abstracted away.

  2. Java is the prime language for the JVM, and it is helpful to be able to read Java to some extent if you need to use Java classes directly. And this may happen quite often; only a few examples:

    • you need to use some third party Java library (and there are tons)
    • working with Properties
    • you need to do something special in Swing which is not supported by the Scala-Swing wrapper
    • also sources explaining stuff for 1) will most probably use Java examples

But my advice is not to study it in advance - you'll pick it up when you need it.

Upvotes: 10

Gene T
Gene T

Reputation: 5176

Off top of my head

  • primitives, autoboxing, and how java arrays are special;

  • erasure and manifests

  • how logically tail recursive calls in scala source are compiled

  • installing -client, -server on your platform and when you want to try 32 bit: e.g. JAVA_HOME and "Java preferences" in OS X. I think openJDK should work anywhere you use same version of Oracle JDK, but IntelliJ warns you to use only official Oracle JDK. I've seen very isolated reports that 3d graphics libs have had problems with openJDK, and also parts of openJDK like the fonts have licensing issues.

  • setting classpaths in REPL, as compiler option, and in SBT

  • Hotspot switches, XMX, XMS (heap settings), most common garbage collectors, inlining method calls

  • java.util.concurrent

  • possible binary compatibility issues with java and scala code compiled in JDK 6 and 7.

Upvotes: 9

Brian Agnew
Brian Agnew

Reputation: 272297

There are a lot of tools surrounding the JVM. If you want to understand how your programs are running (for performance or other reasons) then it's worth being au fait with these. Two useful tools are:

  1. jstack
  2. visualvm

Both are particularly useful for monitoring and interrogating long-running processes.

Upvotes: 5

jamie
jamie

Reputation: 2161

Buy this book now: Java Performance. It was only released last October and is a treasure trove of information for anyone who wants to understand the JVM. If you're going to be a Scala developer, you must understand garbage collection and JVM runtime parameters at the very least.

Upvotes: 9

HamoriZ
HamoriZ

Reputation: 2438

I think you will know more about JVM when you program Scala. I mean you will have more questions like 'Why this solution is slow and that is fast?' - one way to answer this question is to check the bytecode

Upvotes: 1

mishadoff
mishadoff

Reputation: 10789

I don't know exactly what you need, but there are several similar questions on SO, look it.

Also, here good articles for Java Memory Model

My thought it's better to dig in Java language, write some code, read Java-specific books for better understanding how all things works.

Upvotes: 8

Related Questions