25 September, 2014

Learning Scala- Hello World!


If you are using Ubuntu, Install Scala by running the following command on terminal:

sudo apt-get install scala

This would install Scala on your machine.

install Scala

Create a project directory lets say : MyProject and go to it

mkdir MyProject
cd MyProject/

Using terminal run the following lines of code

mkdir -p src/main/scala
This would make a project directory structure for Scala project that we are going to create

echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > src/main/scala/hw.scala

Here we are creating a file named hw.scala, inside src/main/scala direcctory which we created in previous step. and wrote the line
object Hi { def main(args: Array[String]) = println("Hi!") }
in it. Let's format it and understand
object Hi {
def main(args: Array[String]) = println("Hi!")
}
Here, we are defining an object Hi, with a main function inside.
This function simply prints a Hi! on the screen.

Lets compile our code now:
scalac src/main/scala/hw.scala
This would compile our scala code to byte code.
Test the code by running it
scala Hi






scala Hello World Test
It should print "Hi!" on console.

You just created a basic program in Scala.

18 September, 2014

Calculating Largest known Russian Prime number

Prime Number is a number which is not perfectly divisible by more than 2 numbers. (And those two numbers which would divide a prime number are 1 and the number itself.)

A Russian Doll is a set of wooden dolls of decreasing size placed one inside the other.

A Russian Doll Prime Number is a prime number whose right digit can be repeatedly removed, and it still is prime.

Why are interfaces used?


1) In programming languages, Interfaces are like a contract which states what methods would be available by Implementing Classes. This is really helpful, when we are concerned about specific functionality only.

2) Child classes implementing an interface follow IS-A relationship with that interface.