Results 1 to 5 of 5
  1. #1
    SwissR is offline Member
    Join Date
    Jul 2010
    Posts
    39
    Rep Power
    0

    Default Is There A Way To Call Another Java Program Within A Java Program

    Hi everyone,

    I basically have two Java programs and am wondering if i can complete my first programs run and then call my second program within the first like calling a css file in html.

    I dont really want to have to add the class of one program to the other and fiddle around with it. I know I can call them in the command prompt window but if possible I would like to execute them both through one instance if possible.

    regards S

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by SwissR View Post
    I know I can call them in the command prompt window
    That implies that both classes have a main( ... ) method; why not call that method yourself? e.g.

    Java Code:
    YourFirstClass.main(null); 
    YourOtherClass.main(null);
    Note that I didn't pass any arguments to the main( ... ) methods; you decide whether or not that is correct.

    kind regards,

    Jos

  3. #3
    SwissR is offline Member
    Join Date
    Jul 2010
    Posts
    39
    Rep Power
    0

    Default

    Im a little confused by what you mean.
    So your saying that I can call the class and main method of one program within another without actually having to paste the class into said program?

    I mean im calling one program via its main class so do I call the other programs class and then its main method through that...

    I would have thought I would have had to reference a directory, or am I getting the wrong idea here...?

    regards S

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by SwissR View Post
    Im a little confused by what you mean.
    So your saying that I can call the class and main method of one program within another without actually having to paste the class into said program?
    Yes.

    Quote Originally Posted by SwissR View Post
    I mean im calling one program via its main class so do I call the other programs class and then its main method through that...
    Yes.

    Quote Originally Posted by SwissR View Post
    I would have thought I would have had to reference a directory, or am I getting the wrong idea here...?
    Yes. There's nothing special about a main( ... ) method; if the jvm can call it, you can call it as long as the class is visible to the jvm; but it has to be because you wrote in your OP that you can call the class (through its main( ... ) method) from the command line.

    kind regards,

    Jos

  5. #5
    SwissR is offline Member
    Join Date
    Jul 2010
    Posts
    39
    Rep Power
    0

    Default Hi-5

    Thanks JosAH,

    All done and dusted finally :)

    Now roll on half 5 so i can go and have a beer :)

Similar Threads

  1. Replies: 0
    Last Post: 04-19-2010, 07:40 PM
  2. how to call dll file in java program
    By santhosh_el in forum AWT / Swing
    Replies: 6
    Last Post: 06-12-2009, 10:23 PM
  3. Is it possible to make a Phone call program using java?
    By fireball2008 in forum New To Java
    Replies: 2
    Last Post: 05-08-2008, 07:20 PM
  4. How to call C/C++ Program from Java
    By sanjeevtarar in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •