Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

run program from command line

Posted on 2006-03-28
5
Medium Priority
?
233 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:komlaaa
  • 3
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 16316630
no
0
 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 16316690
that is not possible to give that argument for method in commandline
0
 
LVL 5

Expert Comment

by:mrigank
ID: 16316879
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
 
LVL 5

Expert Comment

by:mrigank
ID: 16316895
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
 
LVL 5

Expert Comment

by:mrigank
ID: 16316903
If the scope of the variables is the method, it cannot be done.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question