example

A 'Ping Pong' Scala Akka actors example

Akka actors FAQ: Can you share an "Akka Actors 101" example (a simple "Introduction to Akka Actors" example)?

Sure. If you're looking for a really simple tutorial, check out my Akka Actors "Hello, world" tutorial. If that one is overly simplified and you want something more, continue on here.

A Scala case class copy method example

Scala case class FAQ: When you create a case class in Scala, a copy method is generated for your case class. What does this copy method do?

In short, it lets you make a copy of an object, where a "copy" is different than a clone, because with a copy you can change fields as desired during the copying process.

To demonstrate this, let's create an Employee class as a case class:

Scala Map examples - mapping month numbers to names

Nothing too earth shattering here today, but if you need an example of the Scala Map syntax (how to create a Scala Map), or just want to copy and paste a map of month names to numbers (or numbers to names), I hope the following code is helpful:

Creating Play Framework template functions (examples)

When you want to create a Play Framework template function, you can find some examples on the Scala Templates page. There you'll find these two examples.

First, assuming you have a Product model defined something like this:

case class Product(var name: String, var price: BigDecimal)

The first template looks like this:

The Factory Pattern in Scala

While working on a new Scala application recently, the alarms started going off in my head, saying "You need to use the Factory Pattern here." That's when things got interesting.

Just exactly how do you implement the Factory Pattern in Scala?

Here's a simple, quick example.

(1) The interface

Sparing you all the experiments I went through, let's assume you want a factory that produces animals like this:

Scala - How to rename a class when you import it (a 'rename on import' syntax example)

Scala offers a cool feature where you can rename a class when you import it, including both Scala and Java classes. The basic syntax to rename a class on import looks like this:

import scala.collection.mutable.{Map => MMap}

and this:

import java.util.{HashMap => JavaMap}

If all you needed to know, I hope those "rename on import" syntax examples were helpful.

Why rename a class on import?

An interesting question is, "Why would I want to rename a class on import?"

A simple Java Generics example class

To take a break from a project I was working on yesterday I gave my brain a little exercise to see if I could remember how to create a Java class that used the Java 5 Generics magic. Since I've used Scala a lot recently, I decided to create a Java version of the Scala Tuple class.

The Tuple class simply stores two values, which are often key/value pairs. Beginning with the end in mind, here's how you typically use a Tuple:

Source code for an example Android 'send email' function/method

Android FAQ: Can you share some source code for an Android send email method?

If you need a simple Android 'send email' function/method, this source code should do the trick for you:

A simple Scala JSON parser example using Lift-JSON

Scala JSON FAQ: How can I parse JSON text or a JSON document with Scala?

As I continue to plug away on my computer voice control application (SARAH), last night I started working with JSON, specifically the Lift-JSON library (part of the Lift Framework), which seems to be the preferred JSON library of the Scala community.

MySQL backup - How to backup a MySQL database

MySQL backup FAQ: How do I back up a MySQL database?

I can't speak about backing up MySQL databases that are modified twenty-four hours a day seven days a week, but on all the MySQL databases I currently work with, there are always times when I can guarantee that there won't be any SQL INSERTs, DELETEs, or UPDATEs occurring, so I find it's really easy to perform a MySQL backup using the mysqldump utility program. Here's how it works.

Syndicate content