Module description

This site contains the up-to-date course material, exercises and announcements about PRC2 (Programming Concepts 2: the Test Driven Way), starting in February 2020.

Responsible Teachers for 2020: PRC2: Pieter van den Hombergh, Richard van den Ham, and Linda Urselmans.

Study materials

  • For the Java basics and advanced features we are uisng Cay Horstmann’s fine books from the core Java series. They are on the book-list from September.

  • For The testing part we recommend the book Unit Testing with JUnit and Mockito by
    Tomek Kaczanowski.

  • For the theory parts we will mainly use the Oracle Java Tutorials.
    The exercises will be published on this site.

  • "Using frameworks for testing" will start with using AssertJ, which is a modern and up to date Open Source testing framework. The documentation is of excellent quality and fun to read.

  • For "serialisation to and from JSON" (week 6) we will use Gson, which also has good documentation and some YouTube videos of Gson by Future Studio.

  • For "GUI testing" we will use TestFX. The documentation is a bit lacking, but MVPjava provides some videos on both testing with TestFX and using JavaFX with multiple controllers to develop nice User interfaces.

Study the theory and do the tutorials before you come to class. This will make the lessons more effective for you, because the questions that you might have from studying could be answered immediately.
Studying is not glancing over some (web) pages, but experimenting with the compiler, IDE and other tools, to see if you can use the presented ideas and apply it in your own code.

1. Getting Started

To work successfully with the programs needed for PRC2, you need to install them first. Properly installing Java and other programs is not hard but must be done precisely. What will follow is a description on how to do that under Ubuntu Linux, which is my preferred way of working and will give you the best user experience. You can adapt this configuration for other operating systems too, possibly with a few tweaks.

It is best to get fairly familiar with the command line pretty soon, because in the end it will make you much more effective. Since 2018, bash is also available on Windows 10, and it is the default shell on both OS-X and Ubuntu-Linux.

Before you install any software from the internet, please validate the the package. You typically see signature files such as SHA-256 or PGP-ASC, os something similar, which can help to ascertain that the package is the one you think it is.
For instance with sha512sum ~/Downloads/ you can check the download of that version of netbeans, and the command should produce the same signature as is available on the download website.

2. Install Java and adapt PATH.

The default installation directory for Java on debian based Linuxes, such as Ubuntu is /usr/lib/jvm. On other systems it may vary, under windows do NOT use Program Files, because of the space in the name, but instead create a separate directory simply called e.g. c:\usr\lib\jvm if you insist on using MS-Windows. TODO OS-X?

Fetch the Java distribution from AdoptOpenJDK and choose the distribution/version of choice. For PRC2 we will use Java 11 as a minimum, but you may want to pick up Java 8 for older projects and maybe Java 13 (or even Java 14 when it becomes available) too. Choose the proper platform, download it to your Download folder and unpack the distribution in the installation directory, /usr/lib/jvm under Ubuntu, adapt for your OS.

In the example below we assume that the distribution is packed as a tar.gz archive. The example shows the archive name as of 3 December 2019, OpenJDK11U-jdk_x64_linux_hotspot_11.0.5_10.tar.gz

unpack java distribution using the commandline
sudo mkdir -p /usr/lib/jvm
cd /usr/lib/jvm
sudo tar xf ~/Downloads/OpenJDK11U-jdk_x64_linux_hotspot_11.0.5_10.tar.gz

2.1. Make Java available on the PATH

The $PATH environment variable is used by the command line processor to find the commands or programs whose name you type as first word in a command line. If you type java -version, and your bash says command not found, then your path does not include the java program yet.

Since we want the best Java experience, we will use some common environment variables.

  • JAVA_HOME Define JAVA_HOME first. That will help Java, but also tell other programs to find the desired Java version.
    Set it with export JAVA_HOME=/usr/lib/jvm/jdk-11.0.5+10.

  • PATH Prepend the directory under JAVA_HOME to your path, so all java related programs, such as java , javac, jar etc can be found, by just typing the name.
    Append it by doing export PATH=${JAVA_HOME}/bin:$PATH.

To avoid having to do this every time you start the command-line, add the command to your ~.bashrc script file, at the bottom.

add these lines to your startup script
export JAVA_HOME=/usr/lib/jvm/jdk-11.0.5+10
export PATH=${JAVA_HOME}/bin:$PATH

2.2. Install Apache Maven

We will use Apache Maven, or maven for short throughout the PRC2 course, so you will need that too.

The application is called Maven but as command spelled as mvn.

Maven is the default build tool in the Java world and can build your program from sources without the use of and IDE. This makes your project agnostic to the IDE used, so they work with NetBeans as first class projects out of the box and also with other IDEs with little or no tweaks to that IDE. It is also the way the teachers use to compile and test the students work for the practical assignments and performance assessments.

Fetch a fresh copy of Apache Maven from the website.

To install it, do (example uses version 3.6.3 as of 2019-11-03)

install apache maven and add to path
cd /usr/share
sudo rm -fr maven
sudo tar xf ~/Downloads/apache-maven-3.6.3-bin.tar.gz
sudo ln -sf apache-maven-3.6.3/ maven
cd /usr/bin
sudo ln -sf ../share/maven/bin/mvn .

Once this is done, entering mvn --version should produce output similar to

mvn --version command.
hom@threehundred: /usr/share
🐧$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/share/maven
Java version: 11.0.5, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk-11.0.5+10
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "5.0.0-36-generic", arch: "amd64", family: "unix"

TODO: Adapt for windows.

2.3. Install or update your IDE

The official Java IDE at Fontys ICT Venlo is Apache NetBeans IDE. The long time stable version for the moment is 11.0. At the time of writing version 11.2 serves me very well. At the time of reading a newer version might be available.

