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.
All class names, the first letter should be in Upper Case.
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.
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:
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.
like the name states this are operators such as ( +, :, ?, ~ or #)
consists of an alphanumeric identifier, which is followed by an underscore and an operator identifier.
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.
Newline in Scala
In Scala semicolon at the end of a statement is optional unless you wanna write multiple command on the same line.
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:
this will import the entire content of the short package.
Next Tutorial we will see haw to use variables in Scala.