Posts which you will also like.

Showing posts with label Passing command line arguments in eclipse. Show all posts
Showing posts with label Passing command line arguments in eclipse. Show all posts

Friday, August 3, 2012

Passing Command Line Argument in Eclipse


Passing command line arguments in Eclipse is very easy.We will see step by step procedure to pass command line arguments to a java program using eclipse.

package com.techy.rajeev;

class BadFoodException extends Exception {

}
class Myexception{
    public static void checkfood(String food)throws BadFoodException{
        if(food.equals("Veg")){
            System.out.println("Good food :)");
        }else{
            throw new BadFoodException();
        }
    }
    public static void main(String args[]){
        for(String s: args){
            try {
                checkfood(s);
            } catch (BadFoodException e) {
                e.printStackTrace();
            }
        }
        System.out.println("survived");
    }
}


This is the java program for which we want to pass command line arguments.

Write this program in eclipse IDE and save it.

Now click on the small dropdown icon beside run icon as shown in image:

eclipse1

A drop down menu will appear.Now click on Run Configurations.


eclipse


Now a new window will appear.This window provide us the settings for the run time configurations of a program.


In this window click on the arguments tab and supply the arguments needed by your program separated via space as delimiter.


eclipse3

Thats it.

More on this at techcresendo.com
Read More ->>
DMCA.com Protected by Copyscape Online Plagiarism Tool