Scala basic syntax


  Translation results:

Scala is the abbreviation of Scalable Language and is a multi-paradigm programming language

Martin Odersky of the Ecole Polytechnique Fédérale de Lausanne (EPFL) began designing Scala in 2001 based on the work of Funnel.

Funnel is a programming language that combines functional programming ideas with Petri nets.

Scala basic syntaxsyntax

The biggest difference between Scala and Java is that the semicolon ; at the end of a Scala statement is optional.

We can think of a Scala program as a collection of objects that implement message passing by calling each other's methods. Next, let’s understand the concepts of classes, objects, methods, and instance variables:

Objects - Objects have properties and behaviors. For example: a dog's attributes include: color, name, and behaviors include: barking, running, eating, etc. An object is an instance of a class.

Class - A class is an abstraction of an object, and an object is a concrete instance of a class.

Method - A method describes the basic behavior. A class can contain multiple methods.

Fields - Each object has its unique set of instance variables, namely fields. Object properties are created by assigning values ​​to fields.

Scala basic syntaxexample

$ scala
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1 + 1res0: Int = 2
scala> println("Hello World!")Hello World!
scala>

Popular Recommendations

Home

Videos

Q&A