run program from command line

Hi,
i have a void method(NO Argument) has local variables. i would like to test this
method by imputing these local variables from command line.
Is there a way to do this?

Thanks
komlaaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
no
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Manikandan ThiagarajanSenior consultantCommented:
that is not possible to give that argument for method in commandline
0
mrigankCommented:
You can only run the main method from the command line.
Take the variables from the command line and pass these to the  method you want to test from the main method.

public class MainClass{
    public static void main(String args[]){
        MyClassToTest m = new MyClassToTest();
        m.callMyMethodToTest(args[0],args[1],.......,args[n]);
    }
}

command line
java MainClass
0
mrigankCommented:
sorry

you need to initialise the local variables via the constructor

MyClassToTest m = new MyClassToTest(args[0],args[1],.......,args[n]);
m.callMyMethodToTest();


or you need to use Refection APIs to populate the local variables
0
mrigankCommented:
If the scope of the variables is the method, it cannot be done.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.