Teach Yourself Java in 21 Minutes: Department of Computer Science, Lund Institute of Technology

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Teach Yourself Java in 21 Minutes

Department of Computer Science, Lund Institute of Technology


Author: Patrik Persson Contact: [email protected]

This is a brief tutorial in Java for you who already know


another object-oriented language, such as Simula or C++.
The tutorial is organized as a number of examples showing
the details of Java. The intention is to give you enough
information about the Java language to be able to follow the
course in real-time programming.
There are books claiming to teach you Java in 21 days, but
since you already know object-orientation your learning
time will probably be closer to 21 minutes hence the title.
This document may be freely copied and distributed for non-commercial use. In case of
changes or enhancements, title, department, author, and contact must be preserved, and
changes that are redistributed or made public must be mailed to the contact above.

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

Teach Yourself Java in 21 Minutes 1

You might also like