Exams and tests

Getting Ready for a Data Structures Course (CS2) in Java

Published on October 22, 20265 min read

You passed your first programming course, maybe only just. Now the data structures course is coming up, and you suspect that some of the basics never really stuck. That's normal, and you can fix it. In this post you'll find out which gaps cost you the most in CS2, how to spot them in ten minutes and how to close them in four weeks.

What a CS2 course usually covers

There is no single "CS2". Depending on your university or college, the course may be called Data Structures, Programming II, Object-Oriented Programming or simply have a course number. The content differs too. But if you compare course descriptions from different places, the same topics keep showing up:

  • Object-oriented programming in depth: inheritance, polymorphism, abstract classes, interfaces.
  • Generics and the collections framework: lists, sets, maps, iterators.
  • Exceptions, enums, often file handling and unit tests with JUnit.
  • Data structures and algorithms: stacks, queues, linked lists, trees, sorting, recursion.

What exactly is on your course is in the syllabus or course page. Check it before term starts and cross out the topics you won't need. Everything else in this post is deliberately general.

The gaps that hurt most in CS2

CS2 builds on CS1 without repeating it. These five basics are assumed from week one:

  1. Methods with parameters and a return value. If you mix up return and System.out.println, every data structure task will trip you up.
  2. Arrays and loops over indexes. Sorting algorithms consist of little else.
  3. Classes, objects, constructors and this. Without them you won't understand inheritance or a linked list.
  4. References instead of values. Two variables can point to the same object. For objects, == compares references and equals compares content.
  5. Recursion. Trees and many sorting algorithms are recursive. If you can't play through the call stack in your head, this is where you fall behind.

A ten-minute self-test

Before you read on, write down on paper what this program prints:

public class Main {    static void grow(int[] values) {        values[0] = 99;    }
    static void reset(int number) {        number = 0;    }
    static int sum(int n) {        if (n == 0) {            return 0;        }        return n + sum(n - 1);    }
    public static void main(String[] args) {        int[] values = {1, 2, 3};        int number = 7;        grow(values);        reset(number);        String a = new String("Java");        String b = new String("Java");        System.out.println(values[0]);        System.out.println(number);        System.out.println(a == b);        System.out.println(a.equals(b));        System.out.println(sum(4));    }}
Output
99
7
false
true
10

Here's how to score yourself:

  • Got 99? You know that an array is passed as a reference. The method changes the original.
  • Got 7? You know that an int is copied. The change in reset stays local.
  • Got false and true? You know the difference between == and equals. There's more on that in the chapter on Strings.
  • Got 10? You can trace recursion: 4 + 3 + 2 + 1 + 0.

Every wrong line points to a topic you should review before CS2. Output questions like these are also popular in exams. How to practise them systematically is in "What does the program print?": how to practise the exam question.

A four-week plan

Plan on 30 to 60 minutes a day, five days a week. That fits into a break between terms, even next to a part-time job.

Week 1: methods, arrays, strings

Review Methods and recursion and write two or three small methods every day: the maximum of an array, a word reversed, a check whether a number is prime. What matters is that you write each method yourself and try it with several inputs.

Week 2: classes and inheritance

Read Classes and objects and then Inheritance and interfaces. Build a small class hierarchy, for example Shape with Circle and Rectangle, and calculate areas through an interface. That way you see polymorphism in action before it comes up in lectures.

Week 3: collections, exceptions, generics

Work through Lists and maps, then Exceptions and enums. Count the words in a text with a Map<String, Integer>, for example. Then you already know generics from practice before you write generic classes of your own.

Week 4: first algorithms and data structures

Start with simple sorting and recursion and backtracking. Implement bubble sort and insertion sort yourself and walk through them on paper with an array of five numbers. If you still have time, take a look at stacks, queues and linked lists.

If you notice that the gaps are bigger, take a step back. Our post on the right order for learning Java topics shows what builds on what.

How to practise so it sticks

Reading alone isn't enough. These rules make the difference:

  • Write it yourself. Following someone else's code feels like understanding. Only when you can write it without a template do you know it has stuck.
  • Predict first, then run. Before each run, think about what should come out. If the result is different, you've learned something.
  • Know the common mistakes. Each of our lesson articles ends with a "Common mistakes" section. Read it before you solve the tasks.
  • Practise without autocomplete, too. Many programming exams are still written on paper, depending on your course. Tips for that are in Java exams on paper: practise writing code without an IDE.

How Jario helps with the step up

Jario is built for exactly this gap. The Java basics course goes from your first output to streams and generics in 12 chapters. You can jump straight into the chapter that gave you trouble in the self-test. After that, the Algorithms in Java course takes over: 8 chapters on searching, sorting, recursion, trees, heaps, hashing and graphs, which are typical CS2 topics.

You check every task against tests with "Check". If you get stuck, the AI tutor gives you hints in small steps without giving away the solution. It knows the task, your code and the test result. You can switch off autocomplete in the editor when you're practising for a paper exam. And because everything runs in the browser, you don't need a JDK set up.

In short

Take the self-test, note your gaps and work through them with the four-week plan. Once methods, classes, references and recursion are solid, CS2 is no longer a fresh start but the continuation of something you can already do. In Jario you can start right in your browser with the chapter you need most.