SE450: Horstmann Chapter 1

Contents [0/53]

Object-Oriented Design & Patterns [1/53]
Chapter Topics [2/53]
"Hello, World" in Java [3/53]
"Hello, World" in Java [4/53]
"Hello, World" in Java [5/53]
Using the SDK [6/53]
Using the SDK [7/53]
Using BlueJ [8/53]
Using BlueJ [9/53]
Documentation Comments [10/53]
Documentation Comments - Summary [11/53]
Documentation Comments - Detail [12/53]
Documentation Comments [13/53]
Documentation Comments - API Docs [14/53]
Primitive Types [15/53]
Control Flow [16/53]
Object References [17/53]
The null Reference [18/53]
The this Reference [19/53]
Parameter Passing [20/53]
No Reference Parameters [21/53]
Packages [22/53]
Packages [23/53]
Importing Packages [24/53]
Importing Packages [25/53]
Packages and Directories [26/53]
Exception Handling [27/53]
Checked and Unchecked Exceptions [28/53]
Declaring Checked Exceptions [29/53]
Catching Exceptions [30/53]
The finally Clause [31/53]
Strings [32/53]
Strings [33/53]
String concatenation [34/53]
Converting Strings to Numbers [35/53]
Reading Input [36/53]
The ArrayList class [37/53]
The ArrayList class [38/53]
The ArrayList class [39/53]
Linked Lists [40/53]
List Iterators [41/53]
List Iterators [42/53]
Arrays [43/53]
Arrays [44/53]
Arrays [45/53]
Command-Line Arguments [46/53]
Static Fields [47/53]
Static Methods [48/53]
Programming Style: Case Convention [49/53]
Programming Style: Property Access [50/53]
Programming Style: Braces [51/53]
Programming Style: Fields [52/53]
Programming Style: Miscellaneous [53/53]

Object-Oriented Design & Patterns [1/53]

Cay S. Horstmann

Chapter 1

A Crash Course in Java

horstmann-oodp2

Chapter Topics [2/53]

"Hello, World" in Java [3/53]

file:horstmann/ch01_helloworld/Greeter.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package horstmann.ch01_helloworld;
/**
   A class for producing simple greetings.
 */

public class Greeter
{
  /**
      Constructs a Greeter object that can greet a person or
      entity.
      @param aName the name of the person or entity who should
      be addressed in the greetings.
   */
  public Greeter(String aName)
  {
    name = aName;
  }

  /**
      Greet with a "Hello" message.
      @return a message containing "Hello" and the name of
      the greeted person or entity.
   */
  public String sayHello()
  {
    return "Hello, " + name + "!";
  }

  private String name;
}

"Hello, World" in Java [4/53]

"Hello, World" in Java [5/53]

file:horstmann/ch01_helloworld/GreeterTester.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
package horstmann.ch01_helloworld;
public class GreeterTester
{
  public static void main(String[] args)
  {
    Greeter worldGreeter = new Greeter("World");
    String greeting = worldGreeter.sayHello();
    System.out.println(greeting);
  }
}

file:horstmann/ch01_helloworld/Greeter.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package horstmann.ch01_helloworld;
/**
   A class for producing simple greetings.
 */

public class Greeter
{
  /**
      Constructs a Greeter object that can greet a person or
      entity.
      @param aName the name of the person or entity who should
      be addressed in the greetings.
   */
  public Greeter(String aName)
  {
    name = aName;
  }

  /**
      Greet with a "Hello" message.
      @return a message containing "Hello" and the name of
      the greeted person or entity.
   */
  public String sayHello()
  {
    return "Hello, " + name + "!";
  }

  private String name;
}

Using the SDK [6/53]

Using the SDK [7/53]


Using BlueJ [8/53]

Using BlueJ [9/53]


Documentation Comments [10/53]

Documentation Comments - Summary [11/53]


Documentation Comments - Detail [12/53]


Documentation Comments [13/53]

Documentation Comments - API Docs [14/53]


Primitive Types [15/53]

Control Flow [16/53]

Object References [17/53]

The null Reference [18/53]

The this Reference [19/53]

Parameter Passing [20/53]

No Reference Parameters [21/53]

Packages [22/53]

Packages [23/53]

Importing Packages [24/53]

Importing Packages [25/53]

Packages and Directories [26/53]

Exception Handling [27/53]

Checked and Unchecked Exceptions [28/53]

Declaring Checked Exceptions [29/53]

Catching Exceptions [30/53]

The finally Clause [31/53]

Strings [32/53]

Strings [33/53]

String concatenation [34/53]

Converting Strings to Numbers [35/53]

Reading Input [36/53]

file:horstmann/ch01_input/InputTester.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
package horstmann.ch01_input;
import java.util.Scanner;

public class InputTester
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    System.out.print("How old are you?");
    int age = in.nextInt();
    age++;
    System.out.println("Next year, you'll be " + age);
    in.close();
  }
}

The ArrayList class [37/53]

The ArrayList class [38/53]

The ArrayList class [39/53]

Linked Lists [40/53]

List Iterators [41/53]

List Iterators [42/53]

Arrays [43/53]

Arrays [44/53]

Arrays [45/53]

Command-Line Arguments [46/53]

Static Fields [47/53]

Static Methods [48/53]

Programming Style: Case Convention [49/53]

Programming Style: Property Access [50/53]

Programming Style: Braces [51/53]

Programming Style: Fields [52/53]

Programming Style: Miscellaneous [53/53]


Revised: 2007/09/11 16:59