Advanced Programming [AP-17]

Code 301AA - 9 Credits


Andrea Corradini <>

Lillo Galletta <>
Timetable Monday 11-13, Room Fib L1
Tuesday 9-11, Room Fib L1
Thursday 16-18, Room Fib A1
Office hours Click here
To fix a date, send an email to <>

Course description


Exam dates

Students can take the exam during exam sessions, but there are no fixed date. Please contact the lecturer by email to fix a date for the exam. The next exam sessions are Before the oral exam, students must have filled out the evaluation questionnaire accessible at page


The final grade is based on the evaluation of the three programming assignments listed below, and on a final oral exam. During the oral exam the lecturer may ask questions about any of the topics presented during the course, as detailed in the Syllabus of the course. The topic of the first part of the oral exam can be proposed by the student, as explained in page AP-OralExam.html.

Syllabus of the course

Programming assignments

  1. First programming assignment
  2. Second programming assignment
  3. Third programming assignment


In order to take full advantage of the course and of being able to pas the final exam in a reasonable time, students are required to have an undergraduate level knowledge of at least one object-oriented programming language (like Java, C++, C# or others) and of at least one functional programming language (like Haskell, OCaml, Scheme or others). Students having a weak background on such topics are strongly encouraged to review by themselves the core notions of Object-Oriented and Functional Programming at the beginning of the course, possibly exploiting the following online material:

For Functional Programming:

For Object-Oriented programming:

Textbooks and Reading Material

Reading material:

Reference documentation:

To be completed...

Course Schedule

Sep. 18, 2017
Presentation of the course Slides: AP-2017-01.pdf
Sep. 19, 2017
Languages and Abstract Machines
Compilation and interpretation schemes
Slides: AP-2017-03.pdf Suggested readings: Chapter 1 of Programming Languages: Principles and Paradigms by Maurizio Gabbrielli and Simone Martini
Sep. 22, 2017
Room A1
Compilation and interpretation schemes
Entry test
Slides: AP-2017-03.pdf The entry test is intented to evaluate if students have the necessary prerequisites of the course, namely knowledge of concepts of Object-Oriented and Functional programming.
Sep. 25, 2017
Room L1
Runtime Systems and Introduction to the JVM
Slides: AP-2017-04.pdf Suggested readings: JVM Internals, by James D. Bloom Reference documentation:
The Java Virtual Machine Specification, Java SE 8 Edition
The Java Language Specification, Java SE 8 Edition
Sep. 26, 2017
Room L1
JVM internals
Slides: AP-2017-05.pdf
Sep. 28, 2017
Room A1
The JVM Instruction Set
Slides: AP-2017-06.pdf Suggested readings: Java Code To Byte Code - Part One, by James D. Bloom,
A First Taste of InvokeDynamic, by Charles Nutter,
Oct. 2, 2017
Room L1
Software Components: an introduction Slides: AP-2017-07.pdf Suggested readings:
Chapters 1 and 4 of [COMP], Software Components: Beyond Object-Oriented Programming. C. Szyperski, D. Gruntz, S. Murer, Addison-Wesley, 2002.
Oct. 3, 2017
Room L1
Software Components: the Microsoft way Slides: AP-2017-08.pdf Suggested readings:
Chapter 15 of [COMP]
Oct. 5, 2017
Room A1
Exercises: Inspecting the JVM
Students are invited to bring their own laptop.
Instructions: activities.html
Files: pa_lecture.tar.gz

Software needed for the exercises:
Oct. 9, 2017
Room L1
Software Components: the Sun approach, JavaBeans Slides: AP-2017-09.pdf Suggested readings:
Oct. 10, 2017
Room L1
Reflection in Java Slides: AP-2017-10.pdf Suggested readings:
The Java Tutorial on Reflection API, excluding Arrays and Enumerated Types.
Oct. 12, 2017
Room A1
Exercises on NetBeans, JavaBeans and Reflection in Java
Students are invited to bring their own laptop.
Instructions: exercises.html

Software needed for the exercises:
Oct. 16, 2017
Room L1
Frameworks and Inversion of Control Slides: AP-2017-11.pdf Suggested readings:
Oct. 17, 2017
Room L1
Frameworks: Decoupling components; Dependency Injections; IoC Containers Slides: AP-2017-11.pdf Suggested readings:
Oct. 19, 2017
Room A1
Presentation of programming assigments on NetBeans, JavaBeans and Reflection in Java.
Students are invited to bring their own laptop.
First programming assignment

Software needed for the exercises:
Oct. 23, 2017
Room L1
  • A classification
  • Overloading
  • Coercion
  • Inclusion polymorphism
  • Overriding
Slides: AP-2017-12.pdf. Suggested readings:
Oct. 24, 2017
Room L1
Universal Parametric Polymorphism:
C++ Templates and Java Generics
  • C++ templates
  • The Standard Template Library: an overview
  • Java Generics
  • Bounded type parameters
  • Generics and inheritance: invariance, covariance and contravariance
Slides: AP-2017-13.pdf Suggested readings:
Oct. 26, 2017
Room A1
Java Generics
  • Java Generics, type bounds and subtyping
  • Covariance, contravariance in Java and other languages
  • Subtyping and arrays in Java
  • Wildcards
  • Type erasure and timitations of generics
Introduction to Functional Programming
Slides: AP-2017-14.pdf
AP-2017-15.pdf, up to page 8
Suggested readings:
Nov. 6, 2017
Room L1
Introduction to Haskell
  • Basic and compounds types
  • Patterns and declarations
  • Function declarations
  • A digression on the lambda-calculus
Slides: AP-2017-15.pdf, all Suggested readings:
Nov. 7, 2017
Room L1
  • Evaluation orders in lambda-calculus
  • Call by sharing, by name and by need
  • Laziness in Haskell
  • List comprehension
  • Algebraic Data Types
  • Higher-order functions
Slides: AP-2017-16.pdf Suggested readings:
Nov. 9, 2017
Room A1
Exercises on Functional Programming in Haskell Instructions: exercises3.html Students are invited to install the Glasgow Haskell Compiler and Interpreter (GHCI) downloadable from
Nov. 13, 2017
Room L1
  • Recursion and tail recursion
  • Lambdas in Java 8
Slides: AP-2017-17.pdf Suggested readings:
Nov. 14, 2017
Room L1
The Stream API in Java 8 Slides: AP-2017-18.pdf Suggested readings:
Nov. 16, 2017
Room A1
Exercises on the Stream API of Java 8 Instructions: exercises4.html
Software needed for the exercises:
Nov. 20, 2017
Room L1
Type inference in Haskell
Towards Type classes
Slides: AP-2017-19.pdf
AP-2017-20.pdf, up to page 20.
Suggested readings:
Nov. 21, 2017
Room L1
Type classes in Haskell
The Maybe constructor and composition of partial functions
Slides: AP-2017-20.pdf, all. Suggested readings:
Nov. 23, 2017
Room A1
Exercises on the Stream API and on partial functions in Java 8 Instructions: exercises5.html
Auxiliary file: people.csv

Suggested readings:
Use of Optional in Java,

Second programming assignment (with small changes in Exs. 5 and 6 -- Nov 27, 2017).

Nov. 27, 2017
Room L1
Monads in Haskell
Slides: AP-2017-21.pdf, up to page 50. Suggested readings:
Nov. 28, 2017
Room L1
Monads in Java
Scripting Languages
Slides: AP-2017-21.pdf, all. AP-2017-22.pdf, up to page 20. Suggested readings:
Nov. 30, 2017
Room A1
Two hours dedicated to the completion of the exercises on the Stream API and on partial functions in Java 8 proposed last week (exercises5.html) and to the Second Programming Assignment.

Students having completed the above are invited to solve the optional, more challenging exercises of exercises6.html.

Dec. 4, 2017
Room L1
Scripting Languages
Introduction to Python
  • Basic and Sequence Datatypes
  • Dictionaries
  • Control Structures
  • List Comprehension
  • Function definition
Slides: AP-2017-22.pdf, all.
SLIDES/PythonFunction.pdf, up to page 62.
Suggested readings:
Dec. 5, 2017
Room L1
Introduction to Python
  • Positional and keyword arguments of functions
  • Functional Programming in Python
  • Iterators and Generators
  • Using higher order functions: Decorators
  • Classes and Instances
SLIDES/PythonFunction.pdf, all.
SLIDES/PythonFP.pdf, all.
SLIDES/PythonOOP.pdf, up to page 141.
Suggested readings:
Dec. 7, 2017
Room A1
Exercises on Python Instructions: exercises7.html
Auxiliary file: anagram.txt

Suggested readings:
Primer on Python Decorators,
Dec. 11, 2017
Room L1
Lesson canceled because of weather alert.
Dec. 12, 2017
Room L1
The Python Language
  • Single and Multiple Inheritance
  • Magic Methods for operator overloading
  • [Exception handling: just a few words]
  • Modules definition and importing
  • Browsing the standard library.
SLIDES/PythonOOP.pdf, pages 142-201.
SLIDES/AP-2017-24.pdf, up to page 14.
Suggested readings:
Dec. 13, 2017
Room N1
Recovery Lesson
Examples of Scripts in Python

SLIDES/AP-2017-24.pdf, pages 14-20.
Suggested readings:
Dec.14, 2017
Room A1
Exercises on Scripting in Python Instructions: exercises8.html

Suggested readings: