Is it necessary to know Java before learning Scala?


#1

Is knowing Java a compulsory prerequisite before learning Scala as a beginner programmer having some experience with python and little bit of Java.


#2

I wouldn’t say it is required at all, though it is certainly true that the more knowledge you have about the JVM environment, the better off you are, but you will learn that as you go, whether or not you learn Java, Scala, or some other JVM language.

A number of resources are listed on the Scala Language site.

Atomic Scala is a book that sounds particularly relevant, though I haven’t tried it, so I can’t say how much your existing python knowledge might make the book boring.


#3

Language of Java-the-language isn’t useful at all for learning scala as it is in my opinion.

Some knowledge of the Java ecosystem can be useful, as there are Java libraries you can interop with for pretty much anything.

If you want to dive really deep, knowledge of the JVM may also be useful - unless you just want to do scala-js or scala-native.


#4

Scala’s beautiful… glad I’m trying it out…


#5

In my opinion, no it is not compulsory in itself.

Brett M. Gilio
B.S. Biological Sciences
B.M. Music Composition
http://www.brettgilio.com/

“Sometimes the obvious is the enemy of the true.”

  • G. Stolzenberg

#6

Hello,

You can learn Scala without knowing Java.

However, you most likely find yourself wanting to use the Java standard
library or other Java libraries, and those are documented using Java code
examples.

For example, in Scala, we use String, which is made accessible via
Predef.String http://www.scala-lang.org/api/2.12.4/scala/Predef$.html,
which is an alias for java.lang.String
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html, from the
Java standard library.

 Best, Oliver

#7

How long a Java person should take to start thinking/programming ‘Scala way(or functional way)’?
Take into account that person have to use Java in his/her day job.

Also, as Scala is quite big in terms of features, what features a Java person should really strive to master first?


#8

I don’t think that “how long” is really a measure of time here, but a measure of how much Scala code you have written and what things you have read. Your first Scala code is likely going to look like Java with less syntax. The more you write Scala, the more you should adopt a Scala style if you are also reading stuff to learn what the standard style of Scala is. You will have certain “Aha!” moments when you realize that you could write something in a much simpler way than you had been. How often you have those inevitably depends on who much Scala code you are writing and thinking about.

On what you should strive to master first, I would recommend higher-order methods in the collections library. Also, try really hard to not mutate things. These two will go hand in hand. The real advantage of learning the collections libraries and the higher-order methods is that you will see significant benefits in terms of your code being shorter and more readable. Those types of benefits provide the motivation to keep learning more.

I do a fair bit of competitive programming stuff and I love using Scala for HackerRank problems. A lot of them are very easily solved in a few lines with Scala collections. I will note though that I also erase all of their boilerplate code for reading input and write my own that does it in the Scala way, typically in 1/10th the number of lines.