Skip to content

Repository files navigation

Java Programming: Ally's Tutorial Questions

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.

When are these tutorials?

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!

When should I attempt each question?

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.

Reporting errors

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.

If you get stuck

  • 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.

Question labels, dependencies and tags

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.

The questions!

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.

LabelNameTopic tag(s)Depends onSolution
98e3... 1 4 2 1 4 2 1 ...RecapSolution
f79bPerfect palindromic cubesRecapSolution
4c70Lottery numbersRecapSolution
014eRandom numbersRecapSolution
2d33Reversed order of inputRecapSolution
f7c3Pig LatinRecapSolution
67ddWord countRecapSolution
7ec8Battling fightersRecap, SimpleObjectsSolution
8d24Lucky battling fightersRecap, SimpleObjects7ec8Solution
bec2Music collectionRecap, SimpleObjectsSolution
c2b8Irresponsible rectangleSimpleObjectsSolution
d363Bloated personSimpleObjectsSolution
7206Understanding referencesSimpleObjectsSolution
937dFlawed rectangleSimpleObjectsSolution
bdb4Flawed houseSimpleObjectsSolution
0378Comparing peopleInterfacesSolution
6346Depth of arithmetic expressionsInterfacesSolution
e6fdBit setsInterfacesSolution
fe94Using Stream.map and Stream.filterFunctionalSolution
68e6Using Stream.reduceFunctionalSolution
0f05Coloured pointsInheritanceSolution
dd4cClocksInheritanceSolution
8f65Lucky battling fighters with inheritanceInheritance8d24Solution
845dBooks and dictionariesInheritanceSolution
e93fApparent and actual typesInheritanceSolution
d3f5Streams and downcastingFunctional, Inheritance, GenericsSolution
5235Equality between pointsObjectEquality0f05Solution
710cThe consequences of overriding equalsObjectEquality5235Solution
aa68Symmetric equality testingObjectEqualilty5235Solution
0c21PropertiesAbstractClassesSolution
236bFields for propertiesAbstractClasses0c21Solution
5981ShapesAbstractClassesSolution
dc38Email management systemAbstractClassesSolution
1486String stackInterfacesSolution
8a61Int setInterfaces1486Solution
85bbString stack iteratorsAbstractClasses, Interfaces1486Solution
a6e7Int set iteratorsAbstractClasses, Interfaces8a6185bbSolution
2ffcGeneric stacksGenerics1486Solution
b401Generic setsGenerics8a61Solution
336bEvolving the Set interfaceInterfaces, Advancedb401Solution
17b1Default methodsInterfaces, AdvancedSolution
96dfTree nodesGenericsSolution
7041Cloning tree nodesGenerics96dfSolution
888aGeneric methods with streamsGenerics, Functional68e6Solution
11e2Bounded generic methods with streamsGenerics, FunctionalSolution
c822Problems cloning tree nodesAdvanced7041Solution
735aGeneric iteratorsGenerics85bba6e7b401Solution
876bGenerics and subclassesGenerics, InheritanceSolution
1aebGeneric number manipulationGenericsSolution
b4a5Observing the garbage collectorMemoryManagementSolution
1ae9Reusing immutable value objectsMemoryManagement0f05Solution
290bMemory leaks in JavaMemoryManagement, AdvancedSolution
5566Exception-throwing stacksExceptions1486Solution
a22cNo duplicate email addressesExceptionsdc38Solution
e093Average of numbersExceptionsSolution
7e2aStack overflowExceptionsSolution
30cdHeap exhaustionExceptionsSolution
74d2Exceptions and inheritance (i)Exceptions, InheritanceSolution
2862Exceptions and inheritance (ii)Exceptions, InheritanceSolution
153dExceptions and inheritance (iii)Exceptions, InheritanceSolution
5d30Unreliable buffered readerExceptionsSolution
1171Cloning graphsAdvancedSolution
f763Simulating garbage collectionAdvancedSolution
9a9bTransposing tunesAdvancedSolution
b33fLogging using a functional interfaceAdvanced888aSolution

More hex strings

When I am gone, if someone wants to add more questions then please consume the remaining hex strings here.

About

Tutorial Questions for the Programming II course at Imperial College London

Resources

Stars

53 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages