LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-16-2005, 04:48 PM   #1
LUB997
Member
 
Registered: Jul 2003
Distribution: openSUSE Linux, Apple Darwin UNIX
Posts: 66

Rep: Reputation: 15
Running a Java executable class from another executable class


I am programming with Java and have 2 executable classes, win.class and programManager.class. Both have main() methods and are executable. I want to execute programManager.class from win.class. Can this be done, and if so, what command would I use to do it in my win.java file? All .java and .class files are in the same directory.
 
Old 07-16-2005, 06:23 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Have a look here:

Classloader

You'll want to use

ClassLoader.getSystemClassLoader();

rather than the ClassLoader example they use.

Pretty interesting stuff.
 
Old 07-17-2005, 02:03 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
You can also simply call the other class main method from the first one.
Code:
public class win
{
   ...
   programManager.main(args);
   ...
}
 
Old 07-17-2005, 06:52 AM   #4
mohama
Member
 
Registered: May 2005
Location: solar-system->earth->northern hemisphere
Distribution: ubunutu+knoppix+suse
Posts: 197

Rep: Reputation: 31
answer

hello LUB997 ...
i just wanted to ask if u know what is Object-Oriented Programming ??

i don't realy know what your program supposed to do , but u could change your design and insted of using the static main method , u just could create object of that specific class and send it messeges so that it will respond the way u like ... .. .((( modularity is important thing for programmer )))

modularity is : ---->>
A quality of a system where it consists of various parts which separate cleanly and fit together well. High modularity costs some design time but pays back well through clarity, elegance, maintainability and -->> FLEXIBILITY <<-- .

good luck , :-)
 
Old 07-17-2005, 07:08 AM   #5
mohama
Member
 
Registered: May 2005
Location: solar-system->earth->northern hemisphere
Distribution: ubunutu+knoppix+suse
Posts: 197

Rep: Reputation: 31
another small thing ... .. .

Quote:
public class win
{
...
programManager.main(args);
...
}
i just wanted to say that the piece of code above wont compile ... ( identifier expected error , ))) i quess ((( )
it should be like this ... .. .

Code:
public class win
{
   ...
     public static void main ( String argv[] )
     {
         ...
         programManager.main(args);
         ...
     }
   ...
}
thats it ,
good luck , :-)
 
Old 07-17-2005, 10:14 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Hi mohama,

I tried your example, but it compiles neither, here's what I got:
Code:
win.java:3: illegal start of type
        ...
        ^
win.java:7: <identifier> expected
        }
         ^
2 errors
Hmm, do you really know object oriented programming ???

Last edited by jlliagre; 07-17-2005 at 10:16 AM.
 
Old 07-17-2005, 10:33 PM   #7
LUB997
Member
 
Registered: Jul 2003
Distribution: openSUSE Linux, Apple Darwin UNIX
Posts: 66

Original Poster
Rep: Reputation: 15
I got it to work a different way. I finally figured out how to apply the example in my Java book to my own program and ended up using a package. I just put "package win.manager" at the top of my source file for programManager.java and then on win.java did "import win.manager" and then to call my programManager method from my programManager.class stored in win.manager I just did "programManager();" in my win.java source file. Worked beautifully, but it took me a while to figure out since I don't know a whole lot about Java or object oriented programming yet. I've taken a year of C# in school, but we still haven't really gotten into the object oriented aspects of it yet. For those wondering what kind of program I am making, I am making a Windows for Workgroups 3.11 clone in Java. Not for any particular purpose, but mainly just for the sake of doing something complicated to advance my programming skills, but not so complicated that I can't do it. It of course will not be able to run Windows 3.1 programs, but will just be the Windows 3.1 GUI. win.java is my main screen (the background), and programManager.java is just that; the program manager. As anybody who remembers the DOS days recalls, you used to type "win" from the command prompt to start Windows 3.1. With mine you type "java win" from the bash prompt. If anybody's interested in it, I'll gladly share the sourcecode on it when it's finished, but not until then because the idea here is for me to learn something after all, and not just have others do it for me. Once I succeed at creating it in Java I will then try something more complicated and Linux oriented such as C and maybe GTK or QT for the graphics. My real goal is to create Linux programs, and thus I am really more interested in C than Java, but in this case I chose Java because you can do a lot with it fairly easily, and this is my first run with a program that has a detailed GUI, so I didn't want to use a language that would complicate things too much for me. Thanks for all the responses!
 
Old 07-18-2005, 04:45 AM   #8
mohama
Member
 
Registered: May 2005
Location: solar-system->earth->northern hemisphere
Distribution: ubunutu+knoppix+suse
Posts: 197

Rep: Reputation: 31
hi jlliagre .. .

