Java Training Course/Example Programs: Difference between revisions
Jump to navigation
Jump to search
imported>Gfis No edit summary |
imported>Gfis m →Developper Information: Typo |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
During the training course we developped about 60 Java example programs which use the Java language features to be learned. These programs can all be obtained from the '''Git repository''' for the training course by the command: | |||
git clone https://github.com/gfis/jtc | git clone https://github.com/gfis/jtc | ||
===Start with a greeting=== | ===Start with a greeting=== | ||
* '''HelloWorld''' - output | * '''HelloWorld''' - one-liner: output a greeting | ||
===Arguments, assignment, elementary String and arithmetic operations=== | ===Arguments, assignment, elementary String and arithmetic operations=== | ||
* '''StringAdd''' - concatenate argument strings 4 times and print them out | * '''StringAdd''' - concatenate argument strings 4 times and print them out | ||
* '''IntAdd''' - add 4 integers 4 times and print them | * '''IntAdd''' - add 4 integers 4 times and print them | ||
* '''IntMultiply''' - multiply 4 integers 4 times and print the product | ** '''IntMultiply''' - multiply 4 integers 4 times and print the product | ||
* '''LongMultiply''' - multiply 4 long numbers | ** '''LongMultiply''' - multiply 4 long numbers | ||
===Loops (<code>while, for</code>) and conditions (<code>if</code>), arrays (<code>[]</code>)=== | ===Loops (<code>while, for</code>) and conditions (<code>if</code>), arrays (<code>[]</code>)=== | ||
* '''PowersOf2''' - print the powers of 2 | * '''PowersOf2''' - print the powers of 2 | ||
Line 15: | Line 15: | ||
===Sequences of conditions with <code>switch, if - then - else if ...</code>=== | ===Sequences of conditions with <code>switch, if - then - else if ...</code>=== | ||
* '''Selamat''' - print a greeting depending on the hour | * '''Selamat''' - print a greeting depending on the hour | ||
* '''SelamatSwitch''' - same with <code>switch ... case ... default</code> | ** '''SelamatSwitch''' - same with <code>switch ... case ... default</code> | ||
* '''Number10''' - print the numbers 1..10 | * '''Number10''' - print the numbers 1..10 | ||
* '''Number10Method''' - print the numbers using a class method | ** '''Number10Method''' - print the numbers using a class method | ||
* '''Month''' - print the indonese name of a month | * '''Month''' - print the indonese name of a month | ||
* '''Weekday''' - print the indonese name of a weekday | * '''Weekday''' - print the indonese name of a weekday | ||
===Sequences of words=== | ===Sequences of words=== | ||
* '''Word1''' - print all words with 1 letter | * '''Word1''' - print all words with 1 letter | ||
* '''Word2''' - print all words with 2 letters by 2 nested loops | ** '''Word2''' - print all words with 2 letters by 2 nested loops | ||
* '''Word3''' - print all words with 3 letters | ** '''Word3''' - print all words with 3 letters | ||
* '''Word3Cond1''' - print words with 3 letters and vowel/consonant conditions, first version | * '''Word3Cond1''' - print words with 3 letters and vowel/consonant conditions, first version | ||
* '''Word3Cond2''' - same, using a method, 2nd version | ** '''Word3Cond2''' - same, using a method, 2nd version | ||
* '''Word3Cond3''' - same, output on a single line, 3rd version | ** '''Word3Cond3''' - same, output on a single line, 3rd version | ||
===Filtering files=== | ===Filtering files=== | ||
A ''filter'' program reads a file, modifies all lines somehow, and writes them to another file. | A ''filter'' program reads a file, modifies all lines somehow, and writes them to another file. | ||
Line 33: | Line 33: | ||
* '''FilterMulti3''' - read the modified output of ''Word3Cond3'' and colorize the known words | * '''FilterMulti3''' - read the modified output of ''Word3Cond3'' and colorize the known words | ||
===Date and Calendars=== | ===Date and Calendars=== | ||
* '''Age''' - enter a birthday and compute the years, months ... seconds up to now | * '''Age''' - enter a birthday and compute the elapsed years, months ... seconds up to now | ||
===Fractional arithmetic=== | ===Fractional arithmetic=== | ||
* '''GreatestCommonDivisor''' - the first real algorithm | * '''GreatestCommonDivisor''' - the first real algorithm | ||
* '''Ratio''' - introduction to object oriented programming (<code>static</ | * '''Ratio''' - introduction to object oriented programming (<code>static</code> version) | ||
** '''Rational''' - object with methods for mathematical operators for exact fractions | |||
** '''RationalTestSwing, AboutRationalTest''' - GUI for the addition, subtraction, multiplication of two ''Rational''s | |||
===Games=== | |||
* '''PlayNim''' - play the Nim game with some number of sticks to be taken | |||
** '''PlayNimState''' - improve clarity of program logic by using a Discrete Finite State Automaton (DFSA) | |||
** '''PlayNimSwing, AboutPlayNim''' GUI for the Nim game | |||
* '''ChessGame, ChessPlayer, ChessField, ChessPiece''' - interconnected set of classes for the display of a chess game using Unicode characters for the pieces | |||
===File Handling and Collections=== | |||
* '''HexDump''' - hexadecimal dump of a file, maybe binary | |||
* '''FilterURL''' - filter a file read from an URL (http://..., ftp://..., file://...) | |||
* '''FilterTowns''' - read jtc/test/id_kota.lst with a list of indonesian towns, and extract the names and the number of inhabitants only | |||
* '''SearchTown''' - store the town data in a ''HashMap'', and look one up there | |||
* '''SortTowns''' - store the town data in a ''TreeMap'', and print a list sorted alphabetically by town name | |||
* '''SearchAlice''' - read a text from an URL, for example [https://www.gutenberg.org/files/11/11-0.txt Alice in Wonderland], collect and count the names therein, and print a sorted list | |||
* '''WalkFileTree''' - run through a file directory with a subclass of ''FileVisitor'' and print the entries | |||
===Developper Information=== | |||
* '''SystemProps''' - show the Java system properties, the environment variables with their values, and the components of the system path | |||
* '''TestRegex''' - input a Java regular expression and try to match test texts in a loop | |||
** '''TestRegexSwing, AboutTestRegex''' - Swing GUI version thereof | |||
===Subclasses and Factories=== | |||
* '''Shape''' - class defining common properties and methods for geometrical forms, with output as an SVG (scalable vector graphics) file | |||
* '''ShapeFactory''' - Factory pattern returning an instance of a ''Shape'' | |||
* '''Circle, Square, Triangle, Hexagon''' - implementation of specific ''Shape''s and their SVG representation | |||
===Team collaboration=== | |||
* '''CheckIBAN''' - compute and check the checkdigits of an International Bank Account Number, | |||
** '''CheckIBANFilter''' - check a text file with many IBANs | |||
** '''CheckIBANSwing''' - GUI for checking a single IBAN |
Latest revision as of 20:41, 11 February 2018
During the training course we developped about 60 Java example programs which use the Java language features to be learned. These programs can all be obtained from the Git repository for the training course by the command:
git clone https://github.com/gfis/jtc
Start with a greeting
- HelloWorld - one-liner: output a greeting
Arguments, assignment, elementary String and arithmetic operations
- StringAdd - concatenate argument strings 4 times and print them out
- IntAdd - add 4 integers 4 times and print them
- IntMultiply - multiply 4 integers 4 times and print the product
- LongMultiply - multiply 4 long numbers
Loops (while, for
) and conditions (if
), arrays ([]
)
- PowersOf2 - print the powers of 2
- PowersOf2Check - check for increasing sequence
- PowersOf2Backwards - print sequence backwards
- PowersOf2Array - print sequence from an array
Sequences of conditions with switch, if - then - else if ...
- Selamat - print a greeting depending on the hour
- SelamatSwitch - same with
switch ... case ... default
- SelamatSwitch - same with
- Number10 - print the numbers 1..10
- Number10Method - print the numbers using a class method
- Month - print the indonese name of a month
- Weekday - print the indonese name of a weekday
Sequences of words
- Word1 - print all words with 1 letter
- Word2 - print all words with 2 letters by 2 nested loops
- Word3 - print all words with 3 letters
- Word3Cond1 - print words with 3 letters and vowel/consonant conditions, first version
- Word3Cond2 - same, using a method, 2nd version
- Word3Cond3 - same, output on a single line, 3rd version
Filtering files
A filter program reads a file, modifies all lines somehow, and writes them to another file.
- Filter1 - read a file and replace the vowels in each line
- FilterNumber - read a file and replace all digits by their indonese number words
- FilterMulti3 - read the modified output of Word3Cond3 and colorize the known words
Date and Calendars
- Age - enter a birthday and compute the elapsed years, months ... seconds up to now
Fractional arithmetic
- GreatestCommonDivisor - the first real algorithm
- Ratio - introduction to object oriented programming (
static
version)- Rational - object with methods for mathematical operators for exact fractions
- RationalTestSwing, AboutRationalTest - GUI for the addition, subtraction, multiplication of two Rationals
Games
- PlayNim - play the Nim game with some number of sticks to be taken
- PlayNimState - improve clarity of program logic by using a Discrete Finite State Automaton (DFSA)
- PlayNimSwing, AboutPlayNim GUI for the Nim game
- ChessGame, ChessPlayer, ChessField, ChessPiece - interconnected set of classes for the display of a chess game using Unicode characters for the pieces
File Handling and Collections
- HexDump - hexadecimal dump of a file, maybe binary
- FilterURL - filter a file read from an URL (http://..., ftp://..., file://...)
- FilterTowns - read jtc/test/id_kota.lst with a list of indonesian towns, and extract the names and the number of inhabitants only
- SearchTown - store the town data in a HashMap, and look one up there
- SortTowns - store the town data in a TreeMap, and print a list sorted alphabetically by town name
- SearchAlice - read a text from an URL, for example Alice in Wonderland, collect and count the names therein, and print a sorted list
- WalkFileTree - run through a file directory with a subclass of FileVisitor and print the entries
Developper Information
- SystemProps - show the Java system properties, the environment variables with their values, and the components of the system path
- TestRegex - input a Java regular expression and try to match test texts in a loop
- TestRegexSwing, AboutTestRegex - Swing GUI version thereof
Subclasses and Factories
- Shape - class defining common properties and methods for geometrical forms, with output as an SVG (scalable vector graphics) file
- ShapeFactory - Factory pattern returning an instance of a Shape
- Circle, Square, Triangle, Hexagon - implementation of specific Shapes and their SVG representation
Team collaboration
- CheckIBAN - compute and check the checkdigits of an International Bank Account Number,
- CheckIBANFilter - check a text file with many IBANs
- CheckIBANSwing - GUI for checking a single IBAN