• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call program arguments of different class through java code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

There are some couple of classes which has their own program arguments to execute it. Now i need to create Main execution class and to call all classes. while calling that classes they require to pass arguments. so if i have those program arguments in my code then i will develop main execution class. Kindly let me know if somebody needs more clarity...

Thanks in advance
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not clear to me what you're asking, but it sounds like it might be something like this:



If your question is how to call C1's main and C2's main from Main's main, the answer is that they're just regular methods that you can call like any other:



HOWEVER, that would be a rather unusual requirement, and it suggests a design problem to me. (I can't give you anything more specific about what's wrong without knowing more about what you're trying to do and why you're trying to do it this way.)

If this is not what you're asking, please clarify, using a tiny example like I did to illustrate the issue.
 
Gokul Raam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff,

Thanks for your reply.

You have guessed almost correct.

i will explain more with your example.

there are C1 and C2 clasees and I have Main class and from Main class i need to call C1 and C2 in order to run continuously.
The problem is that both C1 and C2 have different program arguments which are mentioned in run configurations of eclipse and in Main class if i use the below method to call those C1 and C2 classes I will error.

C1.main(args);
C2.main(args);

So Now i need to get those program arguments in code and i need to call those C1 and C2 classes like

args1 = "Program arguments of C1 class"
args2 = "Program arguments of C2 class"

C1.main(args1);
C2.main(args2);


Kindly let me know if you need more clarification.
thanks in advance.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gokul Raam wrote:
there are C1 and C2 clasees and I have Main class and from Main class i need to call C1 and C2 in order to run continuously.
The problem is that both C1 and C2 have different program arguments which are mentioned in run configurations of eclipse and in Main class if i use the below method to call those C1 and C2 classes I will error.

C1.main(args);
C2.main(args);

So Now i need to get those program arguments in code and i need to call those C1 and C2 classes like

args1 = "Program arguments of C1 class"
args2 = "Program arguments of C2 class"

C1.main(args1);
C2.main(args2);



So, what's stopping you? Clearly you know how to call C1 with one set of args, and C2 with another set of args. If you're asking where to get those args from, there's no way anybody here can know that. Only you know what those args are supposed to be and where they're coming from.

If you're asking how to get them from "configurations of eclipse", then that can be found in the eclipse docs, or eclipse tutorial, or eclipse forum. But basically, there will be somewhere in eclipse where you can tell it what args to pass when you start your main program, so you just need to fill that in with something like


and then your Main has to parse those out to figure out which args go with each C1 and C2. Maybe there are a known, fixed number for each, so that, for example, args[0]-args[2] go to C1 and args[3]-args[5] go to C2. Or maybe you provide a special delimiter, such as "--" or ":::" or something, and when Main sees that, it knows everything before it is for C1 and everything after is for C2.
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic