Many of the available resources for learning Scala assume some background in Java. This can prove challenging for someone who is trying to learn Scala with no Java background.
What are some Java-isms a new Scala developer should know about as they learn the language?
For example, it's useful to know what a CLASSPATH is, what the java command line options are, etc...
The Advantages of Scala Scala has an exact syntax, eliminating boilerplate code. Programs written in Scala require less code than similar programs written in Java. It is both an object-oriented language and a functional language. This combination makes Scala the right choice for web development.
Hello, You can learn Scala without knowing Java. examples. Java standard library.
uses of Scala provides the best of both static and dynamic languages. It feels dynamic but is strongly statically typed language. Scala provides type inference for variables and functions, much better than limited type inference in Java and C#. It also provides a compiler that uses type reference to a full extent.
That's a really great question! I've never thought about people learning Java just so they have it easier to learn Scala...
Apart from all the basics like for
loops and such, learning Java Generics can be really helpful. The Scala equivalent is much more potent (and much harder to understand) than Java Generics. You might want to try to figure out where the limits of Java Generics are, and then in which cases Scala's type constructors can be used to overcome those limitations. At the more basic level, it is important to know why Generics are necessary, and how Java is a strongly typed language.
Java allows you to have multiple constructors for one class. This knowledge will be of no use when you learn Scala, because Scala has another way that allows you to offer several methods to create instances of a class. So, you'd rather not have a deep look into this Java concept.
Here are some concepts that differ very strongly between Java and Scala. So, if you learn the Java concepts and then later on want to learn the equivalent in Scala, you should be aware that the Scala equivalent differs so greatly from the Java version that a typical Java developer will have some difficulty to adapt to the Scala way of thinking. Still, it usually helps to first get used to the Java way, because it is usually simpler and easier to learn. I personally prefer to think of Java as the introductory course, and Scala is the pro version.
static
methods (Java) vs. singleton objects (Scala)for
loopsreturn
statement vs. Scala functional style ("every expression returns a value")null
for "no value" vs. Scala's more explicit Option
typeswitch
vs. Scala's match
And here is a list of stuff that you will probably use from the Java standard library, even if you develop in Scala:
And finally, some of Scala's features that have no direct equivalent in Java or the Java standard library:
for
comprehensionsfold
or map
Of course, all the lists are incomplete. That's just my view on what is important. I hope it helps.
And, by the way: You should definitely know about the class path and other JVM basics.
The standard library, above all else, because that's what Scala has most in common with Java.
You should also get a basic idea of Java's syntax, because a lot of books end up comparing something in Scala to something in Java. But other than the platform and some of the library, they're totally distinctive languages.
There are a few trivial conventions passed from one to the other (like command line options), but as you read books and tutorials on Scala you should pick those up as you go regardless of previous Java experience.
The serie "Scala for Java Refugees" can gives some indications on typical Java topics you are supposed to know and how they translate into Scala.
For instance, the very basic main()
Java function which translate into the Application
trait, once considered harmful, and now improved (for Scala 2.9 anyway).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With