Results 1 to 9 of 9
  1. #1
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Question how to call 2 java programs in one another java program

    Hi

    I have written 2 java programs (ie., 2 java projects named school project and census project)

    Now i need to write another java program that will give little menu , asking the user what they are trying to do .

    Please enter:
    1 for school project
    2 for census project

    In which case you will check for validity and call your appropriate program.

    Pls anyone tell me , how to do this in java .
    And how to call 2 different projects from another project .

    Anyhelp to start off is appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default

    What is a "program"?
    Everything in java is contained in a class.
    I think of a program as a class with a main method that you can start execution of by using the java command. The main method can create and call many other classes. All the classes that are used are part of the "program".

    Also you use the word: project. Is this something to do with how to use an IDE?
    If so, is there a forum for the IDE you could ask the question on?

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

    Default

    Quote Originally Posted by Norm View Post
    I think of a program as a class with a main method that you can start execution of by using the java command.
    You can even call the main( ... ) method of that other class directly (it is static and it is public); the entire thing would run in the same jvm as the caller.

    kind regards,

    Jos

  4. #4
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Default

    I am trying to understand what you are saying .I am really a basic new java programmer .Learning and doing at the same time.

    Can anyone of you , give me a skeleton of code showing me how the third class will call 2 other classes based on the choice of the user.

    I wrote 2 projects seperately in eclipse .
    Now i want the third project to give a choice to the user to select any one of the 2 projects.

    In real world ...it is like this

    I as a user should have choice to select either school project or census project to give me the results .

    How would i do that in java ..

    Pls explain me in detail and i would appreciate , if anyone will give me a skeleton code to explain the choice of choosing from 2 diff projects .

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by renu View Post
    Hi

    I have written 2 java programs (ie., 2 java projects named school project and census project)

    Now i need to write another java program that will give little menu , asking the user what they are trying to do .

    Please enter:
    1 for school project
    2 for census project

    In which case you will check for validity and call your appropriate program.

    Pls anyone tell me , how to do this in java .
    And how to call 2 different projects from another project .

    Anyhelp to start off is appreciated.

    if each program is in its own class then instantiate the classes and call the methods of the class you want. if all programs are in the same class then call the appropriate method.

    watch out: your classes should have the same project root.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default

    Using classes from other projects should work the same way as you use Java's classes.
    If needed, import the package and then use new to create new objects of the classes you want to execute.
    If the the other "programs" are independent, standalone programs, that expect to be called/started by the java command, then as JosAH says you can start the class by calling its static method: main method. For example:
    SchoolProject.main(new String[]{});
    A problem will be that the program could call System.exit(0); which will end the JVM for every class.

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

    Default

    Quote Originally Posted by Norm View Post
    A problem will be that the program could call System.exit(0); which will end the JVM for every class.
    Nothing a little SecurityManager can't cure ;-)

    kind regards,

    Jos

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default

    Of course.
    One of my projects was something I called ExecJava. It runs a number of my tools in a single JVM using classloaders and a SecurtyManager and whatever else I needed at the time. All my tools can run either standalone or inside this program's JVM.
    I was working on a smaller, slower machine when I developed it. The startup time for a JVM was long, so I started one JVM and put all my tools in that one. Besides that was what I had done for a living for many years: Maintained an IBM OS

  9. #9
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Default

    thank You all for your replies.

    I did write a single class asking for the option from the user and put the 2 projects i wrote before ..its code into an if clause and it works .

    Thank You ..Now i will have only one class which will be a standalone program on each users PC.

Similar Threads

  1. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  2. Replies: 0
    Last Post: 04-19-2010, 06:40 PM
  3. how to call dll file in java program
    By santhosh_el in forum AWT / Swing
    Replies: 6
    Last Post: 06-12-2009, 09:23 PM
  4. 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, 06:20 PM
  5. How to call C/C++ Program from Java
    By sanjeevtarar in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 08: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
  •