Quote:
win.java:3: illegal start of type
... <<------------------- what such a fool error , :-o :- ( :- o :~ o :~|
^
win.java:7: <identifier> expected
}
^
2 errors <<------------ not realy two errors , the second is a result of the first ... .. . lol
ofcourse it will not compile since u repeat the same errors from that piece of code , there is nothing called ( ... ) in java so you should replace it with java type like ( ArrayList , AvlTree , Graph , .... ) or a type that u made in the same folder or in an imported package . ( i realy wonder how u make such an errors ???!!! )

an other thing , there is nothing for this to do with object oriented programming ,
Quote:
Hmm, do you really know object oriented programming ???
yes i do ... in OOP course i get 95 last semester ... .. . :-)

good luck .... LUB997
bye,
 
Old 07-18-2005, 12:29 PM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Mohama, please think twice before posting, read again this thread and see that you started with this inappropriate comment:

Quote:
i just wanted to say that the piece of code above wont compile ... ( identifier expected error , ))) i quess ((( )
it should be like this ... .. .
So to be sure you understand:

I used an ellipsis (three dots) in my sample code to represent parts unrelated with the demonstration,
"programManager.main(args);" can be used from anywhere inside the win class.

The sample code you posted is not adding anything, but on the opposite seems to limit the main call from the local main, which is wrong.

I was hoping you take my previous posting with humour, but am disappointed and sorry you missed it ...
 
Old 07-19-2005, 03:55 AM   #10
mohama
Member
 
Registered: May 2005
Location: solar-system->earth->northern hemisphere
Distribution: ubunutu+knoppix+suse
Posts: 197

Rep: Reputation: 31
Talking hellooooo

Quote:
I used an ellipsis (three dots) in my sample code to represent parts unrelated with the demonstration,"programManager.main(args);" can be used from anywhere inside the win class.
the underlined is not true , since u can't use it from any where inside the win class ( exactly the same error which u made in that piece of code ) it should be used from a body of one or more of the win class methods including the main method ,

Quote:
I was hoping you take my previous posting with humour, but am disappointed and sorry you missed it ...
well , no ...you shouldn't be niether sorry nor disappointed cause i didn't miss it , further more i wish u didn't and will not miss the humour in mine ...

bye ;~))
 
Old 07-19-2005, 12:34 PM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
it should be used from a body of one or more of the win class methods including the main method
This is just wrong ... it can be used from outside class methods too.
 
Old 07-20-2005, 04:22 AM   #12
mohama
Member
 
Registered: May 2005
Location: solar-system->earth->northern hemisphere
Distribution: ubunutu+knoppix+suse
Posts: 197

Rep: Reputation: 31
ahaaa

and how is that ???
inner class ???

if yes then this thread become with no mean , the perpuse of this forum is to help others and not ... .. .
so ...

bye ,
 
Old 07-20-2005, 02:03 PM   #13
elyk1212
Member
 
Registered: Jan 2005
Location: Chandler, AZ USA
Distribution: Mandrake/Mandriva 10.2
Posts: 186

Rep: Reputation: 30
Hi,
Can you state the purpose of the program and what it will be doing. In Software Engineering/and Hardware Engineering, we are taught that design is the most important step to coding/or simulations. A universal truth. Please let me know and you *may* rework the design if needed.
If you are invoking main within a main, it may be time to look at design, as that is not a very common case (never seen a need for that one in all my years programming, but there *could* be, I guess. This all depends on the design).
 
Old 07-20-2005, 02:04 PM   #14
elyk1212
Member
 
Registered: Jan 2005
Location: Chandler, AZ USA
Distribution: Mandrake/Mandriva 10.2
Posts: 186

Rep: Reputation: 30
And,.... Yes.. I would use an object oriented approach as suggested. Java lends itself to this nicely. But, all depends on design requirements.
 
Old 07-20-2005, 02:26 PM   #15
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,507

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
ahaaa ( post #12)

and how is that ???
I'll tell you when you stop claiming my perfectly right solution is not
Quote:
inner class ???
nope
Quote:
if yes then this thread become with no mean , the perpuse of this forum is to help others and not ... .. .
How are you helpful when writing:
Quote:
i just wanted to say that the piece of code above wont compile
while the code was intentionally not meant to be compiled but just to show how to call a class main method from elsewhere ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a vector class from a list class purefan Programming 9 04-14-2005 10:48 PM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM
Inheriting class members (Qt C++, QApplication class) jtshaw Programming 2 01-15-2004 11:52 AM
Running Java Class Files hackersapien Programming 9 08-07-2003 06:42 AM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM


All times are GMT -5. The time now is 06:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration