PDA

View Full Version : Java Exercises


TheBB
06-12-2006, 8:43 AM
These were requested by a forum member here, but I'll put them out in public so anyone can use it. These are the exercises given to me this spring in a Java programming class I took at my uni. It teaches object-oriented programming, and assumes some knowledge about procedural-oriented programming from before.

The exercises are geered towards a Java IDE known as Eclipse, which is an absolutely great tool. In order to set it up, you'll have to do the following.

Download and install a distribution of the Java 2 SDK (http://java.sun.com/j2se/1.5.0/download.jsp).

Download and install Eclipse 3.2 M4 (http://tdt4100.idi.ntnu.no/notater/eclipse-SDK-3.2M4-win32.zip) (yes you need THIS version).

Download this (http://tdt4100.idi.ntnu.no/jexercise/plugins.zip) plugin for Eclipse (JExercise) and copy the files into the plugin directory for Eclipse.

See this (http://tdt4100.idi.ntnu.no/jexercise/tutorial/create-exercise-project.php) page for details on how to create your exercise project. It must be called "ovinger" ("exercises" in norwergian...). You must do this only once.

See this (http://tdt4100.idi.ntnu.no/jexercise/tutorial/import-exercise-archive.php) page for how to import exercise archives. You must do this once for each exercise.

See this (http://tdt4100.idi.ntnu.no/jexercise/tutorial/open-jexercise-view.php) page for how to use JExercise.

If you have followed all the instructions above you are ready to do your thing. There are 9 exercises:

Exercise 1 (http://tdt4100.idi.ntnu.no/oving/oving1/oving1.zip) (procedural programming)
Exercise 2 (http://tdt4100.idi.ntnu.no/oving/oving2/oving2.zip) (classes and objects)
Exercise 3 (http://tdt4100.idi.ntnu.no/oving/oving2/oving3.zip) (constructors and accessor methods)
Exercise 4 (http://tdt4100.idi.ntnu.no/oving/oving2/oving4.zip) (interfaces)
Exercise 5 (http://tdt4100.idi.ntnu.no/oving/oving2/oving5.zip) (interfaces and JUnit testing)
Exercise 6 (http://tdt4100.idi.ntnu.no/oving/oving2/oving6.zip) (inheritance and abstract classes)
Exercise 7 (http://tdt4100.idi.ntnu.no/oving/oving2/oving7.zip) (java collections, iterators and exceptions)
Exercise 8 (http://tdt4100.idi.ntnu.no/oving/oving2/oving8.zip) (files, exceptions and enumerations)
Exercise 9 (http://tdt4100.idi.ntnu.no/oving/oving2/oving9.zip) (observable and observer, GUI with java and swing)

The solution suggestions are here:

1 (http://tdt4100.idi.ntnu.no/oving/lf/oving1/), 2 (http://tdt4100.idi.ntnu.no/oving/lf/oving2/), 3 (http://tdt4100.idi.ntnu.no/oving/lf/oving3/), 4 (http://tdt4100.idi.ntnu.no/oving/lf/oving4/), 5 (http://tdt4100.idi.ntnu.no/oving/lf/oving5/), 6 (http://tdt4100.idi.ntnu.no/oving/lf/oving6/), 7 (http://tdt4100.idi.ntnu.no/oving/lf/oving7/), 8 (http://tdt4100.idi.ntnu.no/oving/lf/oving8/), 9 (http://tdt4100.idi.ntnu.no/oving/lf/oving9/)

Note that personally I believe many of these exercises are irrelevant to learning Java, many are not even fun, and in any case several of the exercises are badly worded also. The idea is that you write your code and have it automatically tested with this JExercise thing, but this doesn't necessarily work all the time.

Also note that these exercises assume you know about what was told in the lectures, which you don't, and the lecture notes are in norwegian anyway. So you would probably have to search the net for some answers (or peak in the solution). I suggest using the Java API (http://java.sun.com/j2se/1.3/docs/api/) once you get familiar with it.

Also note that all these links go to pages on my uni (except the SDK and API), which may become unavailible at any time before this class is taught the next time (in 6 months). Just so you know.

Enjoy programming... :)