LifeMichael

LifeMichael

Haim Michael Blog

LifeMichael RSS Feed
 
 
 
 

Posts tagged Scala

Scala Programming Course in Shenkar ACD

During 2013 spring semester I will deliver in Shenkar the Java Programming course. Its first part focuses in Java. Its second part focuses in Scala. The highlight is Scala. You can find the detailed syllabus at http://www.lifemichael.com/shenkar/SHENKAR_BASIC_JAVA_201302.pdf. You can find the google group we are going to use during this course at https://groups.google.com/forum/?fromgroups#!forum/shenkar-java-scala-2013-03. You can find the [...]

Scala Programming Course in HIT ACD

During 2013 spring semester I will deliver in HIT the ‘Internet Programming’ course. Its first part focuses in Java. Its second part focuses in Scala. You can find the detailed syllabus at http://www.lifemichael.com/hit/internet_programming_2013_02_en.pdf. You can find the google group we are going to use during this course at https://groups.google.com/forum/?fromgroups#!forum/hit-scala-2013-02. You can find the on-line detailed plan at https://docs.google.com/spreadsheet/pub?key=0AhDgrQD6qivLdEFGdTJYQjQ3ek5OTDlORjdXSnIxY3c&output=html.

Generics Wild Card in Scala PRO

When defining a variable of a generic type we can use a wild card instead of specifying the exact secondary type the generic type uses. object HelloSample { def main(args:Array[String]):Unit = { val a:MyStack[SportCar] = new MyStack[SportCar]; val b:MyStack[_ <: Car] = a; } } class Car class SportCar extends Car class MyStack[T] The following [...]

Generics Contravariance in Scala PRO

When using generics Scala doesn’t support covariance. The following code doesn’t compile. object HelloSample { def main(args:Array[String]):Unit = { val a:MyStack[SportCar] = new MyStack[SportCar]; val b:MyStack[Car] = a; } } class Car class SportCar extends Car class MyStack[T] The following video clip shows the compilation error we get while trying to compile this code and [...]

Functions as Objects in Scala PRO

Function values are treated as objects. The function A=>B is an abbreviation for using a new object instantiated from a class that extends the scala.Function1[A,B] trait and overrides the apply function. There are currently Function1, Function2, Function3… etc… up to Function22, that takes 22 parameters. The following code sample shows that. object HelloSample { def main(args:Array[String]):Unit [...]

Anonymous Inner Class in Scala PRO

Scala allows us to define anonymous inner classes. The syntax is very similar to the one we know in Java. object Demo { def main(args:Array[String]):Unit = { val ob = new MyStack[Int](0) { def data:Nothing = throw new Exception(“empty stack”); } } } abstract class MyStack[T](size:Int) { def data:T; } The following video clip overviews [...]

Generic Functions in Scala PRO

The Scala programming language allows us to define generic functions. This code sample shows that. object Sample { def main(args:Array[String]):Unit = { val ob = getMyStack[Int](10) } def getMyStack[T](num:Int) = { new MyStack[T](num) } } class MyStack[T](size:Int) { //… } The following video clips overviews this code sample, shows its execution and provides more information.

Overloading Unary Operators in Scala PRO

When overloading an unary operators in Scala we should precede the operator name with ‘unary_’. Not doing so we will get an exception when using it. The following code sample shows that. package il.ac.hit.samples object Program { def main(args: Array[String]) { val ob = new RationalNumber(1,3) val other = -ob println(other) } } class RationalNumber(a:Int,b:Int) [...]

By Name Parameters in Scala PRO

When calling a function and passing over an argument which is an expression that needs to be evaluated, the expression will be evaluated before the function is invoked and its value will be passed over. This is the default behavior. By adding => in between the parameter name and its type we will defer the [...]

Tail Recursive Function in Scala PRO

If the last action a function performs is calling to itself then it is a tail recursive function. When a tail recursive function is executed the computer doesn’t need to keep the memory stack frames. It can use one frame only. Using the @tailrec annotation we can instruct the computer to use one frame only [...]

Facebook Page

Life Youtube

Categories

Communities


Certifications




Tags

Speaker Wiki

My Facebook

Technorati

Add to Technorati Favorites

Recommend

Archives

Countries I Visited


visited 17 states (7.55%)
Create Your Own Map!

ClustrMaps

Recent Searches

FeedJIT

Google Page Rank

Alexa Stats

Courses I Teach


 

My Free Lectures


 

 

 

My Free eBooks


 

 

 

 

 

 

 

 

 

 

 

 

 

 

Courses 1996

Courses 1997

Courses 1998

Courses 1999

Courses 2000

Courses 2001

Courses 2002

Courses 2003

Courses 2004

Courses 2005

Courses 2006

Courses 2007

Courses 2008

Courses 2009

Courses 2010

Courses 2011

Courses 2012

Courses 2013