An Intro to Scala and Sending Email in the JVM via SendGrid Yamil Asusta June 18, 2014 Technical // SUMMARIES ?> SendGrid and the Java Virtual Marketplace Are you a Java developer looking to use the Java Virtual Machine (JVM) in different ways like Clojure? If you’re looking into Scala, then this post might be able to help you out. Scala runs in the JVM. If you weren’t aware, all of your Java code can run in Scala. Pretty awesome, right? For example, the SendGrid JAR recently went through some major changes in order to make it more robust. You can use the old JAR as well as the new one because in the end, it all becomes bytecode for the JVM. Differences Between Java and Scala Let’s learn a bit about the difference in syntaxes when coming from Java and using the SendGrid JAR in order to, you know, send email. Importing the library in Java is as simple as: import com.sendgrid.*; Its Scala counter part is: import com.sendgrid._; Basically _ implies wildcard, while in Java it’s *. Also, in Scala, there is no need for semicolons. They’re completely optional. Instantiating SendGrid’s objects is quite similar. The one thing that changes is the fact that Scala has Type inference and there is no need to specify the type of the object. Check out the difference between the two: Java: SendGrid sg = new SendGrid("api_user", "api_key"); SendGrid.Email mail = new SendGrid.Email(); Scala: var sg = new SendGrid("api_user", "api_key"); var mail = new SendGrid.Email(); The rest is the same. If you want an Inmutable object, instantiate it using the keyword val. Another cool thing about Scala is that you can invoke methods using space instead of the usual dot notation. For example: sg.send(mail) // = sg send(mail) They’re completely equal. This is definitely not a comprehensive beginner guide, but I’d be super stoked to find out that it got you a bit interested in Scala. If so, give me a shout out @elbuo8 🙂 Big shout out to Jesus Luzon for the Scala class!