The best way to learn a programming language and the concepts that underlie the language's design is to do lots of programming.
The aim of these tutorial questions is to give you the opportunity to write, inspect, debug and play with a bunch of reasonably small programs. There are quite a lot of questions, they form part of the examinable material for the course, and thus I strongly encourage you to attempt all of them.
I also encourage you to explore your own variations of and extensions to the tutorial questions. Think of extra features you could add to some of the programs, and try to add them.
There aren't any. I'm calling them "tutorial questions", but really the questions are for your own self-study. I won't be running tutorial sessions during my part of the course; instead we will do lots of live coding in class. While I might touch on a few of these questions, the vast majority of them won't be discussed. Similarly, your programming tutor or undergraduate teaching assistant might choose to go over some of these questions during PPT sessions, but they are not part of the core material to be covered in PPT groups.
So, once again: do try out all the questions in your own time before the final test!
The questions are presented in a reasonably logical order, but this order might not match exactly the order we cover material during the lectures. I suggest that you try out each question as soon as you feel you've learned enough to have a stab at it. I've indicated using links where there are dependencies between questions, and have tagged each question with one or more topic areas.
For everyone's benefit (including the benefit of future students), please email me (afd) if you find errors in these sheets or the sample solutions.
- Ask me for help after lectures and tutorials
- Attend the lab sessions and ask the lab helpers for advice
- Send me an email (afd)
However, before you ask for help do make sure you have spent a significant amount of time scratching your head and thinking about your problem, and looking for solutions in the lecture notes and other available sources. You will likely learn a lot by really trying to figure things out for yourself. If you are still stuck after this then I, and the others involved in the course, will be very happy to help.
Each question is labelled with a 4-digit hex identifier, e.g. 98e3.
Some of the questions depend on other questions; I have indicated wherever this is the case, linking to the prerequisite question.
To help you decide how you should prioritise working through the questions, I have attached one or more tags to each question in the list below. The tags are as follows:
- Recap: focuses on recapping basic imperative concepts of Java: loops, recursion, variables, arrays and enumerations.
- SimpleObjects: covers basic use of objects (with little or no use of interfaces, inheritance, etc.).
- Interfaces: covers concepts relating to Java interfaces.
- Functional: focuses on functional programming features of Java: streams, lambdas and method references.
- Inheritance: covers the design and implementation of subclasses.
- AbstractClasses: focuses on using abstract superclasses to share common state and methods among subclasses.
- Generics: focuses on building generic containers, and on technical aspects of Java generics.
- Exceptions: covers handling unexpected program behaviours using Java's exception mechanisms.
- MemoryManagement: explores the stack, heap and garbage collector.
- Advanced: Challenging questions that bring together many concepts covered during my part of the course. If you can solve these questions using only the hints provided then you are doing very well! You might prefer to work through these questions referring to the sample solutions along the way.
You can access the questions via the table below. Solutions are provided for all questions, and code solutions for all questions are available at solutions/code
.
It is totally up to you when to look at these. I suggest you attempt each question without reference to its solution, and start to peek at the solutions when you get stuck, or when you believe you have made good progress on a question.
Much of Object Oriented Programming is not an exact science: there is a lot of room for creativity, and when designing an application one often has to make a choice between multiple imperfect approaches, each with different pros and cons.
As a result, you will likely find that some of your answers differ from the sample solutions. When this is the case, think hard about whether the sample solution is better than your solution, whether your solution is better than the sample solution, or whether they are both viable alternatives.
I'm very happy to discuss alternative solutions. Also, please get in touch if there are parts of the solutions that you do not understand, of if you spot errors.
Label | Name | Topic tag(s) | Depends on | Solution |
---|---|---|---|---|
98e3 | ... 1 4 2 1 4 2 1 ... | Recap | Solution | |
f79b | Perfect palindromic cubes | Recap | Solution | |
4c70 | Lottery numbers | Recap | Solution | |
014e | Random numbers | Recap | Solution | |
2d33 | Reversed order of input | Recap | Solution | |
f7c3 | Pig Latin | Recap | Solution | |
67dd | Word count | Recap | Solution | |
7ec8 | Battling fighters | Recap, SimpleObjects | Solution | |
8d24 | Lucky battling fighters | Recap, SimpleObjects | 7ec8 | Solution |
bec2 | Music collection | Recap, SimpleObjects | Solution | |
c2b8 | Irresponsible rectangle | SimpleObjects | Solution | |
d363 | Bloated person | SimpleObjects | Solution | |
7206 | Understanding references | SimpleObjects | Solution | |
937d | Flawed rectangle | SimpleObjects | Solution | |
bdb4 | Flawed house | SimpleObjects | Solution | |
0378 | Comparing people | Interfaces | Solution | |
6346 | Depth of arithmetic expressions | Interfaces | Solution | |
e6fd | Bit sets | Interfaces | Solution | |
fe94 | Using Stream.map and Stream.filter | Functional | Solution | |
68e6 | Using Stream.reduce | Functional | Solution | |
0f05 | Coloured points | Inheritance | Solution | |
dd4c | Clocks | Inheritance | Solution | |
8f65 | Lucky battling fighters with inheritance | Inheritance | 8d24 | Solution |
845d | Books and dictionaries | Inheritance | Solution | |
e93f | Apparent and actual types | Inheritance | Solution | |
d3f5 | Streams and downcasting | Functional, Inheritance, Generics | Solution | |
5235 | Equality between points | ObjectEquality | 0f05 | Solution |
710c | The consequences of overriding equals |
ObjectEquality | 5235 | Solution |
aa68 | Symmetric equality testing | ObjectEqualilty | 5235 | Solution |
0c21 | Properties | AbstractClasses | Solution | |
236b | Fields for properties | AbstractClasses | 0c21 | Solution |
5981 | Shapes | AbstractClasses | Solution | |
dc38 | Email management system | AbstractClasses | Solution | |
1486 | String stack | Interfaces | Solution | |
8a61 | Int set | Interfaces | 1486 | Solution |
85bb | String stack iterators | AbstractClasses, Interfaces | 1486 | Solution |
a6e7 | Int set iterators | AbstractClasses, Interfaces | 8a61 85bb | Solution |
2ffc | Generic stacks | Generics | 1486 | Solution |
b401 | Generic sets | Generics | 8a61 | Solution |
336b | Evolving the Set interface | Interfaces, Advanced | b401 | Solution |
17b1 | Default methods | Interfaces, Advanced | Solution | |
96df | Tree nodes | Generics | Solution | |
7041 | Cloning tree nodes | Generics | 96df | Solution |
888a | Generic methods with streams | Generics, Functional | 68e6 | Solution |
11e2 | Bounded generic methods with streams | Generics, Functional | Solution | |
c822 | Problems cloning tree nodes | Advanced | 7041 | Solution |
735a | Generic iterators | Generics | 85bb a6e7 b401 | Solution |
876b | Generics and subclasses | Generics, Inheritance | Solution | |
1aeb | Generic number manipulation | Generics | Solution | |
b4a5 | Observing the garbage collector | MemoryManagement | Solution | |
1ae9 | Reusing immutable value objects | MemoryManagement | 0f05 | Solution |
290b | Memory leaks in Java | MemoryManagement, Advanced | Solution | |
5566 | Exception-throwing stacks | Exceptions | 1486 | Solution |
a22c | No duplicate email addresses | Exceptions | dc38 | Solution |
e093 | Average of numbers | Exceptions | Solution | |
7e2a | Stack overflow | Exceptions | Solution | |
30cd | Heap exhaustion | Exceptions | Solution | |
74d2 | Exceptions and inheritance (i) | Exceptions, Inheritance | Solution | |
2862 | Exceptions and inheritance (ii) | Exceptions, Inheritance | Solution | |
153d | Exceptions and inheritance (iii) | Exceptions, Inheritance | Solution | |
5d30 | Unreliable buffered reader | Exceptions | Solution | |
1171 | Cloning graphs | Advanced | Solution | |
f763 | Simulating garbage collection | Advanced | Solution | |
9a9b | Transposing tunes | Advanced | Solution | |
b33f | Logging using a functional interface | Advanced | 888a | Solution |
When I am gone, if someone wants to add more questions then please consume the remaining hex strings here.