A short video introduction to the Scala REPL and variables

I didn't feel like going out in the rain and snow yesterday here in the Boulder, Colorado area, so I decided to stay indoors and create a video introduction to the Scala REPL and the Scala variable types, var and val. Without any further ado, here's the video:

How to enter multiline commands (statements) into the Scala REPL

When you want to test a multiline command/statement in the Scala REPL, you can easily run into a problem where the REPL gets confused, or more accurately, it attempts to evaluate your statement too early.

As a simple example of this, imagine that you want to test the Scala "if" statement syntax. You begin typing your if statement normally, but when you hit [Enter] after your second line, you'll see that everything blows up:

Scala REPL: How to show more methods on a class/object in the REPL alvin May 16, 2012 - 9:45am

When you're working in the Scala REPL and want to see what methods are available on a class/object, you can create an instance of an object, follow that with the "." character, and then press the [Tab] key. This process, known as "tab completion" in the REPL, gives you a preliminary list of methods that can be called on the object.

Here's what this looks like when we try it on an Int object:

How to show Scala String and StringOps methods in the REPL

Just a quick note here today on how to show methods from the String class in the Scala REPL, as well as methods from the StringOps class, which aren't seen as easily.

First, if you've used tab completion in the REPL, you may already know that you can show many String class methods in the REPL. If you hit the [Tab] key once you'll see a short list of String methods:

How to add a new jar file to the Scala REPL classpath (interactive command line)

Scala REPL FAQ: How do I add a Jar file to the Scala REPL classpath? (The Scala REPL is the interactive command line you get if you just type scala at your command line.)

To add a new jar file to the Scala REPL classpath (interactive command line classpath), use the :require command at the command line, like this:

scala> :require myjar.jar