Why Not Try: Free On-line Java Tutorials |
![]() |
![]() |
The following tutorials were written by Davin Pearson as
supplementary material to the University of Canterbury COSC121 course teaching the
Java language. At the top of each tutorial is a hyperlink to a
model answer, but don't look at the answer until you have completed
all the questions of the tutorial!
DISCLAIMER: These tutorials were not developed by TEAM COSC and are independent any COSC course. They are soley intended as a study aid. When you have finished the tutorials, check out my website: www.davinpearson.com
|
![]() |
Number | File(s) | Notes |
---|---|---|
1 | PersonTest.java |
Contains a simple class Person for representing the
concept of a human being, and a driver class
PersonTest .
Key concepts:
|
2 | CitizenTest.java |
Contains a class Citizen for storing a person's
financial information including their salary, savings
and loan (if they have one). Tax is paid by the citizen
and a class called Government is used to keep track
of the total tax paid. The classes are driven by
CitizenTest .
Key concepts:
|
3 | DogTest.java |
An example involving three classes Flea , Dog and
DogOwner to represent the idea that a dog has a flea
and a dog-owner has a dog. The class DogTest is the
driver class.
Key concepts:
|
4 | RunnerTest.java |
Two classes SportsShoe and Runner for modelling
runners and their shoes, together with a driver class
called RunnerTest .
Key concepts:
|
5 | StaticTest.java ,StaticTest2.java . |
This tutorial attempts to convey the meaning of the
static keyword by showing firstly an example
StaticTest.java where static is used and then
secondly an example StaticTest2.java which is the
same example with static removed.
|
6 | ForTest.java |
This tutorial gives you practice in writing
for loops. A for loop has the following
structure:
for (Init-part; While-part; Increment-part) Body-partThis tutorial shows you how the different parts of the for loop affect the behaviour of the loop.
|
7 | LoopTest.java |
Java's three different looping constructs: for ,
do and while . This tutorial takes you through
the process of rewriting a for loop into a do
loop and a while loop.
|
8 | ScrabbleTest.java |
String manipulation. Useful methods to remember are
length() for getting a string's length, and
charAt(NNN) for inspecting the character at location
NNN in a string.
|
9 | ArrayTest.java ,ArrayTest2.java |
Arrays. There are two kinds of arrays: arrays of
references, and arrays of the built-in types. The
built-in types are: int , long , short ,
byte , float , double , char and
boolean .
The file |
10 | CarTest.java . |
Advanced tutorial involving two classes Car , and
Driver for representing automobiles and their
owners, respectively. Also the class CarTest is
used for testing the other two classes.
WARNING: Difficult tutorial. |
11 | TurtleTest.java |
Linked lists. Dr Seuss' story Yurtle the Turtle
describes how a turtle called Yurtle sits at the top of
a pile of other turtles. In this example, the pile of
turtles is represented by a linked list of Turtle
objects, with the up field serving to connect one
Turtle object to another. If a Turtle object
has a non-null up field, then this represents a
turtle that is sitting on top of the current one. The
last turtle in the linked list is the turtle that is at
the top of the pile.
WARNING: Difficult tutorial. |
12 | InheritTest.java |
Theoretical example of inheritance. The file
InheritTest.java contains four classes: Animal ,
Bird and Eagle and a tester class
InheritTest . Class Bird inherits from Animal
and class Eagle inherits from Bird .
The main thing that this tutorial shows is the idea that
inheritance is a non-symmetrical relationship. For
example: the |
13 | StarWars.java |
Practical example of inheritance.
The file StarWars.java is comprised of three
classes: XWing , TieFighter and StarWars .
The first two represent spacecraft from the two sides of
the Star Wars films. The class StarWars
is the driver class and contains code for executing
a battle between the X-Wings and the Tie Fighters.
The tutorial shows how inheritance can be used to reduce the amount of duplication of code. |
14 | AnimalTest.java |
Arrays, inheritance and polymorphism. |