Java 17 Recipes


Download 3.2 Mb.
Pdf ko'rish
bet15/245
Sana02.06.2024
Hajmi3.2 Mb.
#1839910
1   ...   11   12   13   14   15   16   17   18   ...   245
Bog'liq
Java 17 Recipes

Listing 1-2. A “Hello, World” Example
package org.java17recipes.chapter01.recipe01_05;
public class HelloWorld {
/* The main method begins in this class */
public static void main(String[] args) {
ChApteR 1 GettInG StARted wIth JAvA 17


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.

Download 3.2 Mb.

Do'stlaringiz bilan baham:
1   ...   11   12   13   14   15   16   17   18   ...   245




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling