More on Scala Tutorials

(We marked visited pages blue)
  • Introduction to Scala Programming
  • Scala Programming Basic Syntax

    In our last post we have made a short introduction into Scala and we managed to write our first Scala piece of code - Introduction to Scala Programming.

    In this tutorial we will focus on Scala Programming Syntax.

    So what do we need to know about Scala coding syntax ? 
    • Scala is case-sensitive, which means identifier AODBA and aodba would have different meaning in Scala.
    • All method names should start with a Lower Case letter. If multiple words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
    Example :
    • All class names, the first letter should be in Upper Case.
    class MyScalaScalaClass;
    • Scala program processing starts from the main() method which is a mandatory part of every Scala Program.
    • Program File Name − Name of the program file should exactly match the object name. When saving the file you should save it using the object name and append .scala to the end of the name.

    Scala identifiers

        All Scala components require names. Names used for objects, classes, variables and methods are called identifiers. A keyword cannot be used as an identifier and identifiers are case-sensitive. Scala supports four types of identifiers. Scala supports four types of identifiers: Alphanumeric Identifiers
    • all alphanumeric identifier that starts with a letter or an underscore, which can be followed by further letters, digits, or underscores can be used as Identifiers. The '$' character is a reserved keyword in Scala and should not be used in identifiers.
    name,  _name,  __1name,   _1_name
    bad eg:
    123name, $name
    Operator Identifiers
    •   like the name states this are operators such as ( +, :, ?, ~ or #)
    Mixed Identifiers
    • consists of an alphanumeric identifier, which is followed by an underscore and an operator identifier.
    Literal Identifiers
    • is an arbitrary string enclosed in back ticks ( . . . ).

    Comments in Scala

        Single-line and multi-line comments very similar to Java. Multi-line comments may be nested, but are required to be properly nested. All characters available inside any comment are ignored by Scala compiler. Single line
    // Single Line Comment
    Multi line 
    /* Multiple 
      * Line
    /* Comments

    Newline in Scala

        In Scala semicolon at the end of a statement is optional unless you wanna write multiple command on the same line. eg: 
    val name = "aodba"; println(name)

    Scala Packages

        A package is a special object which defines a set of member classes, objects and packages. Scala packages can be imported so that they can be referenced in the current compilation scope. To import a package use the syntax bellow:
    import scala.short._
    • this will import the entire content of the short package.
    Next Tutorial we will see haw to use variables in Scala.

    Leave a comment or a question in the comment area bellow if you fell like

    Be a sport and


    Loading... Please wait

    Subscribe to our Newsletter

    Be a sport and