The Artima Developer Community
Sponsored Link

Web Buzz Forum
Learning Scala 1 : A Hello World

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Chee Seng Chua

Posts: 62
Nickname: quai83
Registered: Nov, 2006

Chee Seng Chua is Senior Application Developer for KZEN Solutions Berhad
Learning Scala 1 : A Hello World Posted: Apr 10, 2009 10:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Chee Seng Chua.
Original Post: Learning Scala 1 : A Hello World
Feed Title: Chee Seng Tech Blog
Feed URL: http://chuacheeseng.blogspot.com/atom.xml
Feed Description: When you think you are superior, you are being an idiot...
Latest Web Buzz Posts
Latest Web Buzz Posts by Chee Seng Chua
Latest Posts From Chee Seng Tech Blog

Advertisement
Scala is a powerful and interesting language to learn. Personally, I like it as the next generation of my daily written Java programming language.

To getting started with Scala is easy. Get a Scala distribution from http://www.scala-lang.org and unzip it to, for say C:\scala-2.7.3.final and set C:\scala-2.7.3\bin into your PATH environment variable. It requires Java runtime environment version 1.5 or later installed on your machine, I am having Sun JDK 6 Update 13 installed on my Windows XP machine.

After the above setup, you can start Scala Interpreter by entering 'scala' in command prompt:-


C:\>scala


Alternatively, you can start the Scala Interpreter also by double clicking 'scala.bat' under the 'bin' folder. You should after the Scala Interpreter waiting for your command now:-


scala>


Now, let's type 3 + 5 into it:-


scala> 3 + 5
res0: Int = 8


The 'res0' is a generated name to refer to the calculated value. You can try to print it out by using println():-


scala> println(res0)
8


You can declare 'val' (value) or 'var' (variable) in Scala, 'val' works similar like 'final' in Java, which reassignment is not allowed. You can try reassign the 'res0' to something else and you should get an error:-


scala> res0 = 9
:5: error: reassignment to val
res0 = 9


Now, let's declare a value call 'myValue':-


scala> val myValue = "Hello World"
myValue: java.lang.String = Hello World


You can see that I do not declare any type for myValue, the Scala compiler is smart enough to infer the value type to String, optionally, you can write it in the following way:-


val myValue:String = "Hello World"


Now, let's print it out:-


scala> println(myValue)
Hello World


That's complete my 'Hello World' in Scala!. ;-)

Read: Learning Scala 1 : A Hello World

Topic: Do we really need a Cloud Manifesto? Previous Topic   Next Topic Topic: The CC Value Proposition for Utilisation

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use