java

How To Use Command Line Arguments in Eclipse

Detailed Instructions for Command Line Arguments in Eclipse
Example: Welcome.java

run->run configuration->java application->your project main ->Arguments->set  u arguments

  1. Basically, it’s simple.
    Click on Run -> Run (not Run Last Launched).In the window shown below,
    notice that the Welcome Java application is highlighted.

    In the large subwindow of the Run window, there is a set of tabs,
    labelled Main, Arguments, JRE, etc.
    Notice that the Main tab is highlighted.

     

  2. Click on the Arguments tab.
    This action brings up a window
    with a few places to enter values.
    You want to type in all your input values
    into the Program arguments window,
    with spaces (blank characters)between each value.For the Welcome program,
    only one input argument value is needed:
    the first name of a new Java student.
    For this run, we have chosen Sarah as
    the name of this student.

    Notice where it has been typed in.
    This is where all command line arguments should be entered.
    These values remain the same for all runs,
    until they are changed in this same window.

     

  3. Then just click Apply, followed by Run.
    The screenshot below shows the output in the console window.

Another Example of a Java program using Command Line Arguments: Args.java

Another example is the Args class,
developed in the TestArgs Eclipse project.
This program requires morethan one command line argument.

 

  1. Click on Run -> Run (not Run Last Launched)
  2. Click on the Arguments tab,
    in the large subwindow of the Run window.
    This action brings up the Program arguments window,
    where you should type in your input values.For the Args program,
    eight input argument values are needed.
    For this run, we have chosen eight random sets of
    characters, some numeric, some alphabetic, as input values:
    namely, 101, Joe, Larry, 93214, 3.145, 66, ABCDEF, xxxxx.
    Notice that there is at least one space between every two arguments.

     

  3. Then just click Apply, followed by Run.
    The screenshot below shows the output in the console window.

     

  4. If you were to click on Run -> Run Last Launched at this point,
    the same command line arguments would be used automatically,
    producing the same output. 
  5. To change the value of the command line argument,
    you need to click on Run -> Run again,
    and change the argument(s) in the Program assignment window.

 


Further Example of a Java programs using Command Line Arguments: TempConversion.java

 

Yet another example is the TempConversionCL class,
developed in the TempConversion Eclipse project.
This program requires only one command line argument,
but this value must be converted from a String
to a doublevalue to be used arithmetically.

 

 

  1. Again, click on Run -> Run (not Run Last Launched)
  2. Click on the Arguments tab,
    in the large subwindow of the Run window.
    This action brings up the Program arguments window,
    where you should type in your input values.For the TempConversionCL program,
    only one input argument value is needed:
    the value of the Celsius temperature.
    For this run, we have chosen 28.5 for
    this value of the Celsius temperature.

     

  3. Then just click Apply, followed by Run.
    The screenshot below shows the output in the console window.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s