Java Programs  «Prev  Next»

Standard Java - Exercise

Developing HelloWorld

Objective: Develop a command-line application.

Exercise Grading

The full credit for this exercise is 5 points. To receive full credit, you will need to successfully create the source code for the application. You will submit your source code.

Exercise Instructions

Create a command-line application named HelloWorld that can determine if a name was supplied as a command-line argument. If a name was supplied, display a greeting message including the command-line argument.
For example, if the user ran the application using
java HelloWorld Bob

then the message "Hello, Bob!" would be displayed. If no arguments are entered, then display the message "Hello, World!"
To complete this exercise, you will need to use the string concatenation operator (+). For instance, one way to display the message "Hello, Bob!" is with the following code:
System.out.println("Hello, " + "Bob" + "!");

You will also need to use an if-else statement. Here's a simple example:

if (age < 20)
  nickname = "young fella";
else
   nickname = "old man";

What to submit to the course

In the text box below, cut and paste the source code for the HelloWorld application.
Click the Submit button to submit the code to the course.