Installing Scala on Linux

The following Scala installation steps are tested on my CrunchBang Linux 11 “Waldorf” machine.

  1. Java Environment Check:
    Scala requires the Java runtime version 1.6 or later. So before you install Scala, first make sure that you Java environment is set up correctly.

    1. To test your Java runtime environment, type java -version at your command prompt and press ENTER. If your Java environment is set up correctly, you should see something like the following:

      ~$ java -version
      OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-2~deb7u1)
      OpenJDK Client VM (build 24.65-b04, mixed mode, sharing)
    2. Test to see that the Java compiler is properly installed. Type javac -version. You should see the compiler version if the compiler is found.

      ~$ javac -version
      javac 1.7.0_65
  2. Scala Setup:
    1. Download Scala from The version I downloaded is Scala 2.11.4. You can get the binaries in tgz, deb, rpm, msi, or zip format depending on your preference and platform. I had chosen the tgz format for my installation.
    2. Unarchive the Scala binaries to a directory of your choice. I unachrive the downloaded file in my local bin directory.
      ~$ cd ~/bin
      ~/bin$ tar -zxvf ~/share/downloads/scala-2.11.4.tgz

      At this point, you can Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived, or tart the Scala compiler by launching scalac from the same location.

    3. Set Path and Environment. For quick access, add scala and scalac to your path. I do so by adding the following lines to the end of my ~/.bashrc file.
      export SCALA_HOME=~/bin/scala-2.11.4
      export PATH=$PATH:$SCALA_HOME/bin

      After this either open a new terminal window to activate the two new environmental variables, or reload your ~/.bashrc script with

      source ~/.bashrc
  3. Test Your Scala Installation:
    Type scala -version, and scalac -version at the command prompt to test your Scala environment. You should see something like the following:

    ~$ scala -version
    Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
    ~$ scalac -version
    Scala compiler version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
  4. Let’s try a simple command in the REPL. Invoke the REPL by typing scala, and enter the println command to say hello to your Scala installation. You can enter :help to find out more about the commands available in the REPL. Type in :q to quit the REPL when you are done.
    ~$ scala
    Welcome to Scala version 2.11.4 (OpenJDK Client VM, Java 1.7.0_65).
    Type in expressions to have them evaluated.
    Type :help for more information.
    scala> println("Hello, Scala!")
    Hello, Scala!
    scala> :q

Java Primitive Data Types

Type Length Range
byte 8-bit signed two’s complement integer. minimum: -128; maximum: 127 (inclusive)
short 16-bit signed two’s complement integer. minimum: -32,768; maximum: 127 (inclusive)
int 32-bit signed two’s complement integer.
in Java 8 and later: int can represent an unsigned 32-bit integer.
signed — minimum: -231; maximum: 231-1 (inclusive)
unsigned — minimum: 0; maximum: 232-1
long 64-bit signed two’s complement integer.
in Java 8 and later: int can represent an unsigned 64-bit integer.
signed — minimum: -263; maximum: 263-1 (inclusive)
unsigned — minimum: 0; maximum: 264-1
float single-precision 32-bit IEEE 754 floating point. See Java Language Specification. Don’t use for precise values, such as currency.
double single-precision 64-bit IEEE 754 floating point. See Java Language Specification. Don’t use for precise values, such as currency.
boolean not precisely defined true and false
char single 16-bit Unicode character minimum: '\u0000' (0); maximum: '\uffff' (65,535) inclusive
Data Type Default Value
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
boolean false
char '\u0000'
String (or any object) null

Java Language Keywords — A’s (2)

Keywords: abstract, assert


As a class modifier, abstract is a nonaccess modifier that declares a class which cannot be instantiated. You cannot create an object from abstract classes. However, you can create subclasses from abstract classes by extending them. An abstract class may or may not include abstract methods. If a class includes abstract methods, the class itself must be declared abstract. When a subclass does not provide all of the abstract methods in its parent class, the subclass must also be declared abstract.

As a method modifier, abstract declares a method that must be implemented by a subclass. The first concrete (not abstract) subclass must implement all abstract methods of the superclass. Abstract methods cannot have the modifiers final or private because subclasses need to access the methods in order to implement them.

It is a compile-time error if a abstract method declaration also contains any one of the keywords private, static, final, native, strictfp, or synchronized.

An abstract method is declared without an implementation. In other words, without braces, and followed by a semicolon, as in the following example code:

public abstract class Shape {
  int x, y;
  void moveTo(int x, int y) {
  } // moveTo(int, int)

  abstract void draw();
  abstract void scale(int factor);
} // class Shape

Then each concrete subclass of Shape, such as Circle and Triangle, must implement the draw and scale methods:

class Circle extends Shape {
  void draw() {
  } // draw()

  void scale(int factor) {
  } // scale(int)
} // class Circle

class Triangle extends Shape {
  void draw() {
  } // draw()

  void scale(int factor) {
  } // scale(int)
} // class Triangle

Abstract class provide default functionality for the subclasses, whereas an interface mandates a list of functions or properties. So, objects that extends an abstract class “Is-A” subclass; objects that implement an interface “Must-Do” the functions, or “Must-Have” the constants or nested types of the interface.

If an abstract class contains only abstract method declarations, it should be declared as an interface instead. Still, keep in mind that when you make a change to an abstract class all of the subclasses will now have this new functionality. On the other hand, once an interface is changed, any class that implements it that will be broken.

[awaiting definition note]

Java Language Keywords (overview)

So I’m trying to memorize the list of keywords in the Java programming language. You cannot use any of them as identifiers in your code. true, false, and null are not keywords. They are actually literals. Likewise, you cannot use them as identifiers in your code.

abstract assert boolean break byte
case catch char class const*
continue default do double else
enum extends final finally float
for goto* if implements import
instanceof int interface long native
new package private protected public
return short static strictfp super
switch synchronized this throw throws
transient try void volatile while

* reserved, currently not used

So, in all, there are 50 keywords to remember. To make it easier for myself I’ll study them in alphabetical group (i.e. 2 start with a; 3 start with b; 6 start with c; etc.).

Next, the A’s →