Teach Yourself Java in 21 Minutes: Department of Computer Science, Lund Institute of Technology
Teach Yourself Java in 21 Minutes: Department of Computer Science, Lund Institute of Technology
Teach Yourself Java in 21 Minutes: Department of Computer Science, Lund Institute of Technology
Table of contents
1 Simple declarations and expressions .......................................................................3
1.1 Simple declarations..............................................................................................................3
1.2 Numeric expressions and assignments.................................................................................3
1.3 Type conversion (casting) ....................................................................................................4
2 Statements ................................................................................................................4
2.1 If statements and boolean expressions .................................................................................5
2.2 While and for statements .....................................................................................................6
3 Classes and objects ..................................................................................................6
3.1 Classes..................................................................................................................................7
3.2 Methods................................................................................................................................7
3.3 Using objects........................................................................................................................8
3.4 Parameters to classes: constructors ......................................................................................8
3.5 The main method .................................................................................................................9
3.6 Inheritance............................................................................................................................9
3.7 Interfaces and listeners.......................................................................................................10
4 Exceptions..............................................................................................................11
4.1 Catching exceptions ...........................................................................................................11
4.2 Throwing exceptions..........................................................................................................12
4.3 Declaring new exceptions ..................................................................................................12
4.4 Unchecked exceptions........................................................................................................13
5 Miscellaneous ........................................................................................................13
5.1 Comments ..........................................................................................................................13
5.2 Using packages ..................................................................................................................13
5.3 Arrays.................................................................................................................................14
5.4 Writing to the terminal.......................................................................................................14
6 A complete Java program ......................................................................................15