To install Apache NetBeans on Ubuntu simply fetch the binary as zip file and unpack it, then either add the contained bin directory to the path, or make a wrapper netbeans command in your personal ~/bin directory.

For my installation I simply used the binaries, in the zip file, and install it in the traditional (as in same directories as the installer would) /usr/local.

Assuming you downloaded the binary, installing it is easy
cd /usr/local
sudo unzip ~/Downloads/
sudo mv netbeans{,-11.2}

For extra creature comfort, add a simple netbeans script to your path

netbeans script in ~/bin
cd ~/bin
cat - <<EOF > netbeans
/usr/local/netbeans-11.2/bin/netbeans \$* &

chmod +x netbeans

Copy the above and paste it in the terminal.

NetBeans IDE should now be startable from the command line (fine for me) as well as from the menu.

2.3.1. Other IDE’s

This section is left empty. We have enough work as it is, but if you have any tips, we are quite willing to share them using these pages.

3. Configuring Maven

Maven and maven projects are first class citizens in the NetBeans world.

Since we build with maven, we are not really bound to particular IDE, other than for editing and maybe the odd debug session.[1]. This means that you can use other IDE’s, but expect no help from the teachers.

We have many things to share with you, and we use maven for that.

We share libraries and project configuration files (pom.xml) with our students. To make them work as intended, you will need to configure the maven settings.xml only once. Since this is a maven setting, your IDE should pick these settings up as well. Certainly NetBeans IDE will.

Start NetBeans IDE and create a Java project with New Project ▷ Java with Maven ▷ Java Application.

In the project, right click on Project Files and choose create settings.xml. Add the Fontys Venlo repository to the settings, which is best done by replacing the xml in the settings file with

settings.xml which adds as repository
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns=""
        <profile>  (1)
                    <id></id> (2)
                    <url></url> (3)
        <activeProfile>sebivenlo</activeProfile> (4)
1 You define a profile inside the profiles section of your settings.xml.
2 Give the profile a name.
3 Specify the URL.
4 Use the given name to make it an active profile by default.

3.1. Using the SeBiPom in your own projects

To use the test libraries and other goodies that wiil be used throughout our course, you should add the sebipom and kind of super-pom (yes, thinking super class is not far off).

Modify the pom.xml file in your project to include sebipom as parent by adding these lines to the pom file:


4. Topics 2019

Focus points in the weeks ahead: . week 1 Testing, JUnit5, assertJ .. comparator will be a big part here? .. experiment with various comp. impls inside test class. .. use sorting as example. assertThat(x).containsExactly(…​) and assertThat(x).containsExactlyInAnyOrder() .. looking at assertThat().extract…​ .. more exercises needed. .. main exercise: fraction (), need more simpler ones. . week 2 lambda . week 3, need simpler in the pub. Also needs try with resources. (A tap is AutoClosable?).

Week Topic Exercises


Test Driven, Unit Testing basics, using coverage

Two Stacks, Fraction


Testing and using Exceptions

In the pub, Shopping cart


Test Driven, how do you actually do that?

Password validator, Booking system


Enums & Generics

Boxes, Shapes, Drinkers


Lambda Expressions

Comparator, Calculator


Java 8 Streams



Java FX Bindings



Object serialisation using JSON



Advanced Testing testing: Mocks and Parameterised Testing



State machines /Regex/



Java Reflection





You should start with the exercises in the week they are listed in and hand them in by committing your work to your personal subversion repository before the start of next week’s lesson. There will be no new exercises in the final lesson week.

5. Way of Working during practical hours.

tdd The way of working with the practical assignments is as follows:

  • Each student has a personal subversion repository

  • The teachers will add the starter project for the assignment in due time
    to all student repositories, which are then available for checkout by the students

  • The students will work on the assignment and work TDD style.

    • Write a test for a requirement (typically a method),
      see it showing failure (RED),

    • then implement the method to turn the test GREEN.

    • If GREEN, svn-commit both test-class AND implementing class.

  • If the assignment is complete (all requirements covered with tests, all tests green and code coverage at an appropriate level ) ask any of the teachers or student assistants to run the teachers test on your code.

    • The teachers will not explicitly test your tests, only your implementation code, but will provide you with the test report.

    • They will run your tests, to see if your test report is in agreement with the teachers tests.

This procedure is similar to the one followed during the performance assessment at the end of the semester. The difference is that we will review not only the implementation, but will start with reviewing the tests. If there is no valid test, the implementation of the method will not be considered.

6. Slack channel(s)

For questions and answers thus documenting them and also discussions and explanations, sharing information, links and other things between students and lecturers, feel free to use the slack channel: Slack invitation link.

Please use the channel #prc2class. We will use this channel to ask and and answer questions during and after class.

Please note that the content of this channel will appear on youtube because we are recording the lectures. So use proper language.

You are only allowed to use a email address. Using slack is optional, but if the students share their knowledge there, this can be a helpful source and learning environment.

7. Automatic correction of practical exercises.

In PRC1 you have become acquainted with automatic tests. In PRC2 you will not only write the implementation, but also the tests. These test need testing too.

The approach follow is having not only a correct implementation, but also some broken implementations to test your tests.

The exact details are spelled out in the rules for the performance assessment.

In short you provide your own test code and implementation, we provide an implementation, our own tests and some broken implementations to make your tests have a nice red blush.

The ubiquitous question is always: Where do I start?

The answer is surprisingly simple: at the requirements of class, method or whatever you want to develop. And always start at the simple end. So if a requirement says that a fresh Stack is empty, that means you can write a test that asserts that a new instance of your class reports that it is empty when the isEmpty() is called.

1. Working test driven will typically not need those