Ron’s Weblog

Mostly related to java, javascript and web development.

Java to Scala- some links

with one comment

Over the last few months, I’ve been trying to take out time to learn more about Scala – finding documentation and tutorials is hard ( specially if like me, you’ve 15 minutes a day to bite through your lunch when reading ). Wouldn’t a “Thinking in Scala” be nice?

Before diving into Scala, I would highly recommend learning more about functional programming. A great read is Functional Programming For The Rest of Us. This is a great introduction to functional programming, and IMO, a good place to start for those of us new to FP.
After this I’d recommend Roundup:Scala for Java Refugees.
This is a six-part series and I would read through all of them.It has great side-by-side examples of both Scala and equivalent(if any) Java code.

What’s great about Scala is the flexibility to structure your code intuitively. Reading an introductory article might not always make this obvious. As a quick example, (based on a similar one in Part 6), you could add a method to any class to save itself to the database (as opposed to looking up a DAO in your service code).

class Person(firstName: String, lastName: String) {
//simple person class
}
//define a Persistent Object
class PersistentObject(obj:Object) {
def save() {
// call a DAO etc println("Saving : "+obj)
}
}

//implicitly convert a POJO to a PersistentObject
implicit def pojo2persistent(obj:Object) = new PersistentObject(obj)
new Person("Ron","Francis").save()

Next on my list: Actors-The other concept probably new to Java programmers are Scala Actors. Actors provide Erlang style concurrency( or Message Passing concurrency, as opposed to Java’s shared state concurrency). Here is an actor tutorial . I haven’t explored this yet – but sounds promising. For example, here is an interesting blog about Scala Actors and comet

Written by Ron Francis

May 8, 2008 at 5:56 pm

Posted in Scala, java

Tagged with

One Response

Subscribe to comments with RSS.

  1. [...] você encontra mais links úteis, inclusive a série de artigos Roundup: Scala for Java Refugees, recomendado por Ron Francis para quem quer transitar de Java para Scala, um caminho suave segundo Joel [...]


Leave a Reply