Object-Oriented Design

homepage

Chapter Topics

"Hello, World" in Java

public class Greeter
{
public Greeter(String aName)
{
name = aName;
}
public String sayHello()
{
return "Hello, " + name + "!";
}
private String name;
}

"Hello, World" in Java

"Hello, World" in Java

public class GreeterTester
{
public static void main(String[] args)
{
Greeter worldGreeter = new Greeter("World");
String greeting = worldGreeter.sayHello();
System.out.println(greeting);
}
}

Using the SDK

Using the SDK


Using BlueJ

Using BlueJ


Documentation Comments

1 /**
2 A class for producing simple greetings.
3 */
4 5 public class Greeter
6 {
7 /**
8 Constructs a Greeter object that can greet a person or
9 entity.
10 @param aName the name of the person or entity who should
11 be addressed in the greetings.
12 */
13 public Greeter(String aName)
14 {
15 name = aName;
16 }
17
18 /**
19 Greet with a "Hello" message.
20 @return a message containing "Hello" and the name of
21 the greeted person or entity.
22 */
23 public String sayHello()
24 {
25 return "Hello, " + name + "!";
26 }
27
28 private String name;
29 }

Documentation Comments - Summary


Documentation Comments - Detail


Documentation Comments

Documentation Comments - API Docs


Primitive Types

Escape Sequence Meaning
\b backspace (\u0008)
\f form feed (\u000C)
\n newline (\u000A)
\r return (\u000D)
\t tab (\u0009)
\\ backslash
\' single quote
\" double quote

Control Flow

Object References

The null Reference

The this Reference

Parameter Passing

No Reference Parameters

Packages

Packages

Importing Packages

Importing Packages

Packages and Directories

Exception Handling

Checked and Unchecked Exceptions

Declaring Checked Exceptions

Catching Exceptions

try-with-Resources

The finally Clause

Strings

String greeting = "Hello";
char ch = greeting.charAt(1); // sets ch to 'e' greeting = "Goodbye";

Strings

String concatenation

Converting Strings to Numbers

Reading Input

The ArrayList<E> class

The ArrayList<E> class

The ArrayList<E> class

Linked Lists

List Iterators

List Iterators

Arrays

Arrays

Arrays

Command-Line Arguments

Static Fields

Static Methods

Programming Style: Case Convention

Programming Style: Property Access

Programming Style: Braces

Programming Style: Fields

Programming Style: Miscellaneous