Advanced Object-Oriented Languages Scala

Size: px
Start display at page:

Download "Advanced Object-Oriented Languages Scala"

Transcription

1 Advanced Object-Oriented Languages Scala Programming Paradigms Department of Computer Science University of Aalborg, Denmark Erik Ernst (U. of Aarhus)

2 Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 2 Erik Ernst

3 Purpose of using Scala Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 3 Erik Ernst

4 Purpose of using Scala Why Scala? It is a real programming language, can be used for experiments Much more interesting than, e.g., Java, and cleaner Run-time concepts: class, mixin, trait Type related concepts: type arguments, variance Functional programming in an OO context October 2008, Aalborg 4 Erik Ernst

5 Introduction syntax Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 5 Erik Ernst

6 Introduction syntax To read Scala, start thinking Java class Point(xc: int, yc: int) { var x: int = xc var y: int = yc def move(dx: int, dy: int): unit = { x = x + dx y = y + dy override def tostring(): String = ( + x +, + y + ) October 2008, Aalborg 6 Erik Ernst

7 Introduction syntax Constructor arguments are given to the class class Point(xc: int, yc: int) { var x: int = xc var y: int = yc def move(dx: int, dy: int): unit = { x = x + dx y = y + dy override def tostring(): String = ( + x +, + y + ) October 2008, Aalborg 7 Erik Ernst

8 Introduction syntax Types are specified after names, with a colon class Point(xc: int, yc: int) { var x: int = xc var y: int = yc def move(dx: int, dy: int): unit = { x = x + dx y = y + dy override def tostring(): String = ( + x +, + y + ) October 2008, Aalborg 8 Erik Ernst

9 Introduction syntax Declarations start with a keyword; def has = class Point(xc: int, yc: int) { var x: int = xc // cf. constant: val x: int = xc var y: int = yc def move(dx: int, dy: int): unit = { x = x + dx y = y + dy override def tostring(): String = ( + x +, + y + ) // override required because of impl. in the superclass October 2008, Aalborg 9 Erik Ernst

10 Introduction syntax Built-in types have slightly different names class Point(xc: int, yc: int) { var x: int = xc var y: int = yc def move(dx: int, dy: int): unit = { x = x + dx y = y + dy override def tostring(): String = ( + x +, + y + ) October 2008, Aalborg 10 Erik Ernst

11 Introduction syntax An overview of the built-in types Any AnyVal AnyRef (java.lang.object) Double Int... Unit Boolean... ScalaObject Seq List java.lang.string... (other java classes) Option... (other scala classes) Null Nothing October 2008, Aalborg 11 Erik Ernst

12 Introduction syntax No special casing for primitive types (cf. Java) object UnifiedTypes extends Application { val set = new scala.collection.mutable.hashset[any]; set += This is a string // add a string set += 732 // add a number set += c // add a character set += true // add a boolean value set += &main // add the main function val iter: Iterator[Any] = set.elements; while (iter.hasnext) { System.out.println(iter.next) October 2008, Aalborg 12 Erik Ernst

13 Entity concepts: Class, mixin, trait Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 13 Erik Ernst

14 Entity concepts: Class, mixin, trait Classes A class describes a set of objects with similar structure, but different identity and possibly different state Point is a fine example new syntax, but apart from that it is basically recognizable as Java-like code Subclasses also as in Java, with extends, and inheritance too, apart from the requirement to use override (Later we will take a brief look at case-classes) October 2008, Aalborg 14 Erik Ernst

15 Entity concepts: Class, mixin, trait Mixins with an excursion to Java... Sometimes it is impractical that only subclasses can inherit the implementation of a set of methods Listener I JFrame E.g.: In Java, if I is an interface and C is a class implementing I then one cannot reuse the implementation in C in a class which must get another superclass than C Work-around: Copy the code! MyListener C MyWindow October 2008, Aalborg 15 Erik Ernst

16 Entity concepts: Class, mixin, trait Mixins with an excursion outside Java... Sometimes it is impractical that only subclasses can inherit the implementation of a set of methods Listener I JFrame E.g.: In Java, if I is an interface and C is a class implementing I then one cannot reuse the implementation in C in a class which must get another superclass than C MyListener MyWindow C Better: let C be a mixin! October 2008, Aalborg 16 Erik Ernst

17 Entity concepts: Class, mixin, trait Mixin example in Scala setup class Point2D(xc: int, yc: int) { val x = xc val y = yc override def tostring() = x = + x +, y = + y class Point3D(xc: int, yc: int, zc: int) extends Point2D(xc, yc) { val z = zc override def tostring() = super.tostring +, z = + z October 2008, Aalborg 17 Erik Ernst

18 Entity concepts: Class, mixin, trait Mixin example in Scala def. and apply trait Colored { var color = Black def setcolor(newcol: String): unit = color = newcol override def tostring() = super.tostring +, col = + color class ColoredPoint3D(xc: int, yc: int, zc: int) extends Point3D(xc, yc, zc) with Colored October 2008, Aalborg 18 Erik Ernst

19 Entity concepts: Class, mixin, trait Mixins in Scala in general Point2D Mixins are declared with trait and used with with A mixin cannot have constructor parameters Compared to Java interfaces, mixins can have implemented methods and state The point is that we can add it to more than one class! Point3D ColoredPoint3D Colored October 2008, Aalborg 19 Erik Ernst

20 Entity concepts: Class, mixin, trait A remark about general traits The general traits concept is in fact not identical to Scala s traits General traits cannot have state General traits have method renaming/exclusion/selection All in all: general traits are very flexible method tool boxes, and traits in Scala are almost the same thing However, Scala traits are actually closer to another concept, mixins, which is why that term was used October 2008, Aalborg 20 Erik Ernst

21 Entity concepts: Class, mixin, trait Another trait/mixin example trait HasAdd { def add(i: int, j: int) = i+j def mult(i: int, j: int): int trait HasMult { def add(i: int, j: int): int def mult(i: int, j: int) = i*j abstract class HalfComputer { def start: unit; def stop: unit class Computer extends HalfComputer with HasMult with HasAdd { def start =...; def stop =... October 2008, Aalborg 21 Erik Ernst

22 Functional programming Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 22 Erik Ernst

23 Functional programming Functional programming = OO with a twist ;-) Functional programming was designed into Scala from the very beginning But it is in fact pure OO made slightly more concise Functions are objects, function calls are method calls, and methods can be turned into functions on demand An element that did not fit in: Lazy evaluation An element that was not needed: Structural type equivalence October 2008, Aalborg 23 Erik Ernst

24 Functional programming Basic functional programming in Scala // an anonymous function... (x: int) = x // can, e.g., initialize a variable val f: (Int= Int) = ((x: Int) = x + 1) // what this actually means (we return to this later) val f2 = new Function1[Int, Int] { def apply(x: Int): Int = x + 1 // methods are transformed to functions on demand val s = 5 System.out.println(s.toString +, + s.tostring ) // prints 5, function October 2008, Aalborg 24 Erik Ernst

25 Functional programming An example of a higher-order function class Decorator(left: String, right: String) { def layout(x: int) = left + x.tostring + right object FunTest extends Application { def app(f: int = String, v: int) = f(v) val decorator = new Decorator( [, ] ) System.out.println(app(decorator.layout, 7)) So what does it print? October 2008, Aalborg 25 Erik Ernst

26 Functional programming Using block structure (free variables where?) object FilterTest extends Application { def filter(xs: List[int], threshold: int) = { def process(ys: List[int]): List[int] = if (ys.isempty) ys else if (ys.head threshold) ys.head :: process(ys.tail) else process(ys.tail); process(xs) System.out.println(filter(List(1, 9, 2, 8, 3, 7, 4), 5)) October 2008, Aalborg 26 Erik Ernst

27 Functional programming Using block structure (free variable) object FilterTest extends Application { def filter(xs: List[int], threshold: int) = { def process(ys: List[int]): List[int] = if (ys.isempty) ys else if (ys.head threshold) ys.head :: process(ys.tail) else process(ys.tail); process(xs) System.out.println(filter(List(1, 9, 2, 8, 3, 7, 4), 5)) October 2008, Aalborg 27 Erik Ernst

28 Functional programming Currying (to receive arguments one by one) object CurryTest extends Application { def filter(xs: List[int], p: int = boolean): List[int] = if (xs.isempty) xs else if (p(xs.head)) xs.head :: filter(xs.tail, p) else filter(xs.tail, p) def modn(n: int)(x: int) = ((x % n) == 0) val nums = List(1, 2, 3, 4, 5, 6, 7, 8) System.out.println(filter(nums, modn(2))) System.out.println(filter(nums, modn(3))) October 2008, Aalborg 28 Erik Ernst

29 Functional programming Functional programming in Scala Scala does not enforce immutability, but it is eagerly supported Anonymous and higher-order functions are easy to express and use Standardization removes the need for structural type equivalence For infinite structures and similar lazy tricks some manual work is required October 2008, Aalborg 29 Erik Ernst

30 Pattern matching Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 30 Erik Ernst

31 Pattern matching A special kind of classes are used for pattern matching // Example: lambda terms abstract class Term case class Var(name: String) extends Term case class Fun(arg: String, body: Term) extends Term case class App(f: Term, v: Term) extends Term // We may now create expressions, e.g.... Fun( x, Fun( y, App(Var( x ), Var( y ))))... Note: No need to write new for creation of objects October 2008, Aalborg 31 Erik Ernst

32 Pattern matching Pattern matching is achieved with match/case def print(term: Term): unit = term match { case Var(n) = System.out.print(n) case Fun(x,b) = System.out.print( ˆ + x +. ); print(b) case App(f,v) = System.out.print( ( ); print(f) System.out.print( ); print(v); System.out.print( ) ) def isidentityfun(term: Term): boolean = term match { case Fun(x, Var(y)) if x == y = true case = false val id = Fun( x, Var( x )) val t = Fun( x, Fun( y, App(Var( x ), Var( y )))) print(t); System.out.println(isIdentityFun(id)) System.out.println(isIdentityFun(t)) October 2008, Aalborg 32 Erik Ernst

33 Generic classes Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 33 Erik Ernst

34 Generic classes Type arguments We often need to use a class with more than one type in a specific location Typical example: sets, stacks, lists Known solutions: (too) general data type; copying source code; using type arguments October 2008, Aalborg 34 Erik Ernst

35 Generic classes A general stack (what s the problem?) class GeneralStack { var elems = Nil def push(x: Any): unit = elems = x :: elems def top: Any = elems.head def pop: unit = elems = elems.tail October 2008, Aalborg 35 Erik Ernst

36 Generic classes The problem is loss of type information! val greeting: String = Hello, world! val mystack: GeneralStack = new GeneralStack mystack.push(greeting) // Type error in the next line!! val samegreeting: String = mystack.top October 2008, Aalborg 36 Erik Ernst

37 Generic classes Better: copy-paste to adjust the type (OK now?) class IntStack { var elems = Nil def push(x: int): unit = elems = x :: elems def top: int = elems.head def pop: unit = elems = elems.tail class StringStack { var elems = Nil def push(x: String): unit = elems = x :: elems def top: String = elems.head def pop: unit = elems = elems.tail October 2008, Aalborg 37 Erik Ernst

38 Generic classes Even better: Make the type an argument class Stack[T] { var elems = Nil def push(x: T): unit = elems = x :: elems def top: T = elems.head def pop: unit = elems = elems.tail October 2008, Aalborg 38 Erik Ernst

39 Generic classes Using the stack object GenericsTest extends Application { val stack: Stack[int] = new Stack[int]; stack.push(1); stack.push( a ); // what s going on here? System.out.println(stack.top); stack.pop; System.out.println(stack.top); October 2008, Aalborg 39 Erik Ernst

40 Generic classes NB: we ve been cheating elems must have a type class GeneralStack { var elems: List[Any] = Nil... class IntStack { var elems: List[Int] = Nil... class StringStack { var elems: List[String] = Nil... class Stack[T] { var elems: List[T] = Nil... October 2008, Aalborg 40 Erik Ernst

41 Variance Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 41 Erik Ernst

42 Variance Variance Subtype example: Point3D is a subtype of Point2D General rule: where a type is expected any subtype can be used, so we can use a Point3D where Point2D is expected Variance is about the rules for when a type is a subtype of an other one First we look at a problem in connection with variance... October 2008, Aalborg 42 Erik Ernst

43 Variance A typing problem... // int is a subtype of Any, i.e., int : Any val myintstack: Stack[int] = new Stack[int] val mystack: Stack[Any] = myintstack mystack.push( A string, no less ) // what s wrong here? why does it fail? October 2008, Aalborg 43 Erik Ernst

44 Variance The typing problem is not Scala s: the program is rejected with an error message... is based on the assumption that Stack[Int] <: Stack[Any] In general it is caused by the assumption that type functions are increasing: if S <: T, then C[S] <: C[T ] this is often written as follows: Γ S <: T Γ C[S] <: C[T ] and that assumption is wrong!! October 2008, Aalborg 44 Erik Ernst

45 Variance Covariance fixes the problem Covariant type-args declared using + : class Stack[+T] {... Define covariant positions: Method result types, val types (intuition: where you can get data from something); contravariant positions: Method arguments (put); non-variant positions: var types (both get and put) Limitation: A covariant type-arg can only be used in a covariant position Achieved benefit: Γ S <: T Γ C[S] <: C[T ] if C s type-arg is covariant E.g., Stack[Int] is a subtype of Stack[Any], if the type-arg of Stack is covariant October 2008, Aalborg 45 Erik Ernst

46 Variance But this type-arg cannot be covariant! class Stack[+T] { var elems: List[T] = Nil // Wonder if this is OK? def push(x: T): unit = elems = x :: elems // ERROR! def top: T = elems.head // OK def pop: unit = elems = elems.tail October 2008, Aalborg 46 Erik Ernst

47 Variance We must change Stack to use covariance Idea: create a functional version of Stack I.e., never change a stack, always create a similar one and return it Background: we can avoid using the type-arg outside covariant positions if we are willing to pay for it! October 2008, Aalborg 47 Erik Ernst

48 Variance A functional, covariant stack class Stack[+A] { def push[b : A](elem: B): Stack[B] = new Stack[B] { override def top: B = elem override def pop: Stack[B] = Stack.this override def tostring() = elem.tostring() + + Stack.this.toString() def top: A = error( no element on stack ) def pop: Stack[A] = error( no element on stack ) override def tostring() = October 2008, Aalborg 48 Erik Ernst

49 Variance Using the functional, covariant stack object VariancesTest extends Application { var s: Stack[Any] = new Stack[Int]().push[String]( hello ) s = s.push(new Object()) s = s.push(7) System.out.println(s) Challenge: which green elements can we have/delete? Why? October 2008, Aalborg 49 Erik Ernst

50 Variance Summary about the functional, covariant stack It is possible to create a covariant stack! Every time something is push ed on it, it potentially loses type information A useful rule of thumb: This kind of data structure must be used under an explicit type October 2008, Aalborg 50 Erik Ernst

51 Variance One last variance example: Functions Functions in Scala are represented as objects Function declarations, types, and applications are just syntactic sugar Expansion reduces these mechanisms to ordinary OO mechanisms trait Function[+r] { def apply: r trait Function1[-t,+r] { def apply(x: t): r T 1,..., T k = S just means Functionk[T 1,..., T k, S] f (x) just means f.apply(x) when f is an object October 2008, Aalborg 51 Erik Ernst

52 Variance Function desugaring example val plus1: (int = int) = (x: int) = x + 1 plus1(2) // is expanded into the following object code: val plus1: Function1[int, int] = new Function1[int, int] { def apply(x: int): int = x + 1 plus1.apply(2) October 2008, Aalborg 52 Erik Ernst

53 Summary Overview Purpose of using Scala Introduction syntax Entity concepts: Class, mixin, trait Functional programming Pattern matching Generic classes Variance Summary October 2008, Aalborg 53 Erik Ernst

54 Summary Summary Scala was introduced, and used to illustrate the following concepts: Classes, mixins/traits Type arguments Variance Functions as objects Several connections to earlier lectures: Functions are first-class, higher-order values (though objects) Pattern matching can be used on case-classes (but not: lazy evaluation, ref. transparency) Scala is an example of a multi-paradigmatic language October 2008, Aalborg 54 Erik Ernst

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example Overview Elements of Programming Languages Lecture 11: Object-oriented functional programming James Cheney University of Edinburgh October 30, 2017 We ve now covered: basics of functional programming (with

More information

Lecture 09: Introduction to Scala

Lecture 09: Introduction to Scala Lecture 09: Introduction to Scala Computer Science Department, University of Crete Multicore Processor Programming Based on slides by D. Malayeri, S.D. Vick, P. Haller, and M. Madsen Pratikakis (CSD) Scala

More information

CS 2340 Objects and Design - Scala

CS 2340 Objects and Design - Scala CS 2340 Objects and Design - Scala Objects and Operators Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design - Scala Objects and Operators 1 / 13 Classes

More information

Programming Paradigms, Fall 06

Programming Paradigms, Fall 06 Programming Paradigms, Fall 06 Multiple Choice Exam January 29, 2007, 10:00 11:15 ID Name Each of the following questions has exactly one correct answer. For each question, you may select one or more answers

More information

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline Bibliography Analyse et Conception Formelle Lesson 5 Crash Course on Scala Simply Scala. Onlinetutorial: http://www.simply.com/fr http://www.simply.com/ Programming in Scala, M. Odersky, L. Spoon, B. Venners.

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 1 Thomas Wies New York University Review Last lecture Object Oriented Programming Outline Today: Scala Sources: Programming in Scala, Second

More information

The SCAlable LAnguage

The SCAlable LAnguage The SCAlable LAnguage The Scala Language: Object Oriented Functional Programming Gabor Szokoli Overview Introduction Everything is an Object Inheritance and mixins For comprehensions Generic Types: Covariance,

More information

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally

More information

Topic VIII. The state of the art Scala < > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008.

Topic VIII. The state of the art Scala <  > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008. References: Topic VIII The state of the art Scala < www.scala-lang.org > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008. An overview of the Scala programming language by M.

More information

CSCI-GA Final Exam

CSCI-GA Final Exam CSCI-GA 2110-003 - Final Exam Instructor: Thomas Wies Name: Sample Solution ID: You have 110 minutes time. There are 7 assignments and you can reach 110 points in total. You can solve the exercises directly

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

More information

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2014 2015 rcardin@math.unipd.it INTRODUCTION Object/functional

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative

More information

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA CSE 3302 Lecture 7: Polymorphism and generics 16 September 2010 Nate Nystrom UTA 2 Polymorphism poly = many morph = shape Allow a variable to contain values with different types 3 Subtype polymorphism

More information

CS Programming Languages: Scala

CS Programming Languages: Scala CS 3101-2 - Programming Languages: Scala Lecture 5: Exceptions, Generic Classes Daniel Bauer (bauer@cs.columbia.edu) November 19, 2014 Daniel Bauer CS3101-2 Scala - 05 - Exceptions, Generic Classes 1/28

More information

Functions and Objects. Week 7: Symbolic Computation

Functions and Objects. Week 7: Symbolic Computation Week 7: Symbolic Computation In the previous weeks, we've seen the essential elements of modern functional programming: Functions (rst class) Types (parametric) Pattern Matching Lists This week, we'll

More information

CompSci 220. Programming Methodology 12: Functional Data Structures

CompSci 220. Programming Methodology 12: Functional Data Structures CompSci 220 Programming Methodology 12: Functional Data Structures A Polymorphic Higher- Order Function def findfirst[a](as: Array[A], p: A => Boolean): Int = { def loop(n: Int): Int = if (n >= as.length)

More information

Scala Style Guide Spring 2018

Scala Style Guide Spring 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Scala Style Guide Spring 2018 Contents 1 Introduction 1 2 Naming 1 3 Formatting 2 4 Class Declarations 3 5 Functional Paradigms 4 6 Comments

More information

The Case for Simple Object-Orientation in VDM++ Erik Ernst Aarhus University, Denmark

The Case for Simple Object-Orientation in VDM++ Erik Ernst Aarhus University, Denmark The Case for Simple Object-Orientation in VDM++ Erik Ernst Aarhus University, Denmark An outsider.. My research area is OO language design, implementation, formalization, esp. type systems (virtual classes,

More information

n n Official Scala website n Scala API n

n   n Official Scala website n Scala API n n Quiz 8 Announcements n Rainbow grades: HW1-8, Quiz1-6, Exam1-2 n Still grading: HW9, Quiz 7 Scala n HW10 due today n HW11 out today, due Friday Fall 18 CSCI 4430, A Milanova 1 Today s Lecture Outline

More information

Overview. Elements of Programming Languages. Objects. Self-Reference

Overview. Elements of Programming Languages. Objects. Self-Reference Overview Elements of Programming Languages Lecture 10: James Cheney University of Edinburgh October 23, 2017 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

Optimizing Higher-Order Functions in Scala

Optimizing Higher-Order Functions in Scala Optimizing Higher-Order Functions in Scala Iulian Dragos EPFL Outline A quick tour of Scala Generalities Extension through libraries Closure translation in Scala Cost Optimizations in the Scala compiler

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 1994-2016 Functional Programming An alternative paradigm to imperative programming First-class functions Emphasis

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

...something useful to do with the JVM.

...something useful to do with the JVM. Scala Finally... ...something useful to do with the JVM. Image source: http://www.tripadvisor.com/locationphotos-g187789-lazio.html Young Developed in 2003 by Martin Odersky at EPFL Martin also brought

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Subclassing for ADTs Implementation

Subclassing for ADTs Implementation Object-Oriented Design Lecture 8 CS 3500 Fall 2009 (Pucella) Tuesday, Oct 6, 2009 Subclassing for ADTs Implementation An interesting use of subclassing is to implement some forms of ADTs more cleanly,

More information

CSE341, Spring 2013, Final Examination June 13, 2013

CSE341, Spring 2013, Final Examination June 13, 2013 CSE341, Spring 2013, Final Examination June 13, 2013 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, except for both sides of one 8.5x11in piece of paper. Please stop

More information

List are immutable Lists have recursive structure Lists are homogeneous

List are immutable Lists have recursive structure Lists are homogeneous WORKING WITH LISTS val fruit = List("apples", "oranges", "pears") val nums: List[Int] = List(1, 2, 3, 4) val diag3 = List( List(1, 0, 0), List(0, 1, 0), List(0, 0, 1) ) val empty = List() List are immutable

More information

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free

More information

Functional programming

Functional programming Functional programming Functional programming In functional programming, functions are the core building blocks In pure functional programming, functions are like mathematical functions Mathematical functions

More information

Object typing and subtypes

Object typing and subtypes CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The

More information

Programs as Data. The Scala language

Programs as Data. The Scala language Programs as Data The Scala language Peter Sestoft 2011-11-14 1 Agenda Kursusevaluering slutter i dag! Object-oriented programming in Scala Classes Singletons (object) Traits Compiling and running Scala

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 22 Class-Based Object-Oriented Programming Dan Grossman 2012 PL Issues for OOP? OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive

More information

- couldn t be instantiated dynamically! - no type or other method of organizing, despite similarity to

- couldn t be instantiated dynamically! - no type or other method of organizing, despite similarity to Roots in ADT Languages Lecture 20: OOLs CSC 131 Fall, 2014 Kim Bruce Ada and Modula-2 internal reps - couldn t be instantiated dynamically - no type or other method of organizing, despite similarity to

More information

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:

More information

Introduction to Scala

Introduction to Scala The new Java? July 4, 2009 Presentation Outline Outline Introduction Concise Syntax Object Orientation Functional Programming Various Stuff Conclusion Introducing Scala What is Scala? 100% Object-oriented

More information

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 Contents 1 Mutation in the Doghouse 1 1.1 Aside: Access Modifiers..................................

More information

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D) DATA TYPES CS 403: Types and Classes Stefan D. Bruda Fall 2017 Algorithms + data structures = programs Abstractions of data entities highly desirable Program semantics embedded in data types Data types

More information

Overview. Elements of Programming Languages. Objects. Self-Reference

Overview. Elements of Programming Languages. Objects. Self-Reference Overview Elements of Programming Languages Lecture 11: James Cheney University of Edinburgh November 3, 2015 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Some Advanced ML Features

Some Advanced ML Features Some Advanced ML Features Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming University of Washington: Dan Grossman ML is small Small number of powerful constructs

More information

Object Oriented Classes, Objects, Inheritance, and Typing

Object Oriented Classes, Objects, Inheritance, and Typing Object Oriented Classes, Objects, Inheritance, and Typing By: Nicholas Merizzi January 2005 Pros & Cons of OO programming Conclusion & Discussion Outline General Introduction Why the O.O. paradigm? Classes

More information

Copyright 2018 Tendril, Inc. All rights reserved.

Copyright 2018 Tendril, Inc. All rights reserved. Type Parameter Power-Up! Variance, Bounds, and Inference INTRO Motivations 3 INTRO Motivations Home Energy Report Generation System Free Monad Workflow stages extending common base class Workflow actions

More information

Announcements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy

Announcements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy Announcements CSCI 334: Principles of Programming Languages Lecture 16: Intro to Scala HW7 sent out as promised. See course webpage. Instructor: Dan Barowy Announcements No class on Tuesday, April 17.

More information

Software Engineering Design & Construction

Software Engineering Design & Construction Winter Semester 17/18 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt A Critical View on Inheritance 2 A Critical View On Inheritance

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Object-Oriented Design Lecture 13 CSU 370 Fall 2008 (Pucella) Friday, Oct 31, 2008

Object-Oriented Design Lecture 13 CSU 370 Fall 2008 (Pucella) Friday, Oct 31, 2008 Object-Oriented Design Lecture 13 CSU 370 Fall 2008 (Pucella) Friday, Oct 31, 2008 Laziness For this lecture, I want to return to something that came up during the last homework, the third homework where

More information

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007 Previous C# Releases C# 3.0 Language Features C# Programming March 12, 2007 1.0 2001 1.1 2003 2.0 2005 Generics Anonymous methods Iterators with yield Static classes Covariance and contravariance for delegate

More information

Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP?

Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP? Don t Believe the Hype CS152: Programming Languages Lecture 21 Object-Oriented Programming Dan Grossman Spring 2011 OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive analogy

More information

Classes, subclasses, subtyping

Classes, subclasses, subtyping 1 CSCE 314: Programming Languages Dr. Flemming Andersen Classes, subclasses, subtyping 2 3 Let me try to explain to you, what to my taste is characteristic for all intelligent thinking. It is, that one

More information

Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007

Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007 Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007 (These notes are very rough, and differ somewhat from what I presented in class; I am posting them here to supplemental

More information

Exercise 8 Parametric polymorphism November 18, 2016

Exercise 8 Parametric polymorphism November 18, 2016 Concepts of Object-Oriented Programming AS 2016 Exercise 8 Parametric polymorphism November 18, 2016 Task 1 Consider the following Scala classes: class A class B extends A class P1[+T] class P2[T

More information

Functional Programming Language Scheme

Functional Programming Language Scheme Functional Programming Language Scheme Mirjana Ivanovic University of Novi Sad, Serbia Scheme Scheme - dialect of programming language LISP. Small but powerful With a lot of built-in functions Not pure

More information

C++ Part 2 <: <: C++ Run-Time Representation. Smalltalk vs. C++ Dynamic Dispatch. Smalltalk vs. C++ Dynamic Dispatch

C++ Part 2 <: <: C++ Run-Time Representation. Smalltalk vs. C++ Dynamic Dispatch. Smalltalk vs. C++ Dynamic Dispatch C++ Run-Time Representation Point object Point vtable Code for move C++ Part x y CSCI 4 Stephen Freund ColorPoint object x 4 y 5 c red ColorPoint vtable Code for move Code for darken Data at same offset

More information

The DOT Calculus. (Dependent Object Types) Nada Amin. June 18, Scala Days

The DOT Calculus. (Dependent Object Types) Nada Amin. June 18, Scala Days The DOT Calculus (Dependent Object Types) Nada Amin Scala Days June 18, 2014 1 DOT: Dependent Object Types DOT is a core calculus for path-dependent types. Goals simplify Scala s type system by desugaring

More information

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation

More information

An Introduction to Scala for Spark programming

An Introduction to Scala for Spark programming An Introduction to Scala for Spark programming Nastaran Fatemi Slides of this course are prepared based on the book Programming in Scala and its presentations by Martin Odersky What s Scala Scala is a

More information

Compiler construction 2009

Compiler construction 2009 Compiler construction 2009 Lecture 6 Some project extensions. Pointers and heap allocation. Object-oriented languages. Module systems. Memory structure Javalette restrictions Only local variables and parameters

More information

Opaque types. Understanding SIP-35. Erik nescala

Opaque types. Understanding SIP-35. Erik nescala Opaque types Understanding SIP-35 Erik Osheim @d6 nescala 2018 1 who am i? typelevel member λ maintain spire, cats, and other scala libraries interested in expressiveness and performance ml-infra at stripe

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors 1 CS/ENGRD 2110 FALL 2016 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 References to text and JavaSummary.pptx 2 Local variable: variable declared in a method

More information

Imperative Programming 2: Traits

Imperative Programming 2: Traits Imperative Programming 2: Traits Hongseok Yang University of Oxford Experience with traits so far In IP1, you have used traits as interfaces, in order to specify available methods and fields. trait IntQueue

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs Elements of Programming Languages Lecture 6: Data structures James Cheney University of Edinburgh October 9, 2017 The story so far We ve now covered the main ingredients of any programming language: Abstract

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions

More information

D7020E. Robust and Energy-Efficient Real-Time Systems D7020E. Lecture 2: Components & the Timber language

D7020E. Robust and Energy-Efficient Real-Time Systems D7020E. Lecture 2: Components & the Timber language Robust and Energy-Efficient Real-Time Systems Lecture 2: Components & the Timber language 1 1 Recall The dynamic evolution of a system... with offset asynchronous calls synchronous call T T blocked buffered

More information

D7020E. The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems. blocked Lecture 2: Components & the Timber language.

D7020E. The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems. blocked Lecture 2: Components & the Timber language. Recall The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems with offset asynchronous calls synchronous call T T blocked Lecture 2: Components & the Timber language buffered??

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Introducing Scala-like function types into Java-TX

Introducing Scala-like function types into Java-TX Introducing Scala-like function types into Java-TX ManLang 2017 Martin Plümicke Andreas Stadelmeier www.dhbw-stuttgart.de/horb Overview 1 Type of lambda expressions in Java-8 2 Introducing real function

More information

Control Structures. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1

Control Structures. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1 Control Structures Christopher Simpkins csimpkin@spsu.edu CS 3693, Fall 2011 Chris Simpkins (Georgia Tech) CS 3693 Scala 2011-08-31 1 / 1 Control Structures Scala has only four built-in control structures:

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Generics with Type Bounds

Generics with Type Bounds Generics with Type Bounds Computer Science and Engineering College of Engineering The Ohio State University Lecture 27 Generic Methods Like classes, methods can be generic class ArrayOps { //ordinary nongeneric

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

Imperative Programming 2: Inheritance 1

Imperative Programming 2: Inheritance 1 Imperative Programming 2: Inheritance 1 Hongseok Yang University of Oxford Motivation Scala programs consist of classes, traits and singleton objects. Inheritance is a fundamental building block for relating

More information

Software Engineering: Design & Construction

Software Engineering: Design & Construction Software Engineering: Design & Construction Department of Computer Science Software Technology Group Practice Exam May 22, 2015 First Name Last Name Matriculation Number Course of Study Department Signature

More information

Everything is an object. Almost, but all objects are of type Object!

Everything is an object. Almost, but all objects are of type Object! Everything is an object Almost, but all objects are of type Object! In Java, every class is actually a subclass of Object...or has a superclass which has Object as superclass... There is a class called

More information

Lecture 8: Summary of Haskell course + Type Level Programming

Lecture 8: Summary of Haskell course + Type Level Programming Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

The DOT Calculus. (Dependent Object Types) Nada Amin. May 12, flatmap(oslo)

The DOT Calculus. (Dependent Object Types) Nada Amin. May 12, flatmap(oslo) The DOT Calculus (Dependent Object Types) Nada Amin flatmap(oslo) May 12, 2014 1 Types in Scala and DOT 2 Types in Scala modular named type scala.collection.bitset compound type Channel with Logged refined

More information

Parsing Scheme (+ (* 2 3) 1) * 1

Parsing Scheme (+ (* 2 3) 1) * 1 Parsing Scheme + (+ (* 2 3) 1) * 1 2 3 Compiling Scheme frame + frame halt * 1 3 2 3 2 refer 1 apply * refer apply + Compiling Scheme make-return START make-test make-close make-assign make- pair? yes

More information

CS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 24 Bounded Polymorphism; Classless OOP Dan Grossman Spring 2011 Revenge of Type Variables Sorted lists in ML (partial): type a slist make : ( a -> a -> int) -> a slist

More information

Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018

Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler Lab 8: Introduction to Scala 12:00 PM, Mar 14, 2018 Contents 1 Getting Started 1 2 Vals vs Vars 1 3 Team Rocket s Shenanigans 2 4 Lunch Time! 3 5

More information

Linked lists and the List class

Linked lists and the List class Linked lists and the List class Cheong 1 Linked lists So far, the only container object we used was the array. An array is a single object that contains references to other objects, possibly many of them.

More information

Object-oriented programming

Object-oriented programming Object-oriented programming HelloWorld The following code print Hello World on the console object HelloWorld { def main(args: Array[String]): Unit = { println("hello World") 2 1 object The keyword object

More information

CSCI 355 Lab #2 Spring 2007

CSCI 355 Lab #2 Spring 2007 CSCI 355 Lab #2 Spring 2007 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 10 Thomas Wies New York University Review Last class ML Outline Modules Sources: PLP, 3.3.4, 3.3.5, 3.8 McConnell, Steve. Code Complete, Second Edition,

More information

Review sheet for Final Exam (List of objectives for this course)

Review sheet for Final Exam (List of objectives for this course) Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter

More information