Home‎ > ‎Applied Core Java‎ > ‎Introduction‎ > ‎

Hello Name

Problem : Write a program that takes a name from command line and say Hello to it?

Program :


Step 1 - Coding

Create a text file c:\sunilos\HelloName.java  and copy below contents.


 *A program which take command line argument and print on command prompt.

public class HelloName {
    public static void main(String[] args) {

        System.out.println("Hello " + args[0]);

Step 2 - Deployment

  1. Create a folder 'c:\sunilos'. 
  2. Create or copy HelloName.java into 'c:\sunilos' folder.
  3. Open your command prompt and go to  'c:\sunilos'
  4. Compile HelloName.java with help of 
    • javac HelloName.java command. Command will create class file in the same folder.
  5. Congratulations!! your Java program is ready to serve.

Step 3 - Testing

  1. Make sure you are on Command Prompt under c:\sunilos directory
  2. Now start your  java program from command prompt with help of 
    • java HelloName SunilOS command.


It will display.
Hello SunilOS

<<Previous | Next>>
Namrata Sisodiya,
Aug 19, 2011, 2:58 AM