bangvef.blogg.se

Scala hello world
Scala hello world












scala hello world

Before we move on, in both programs, the Java class and the Scala object are public.The reason why we have defined an object instead of a class in the equivalent Scala program is described in a short while. We can also, of course, define classes and create objects using new keyword as in Java. In Scala, we can directly define an object as shown above. In Java, we create an object using the new keyword followed by the class name. An object is a concrete instance of a class. The major contrast between the two programs is that while the Java program has a class declaration, the Scala program has an object declaration.Ĭonceptually, a class is a blueprint for objects.Scala provides an easier and more concise way to import multiple statements as we will see in a later post. While import statement is not shown in the above simple programs, they can both be part of a program in Java as well as Scala.

scala hello world

Semicolon is required though when multiple statements are written in a single line. Newline marks end of a statement and beginning of another. In a Scala program, the compiler does not care whether a statement ends with a semicolon or not. While the package statement or rather every statement in the Java program ends with a semi-colon, semicolon is not mandatory in the Scala program. Both the programs begin with a package declaration.We compare and contrast the first programs in Java and Scala as follows: The output of both of the above programs is to print out Hello World. In Scala, an equivalent program looks something as follows – Primary and Auxiliary Constructors in Scala.You might already know that to run a Java program, there must be a public class with a main method that takes one parameter, a String, and has a void return type. As a first step into learning Scala and as one who is familiar with Java, let us compare the customary Helloworld programs in Java and Scala.














Scala hello world