Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Scala] Importing Java libs.
07-28-2010, 06:58 AM
Post: #1
[Scala] Importing Java libs.
Scala - Import Java Libraries
What you need
All you really need is Scala and JRE installed

Getting Started
After Scala is Installed, you simple have to go into your terminal
Or, Cmd if running windows and type Scala. This opens up the interactive scala shell.
Since Scala can make use of Java libraries, might as well use it!

In the Shell
Once it's up and running you should have something similiar to this
Code:
\Welcome to Scala version 2.7.7final (OpenJDK 64-Bit Server VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.

scala>
Now we can start using our java libraries!

Import one by simply typing this:
Code:
import java.util._

Semi-colons not needed, although. You can have them to terminate lines.
This is similiat to java with the obvious import statement. Just for clarity.. in Scala
'_' is the wild card character ( In Java it's '*').

Using Libraries After Import
Take a look at the Java API, and see whats in the libraries you just loaded. In Java.util
there is the date functions. So lets create a new Date
Code:
val DateP9 = new Date

This code is simple, you create a value. Which is like a final variable in java. Which just
means you cannot change it after it has been set. If you would like to have a variable that
you can change, you can just use var!

The Output

The output you get from this should be the current date and information on what you just created
like so:
d: java.util.Date = Tue Jul 27 16:49:37 EDT 2010

Have fun. Scala is a great language to learn

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
07-28-2010, 08:14 PM
Post: #2
RE: [Scala] Importing Java libs.
It is an interesting lib. THX for sharing !!!

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: