File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Scala and the fly likes  Scalatra in Action, The Well-Grounded Java Developer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Scala
Bookmark " Scalatra in Action, The Well-Grounded Java Developer" Watch " Scalatra in Action, The Well-Grounded Java Developer" New topic
Author

Scalatra in Action, The Well-Grounded Java Developer

paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 169

Hi ,
How transferable are Java skills to Scala ?
For example, does Scala use the same libraries and classes?

Thanks,
Paul
Brian Hanafee
Greenhorn

Joined: Jan 31, 2013
Posts: 7

Second question first: Yes! You can use any of the Java libraries. Interoperability is definitely a strength. Once you try using the Scala collections library, you probably won't want to use the Java collections, but it's all there. Many of my Scala projects have long lists of Java library dependencies (Joda time, for example). Importing a Java class or interface is really no different than importing a Scala class or trait, except of course Scala-specific features aren't available. It's also quite easy to create Scala objects that extend or implement Java classes and interfaces.

The answer to your first question is also yes, Java skills are transferable to Scala. That's a double-edged sword. You can make your Scala feel and behave like it's just a syntacticly different version of Java, and apply the same OO design principles as you would in a Java environment. It'll work fine, and your productivity in Scala will quickly become on-par with your productivity in Java. The other answer to your first question is no, Java skills are not helpful (and in some ways detrimental) to using Scala as a functional language. It's a very different mindset, but it's also where some of the bigger gains in productivity are to be found. The temptation to do something the Java way can be hard to overcome and think through a functional solution. I highly recommend taking Martin Odersky's class and really pushing yourself to develop functional skills to complement your OO skills.


Edit: typo and implement java interfaces rather than objects
paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 169
Hi,
Thank you for the tips.
The flexibility sounds great but your right ,it doesn't make sense to use a new language to mimic an existing one.
Thanks,
Paul
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Brian Hanafee wrote:

The answer to your first question is also yes, Java skills are transferable to Scala. That's a double-edged sword. You can make your Scala feel and behave like it's just a syntacticly different version of Java, and apply the same OO design principles as you would in a Java environment. It'll work fine, and your productivity in Scala will quickly become on-par with your productivity in Java. The other answer to your first question is no, Java skills are not helpful (and in some ways detrimental) to using Scala as a functional language. It's a very different mindset, but it's also where some of the bigger gains in productivity are to be found. The temptation to do something the Java way can be hard to overcome and think through a functional solution. I highly recommend taking Martin Odersky's class and really pushing yourself to develop functional skills to complement your OO skills.


Edit: typo and implement java interfaces rather than objects


If I think about it, my java skills which are imperative by the way is definitely not advisable to be transferable to Scala style of functional programming. All I can take from Java are just the libraries.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
paul nisset
Ranch Hand

Joined: May 13, 2009
Posts: 169
That's good to know. It will probably save many hours fitting a square peg in a round hole.
Brian Hanafee
Greenhorn

Joined: Jan 31, 2013
Posts: 7

Joe Harry wrote:If I think about it, my java skills which are imperative by the way is definitely not advisable to be transferable to Scala style of functional programming. All I can take from Java are just the libraries.


That might be a little extreme. There are times when an OO approach does make sense. Scala blends them, so you can have it both ways. Try to find a functional solution first, but keep OO approaches in your toolbox. Many of the OO solutions in Scala are an improvement over their Java counterparts, resulting in less code to implement the same or more functionality. Traits, for example, are an OO solution that combines benefits of Java interfaces and Java abstract classes. Getter/setter pairs are completely unnecessary. Scala also has real closures rather than the broken inner class concept. The result is that many of the GoF patterns become invisible parts of the language that just work rather than tedious boilerplate. Also the type system (abstract types, variance/contra-variance notations, etc.) moves much more of the type checking from the runtime to the compiler where it belongs, so that more powerful libraries can be created without sacrificing correctness.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Scalatra in Action, The Well-Grounded Java Developer