Friday, March 11, 2016

reading file in Scala

Files can be read in Scala using the below code.

Here as I have defined a dedicated packages for all the examples presented here i.e example which is defined in first line. We need to import package for the io operation. We defined a class/object Main in which we defined a main method. We have defined a variable filename in which we have decalred our file name with the path and read its content using the for loop over the file lines.

Wednesday, March 9, 2016

Hello World Program in Scala

Below is the hello world program in Scala

As Scala is very similar to java. Hence people with programming experience can relate the below code to java. Object keyword will create a class HelloWorld and instantiate one object with same name. Main function serves the same purpose as that in java and acts as the starting point for code execution. And println function prints the output.