0
0
Javaprogramming~15 mins

Method calling in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeMethod calling
📖 Scenario: You are creating a simple Java program to greet users by their names. This program will help you understand how to call methods to reuse code.
🎯 Goal: Build a Java program that defines a method to greet a user by name and calls this method to display a greeting message.
📋 What You'll Learn
Create a method named greetUser that takes a String parameter called name and prints a greeting message.
Call the greetUser method from the main method with a specific name.
Print the greeting message to the console.
💡 Why This Matters
🌍 Real World
Calling methods is how programs reuse code to perform tasks multiple times without repeating code.
💼 Career
Understanding method calling is essential for writing clean, organized, and maintainable Java programs in any software development job.
Progress0 / 4 steps
1
Create the main class and main method
Create a public class named GreetingApp and add the main method inside it.
Java
💡 Need a hint?

The main method is the starting point of any Java program.

2
Create the greetUser method
Inside the GreetingApp class but outside the main method, create a public static method named greetUser that takes a String parameter called name and prints "Hello, " + name + "!".
Java
💡 Need a hint?

Define the method outside main but inside the class. Use System.out.println to print.

3
Call the greetUser method from main
Inside the main method, call the greetUser method with the argument "Alice".
Java
💡 Need a hint?

Call the method by its name and pass the exact string "Alice" as argument.

4
Print the greeting message
Run the program and print the output to the console. The output should be exactly Hello, Alice!
Java
💡 Need a hint?

Make sure to run the program and check the console output.