Book cover

"OOP with Java" Companion Site.

This page is dedicated to the the book:
E. Ageenko "Object Oriented Programming with Java", University of Joensuu, 2003.

It features:


NOTE: Sun Java 1.4.2 Run-time environment is required to run the samples!
The applets will not run with Microsoft Java Virtual Machine.

Have problems running applets?

Get Java!

Would you like to develop in Java?

Install Java 2 Standard Edition JDK 1.4.2 or newer!


SAMPLES

Simple Applications (see docs):

First Java demonstration program to test your Java installation [Hello.java]

Compile it:
javac Hello.java
Run it:
java Hello
java Hello Ivan

Simple application that list folders within given path: [FolderLister.java]


Input in Java:

There is no standard easy way to organize input of program parameters in Java. In order to help you there are the following alternatives. The javadoc documentation for the examples and first two alternatives is found here. The documentation for tio library is here.

1. Input using pop-up windows (for VERY BEGINNERS!):

This library is used to input primitive data type values via simple Swing dialog box. It supports the following types: int, char, String, float and boolean. If a wrong input is given, it automatically asks to repeat the input.

2. Input using wrapper classes (but not exceptions):

This library performs input from a console on a line and token basis. The functionality it poses is: (a) to read one line of the input (all characters until end-of-line) into a String, (b) read one line of input and extract tokens (words separated by white space) into array of Strings, (c) parse tokens (words) into primitive data types.

The library hides exceptions from the user. Instead it uses wrapper classes to store input values. If the input was not successful or there were any parsing errors (e.g. attempt to parse string "abc" to integer) the library returns null, otherwise an object of the appropriate wrapper class is returned.

Example:

In the input line The number 1024, there are three tokens "The", "number", and "1024". Last token can be parsed to int 1024 or float 1024.0. In the first case, an object of Integer class is returned. The value can be obtained using its intValue() method.

You can use this library also for parsing command-line arguments if you do not want to worry about exceptions (method Integer.valueOf(String) casts NumberFormatException).

3. Input via tio library (for ADVANCED USERS!):

This library defines a class Console, which creates two streams: Console.in and Console.out. These two can be used in absolutely the same fashion as System.in and System.out, however they offer advanced functionality.

The stream Console.in has methods that allow for simple input of numbers, strings and characters from a text stream (e.g. int readInt() method). The methods reading numeric values behave in the same fashion as the C-methods. They attempt to interpret the input as appropriate data type. If this attempt fail, the methods do not read the input data (!) but cast java.lang.NumberFormatException. Also, input does not limited to a single line (advantage over stdio library)

The stream Console.out has additional methods (out.printf(...) and out.printfln(...)) that perform formatted printing. It also includes support for setting the width of the output field, using left or right justification in the output field, using an arbitrary fill character, and setting the number of digits to the right of the decimal point in floating point values. Methods out.print(...) and out.println(...) behave naturally.

This library does not use wrapper classes (well, it uses them internally for parsing data), but relay on the use of exceptions for indicating erroneous situations!


*** NEW *** Sample BlueJ projects:

  1. Greet
  2. Dog

Applets (see docs):

  1. Applet with GUI: CaseConverter
  2. Applet illustrating event handling: MouseLocation
  3. Applet illustrating painting: ClickMe
  4. Applet illustrating absolute positioning of the components: RunningButton
  5. Applet illustrating event consuming: EventConsuming
  6. Applet illustrating design that minimize coupling (components are as independent of each other as possible): BoardApplet
  7. Applet illustrating design of own (lightweight) visual components: Playground
  8. Applet illustrating event dispatching techniques and creating advanced custom components: BrickButtonDemo

New Applets:

  1. Collection of basic Swing widgets
  2. Button Click Counter (button and label): AWT and SWING versions
  3. Button Click Counter: Using graphic text representation
  4. Simple HTML browser

A simple OOP project - PlayBalloon:

  1. PlayBalloon applet (basic)
  2. PlayBalloon 2 applet (advanced)
  3. Source code (just unzip it)
  4. Design strategy and diagrams (PDF, 140K)
  5. Documentation (javadoc, HTML)

Documentation (javadoc):

  1. JavaDoc documentation for simple application, selected solutions, and utility classes
  2. JavaDoc documentation for tio package
  3. JavaDoc documentation for the applets
  4. Java AWT GUI Tutorial is accessible locally here
  5. Java API On-line Help (v.1.4.2, from SUN Microsystems)