SE251:Java Exercise Bank
Jump to navigation
Jump to search
Welcome
The purpose of this page is to provide offline programming exercises to supplement the assignments. There has been a large volume of interest from the class in getting more hands on with Java programming. So here's an attempt to address this. These exercises do not contribute to your final assessment, but you can get official help with them from the lecturers and tutors (we'll try our best to help anyway :). Of course, you are strongly encouraged to discuss among yourselves on this Wiki.
Exercises
Watch this space. I am gradually going to build this page up. Feel free to add your own suggestions as well.
Exercise | Level* | Summary |
---|---|---|
String manipulation and StringBuffers | 2 | Explore useful String operations, including comparison, substring, regular expressions, tokenising and more. Also effeciently building Strings using StringBuffer. |
Reversing file contents | 1.5 | Read lines from a file and print them in reverse. The file is specified through the console. |
A Simple File Shell | 3 (4 with optional) | Create, delete and list directories and files directly through Java. |
Writing a generic Pair<E1,E2> | 2 | Write a generic class Pair for holding two objects of parameterisable types, e.g. Pair<Date,Money>. |
Writing a Chain<E> datastructure | 2.5 | Write a special data structure called Chain, which retains the ordering of elements (like a List) but only allows at most one instance of each element (like a Set). |
Writing set operations | 2 | Write operations for computing the union, intersection, difference and cartesian product between two Set objects. |
Writing a MultiMap<K,V> datastructure | 3 | Write a special data structure called MultiMap<K,V>, which stores a mapping from a single key to a set of values. Useful for implementing a many-to-many relationship. |
A simple differencing tool | 3 | Write a simple differencing tool that works out the difference between two files A and B each containing a list of Strings separated by line breaks. |
*Levels (1=easiest, 5=hardest) are only a rough subjective guide to how much work the exercise may involve.
Quick dirty guide to some quintessential Java packages/classes
- package java.lang: alternative link - outside of UoA:
- Object - well, what can I say. You may find yourself overriding
equals()
andhashcode()
- String, StringBuffer - everything relating to text
- Number and friends (Integer, Boolean, Double, etc) - for wrapping primitive types
- Math - mathematical functions such as squre root, log, cosine, power, max, min, etc.
- System - the almighty
out.println()
, alsocurrentTimeMillis()
- Object - well, what can I say. You may find yourself overriding
- package java.io: alternative link - outside of UoA:
- File - represents files or directories in your actual file system
- FileFilter - useful for listing only specific files, e.g. files ending with ".java"
- XXXReader, XXXWriter - many different implementations for reading from and writing to various sources
- XXXInputStream, XXXOutputStream - many different implementations for reading from and writing to various streams
- package java.util: alternative link - outside of UoA:
- ArrayList, LinkedList - implementations of the List data structure
- HashSet, TreeSet - implementations of the Set data structure
- HashMap, TreeMap - implementations of the Map (aka Hashtable/dictionary/etc) data structure
- Collections, Arrays - provide useful algorithms (e.g. sorting, searching, max, min) to perform over Collections and Arrays
- Date - represents time, surprise surprise
- package java.awt.* alternative link - outside of UoA:
- More on this later...
- package javax.swing.* alternative link - outside of UoA:
- More on this later...