
This page is dedicated to the the book:
E. Ageenko "Object Oriented Programming with Java", University of
Joensuu, 2003.
It features:
Install Java 2 Standard Edition JDK 1.4.2 or newer!
First Java demonstration program to test your Java installation [Hello.java]
Compile it:
javac Hello.javaRun it:
java Hellojava Hello Ivan
Simple application that list folders within given path: [FolderLister.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.
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.
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 int1024or float1024.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).
tio library
(for ADVANCED USERS!):tio subfolder of your
projectThis 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!