The Artima Developer Community
Sponsored Link

Java Answers Forum
Run a java class within another class

3 replies on 1 page. Most recent reply: Sep 19, 2008 9:12 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Yonatan Vowell

Posts: 1
Nickname: yvowell
Registered: Sep, 2008

Run a java class within another class Posted: Sep 15, 2008 6:03 AM
Reply to this message Reply
Advertisement
Hi,
I'm trying to run a Java class within my java program without using Runtime.getRuntime().exec()
can anyone tell me how to do this?


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Run a java class within another class Posted: Sep 18, 2008 2:22 PM
Reply to this message Reply
I thought this was pretty basic to java programming.

You can create one on your code with its constructor.

AnotherClass another = new AnotherClass();

or

AnotherClass another = getAnotherClass();

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Run a java class within another class Posted: Sep 19, 2008 12:07 AM
Reply to this message Reply
> I thought this was pretty basic to java programming.
>
> You can create one on your code with its constructor.
>
> AnotherClass another = new AnotherClass();
>
> or
>
> AnotherClass another = getAnotherClass();

I dont think that's what he means. I think actually firing up a Java Application as in from command line the same way you can call:

Runtime.getRuntime().exec("java MyApp");


When I saw this post I initially thought of messing with Classloaders and calling those within code, but then I thought I have never done that and don't have much experience - hence my response would be misleading.

You can however give a class a main method and call its main method - I doubt that's what he's looking for either though.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Run a java class within another class Posted: Sep 19, 2008 9:12 AM
Reply to this message Reply
He needs to explain his request or question better.

Sometimes it is difficult for those whose native language is not English to express their questions where I can understand.

But running another java program from inside a java program is inherent in the programming language from ita earliest days.

Flat View: This topic has 3 replies on 1 page
Topic: Rectangles in Java Previous Topic   Next Topic Topic: generic method unchecked cast problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use