18
HelloMessage hm;
hm = new HelloMessage();
System.out.println(hm.getMessage());
hm.setMessage("Hello, World");
System.out.println(hm.getMessage());
}
}
The
second class, HelloMessage, is a container class
that holds a string-based
message.
Listing 1-3. A “Message” Example
package org.java17recipes.chapter01.recipe01_05;
public class HelloMessage {
private String message = "";
public HelloMessage() {
this.message = "Default Message";
}
public void setMessage (String m) {
this.message = m;
}
public String getMessage () {
//it changes
the message to uppercase
return message.toUpperCase();
}
}
Make sure you have pasted (or typed) the code. Compile and run the program.
Right- click in the project and select Run As ➤ Java Application,
as shown in Figure
1-15
.
ChApteR 1 GettInG StARted wIth JAvA 17
19
Figure 1-15. Running a project in Eclipse IDE
Now you should see the following output.
DEFAULT
MESSAGE
HELLO, WORLD
This output appears in a new view named Console,
which Eclipse opens at the
bottom of the IDE window, as shown in Figure
1-16
.
Figure 1-16. Console view in Eclipse IDE
ChApteR 1 GettInG StARted wIth JAvA 17
20
How It Works
You can run almost all the solutions in this chapter using
the same general technique
shown in this recipe. For that reason, we show the step-by-step screenshots this
one time.
Do'stlaringiz bilan baham: