The Artima Developer Community
Sponsored Link

Java Answers Forum
Urgent very high level help requires

4 replies on 1 page. Most recent reply: Jul 21, 2002 5:32 AM by thomas

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 4 replies on 1 page
Manolo

Posts: 1
Nickname: xganzabal
Registered: Jul, 2002

Urgent very high level help requires Posted: Jul 13, 2002 11:03 AM
Reply to this message Reply
Advertisement
Hi,
a need help for a quite sophisticated thing, I explain: a want to write a program that would use user-created classes; the user would be asked the name of the file where the class is (either code or bytecode) and the program would use that class . The problem is that the program is complied and running before knowing about that classes. I dont know if this can be done in Java. If someone knows how to do this or is sure that this cannot be done in Java, please let me know.
Thanks,
Xabi.


he yunlong

Posts: 4
Nickname: javasea
Registered: Jul, 2002

Re: Urgent very high level help requires Posted: Jul 13, 2002 4:17 PM
Reply to this message Reply
as one example:

require the classes to be used have implements the JMX interface, your server program has access to the MBean configuration file which curtains the class name, service name and location.
maybe I can't express it clearly, your can have a look on JMX standard.

Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Urgent very high level help requires Posted: Jul 13, 2002 6:18 PM
Reply to this message Reply
Have a read about reflection.

daniel mantel

Posts: 1
Nickname: danman
Registered: Jul, 2002

Re: Urgent very high level help requires Posted: Jul 17, 2002 12:13 AM
Reply to this message Reply
Hi...
Like someone says, take a look to reflection.
You can ask from the user a abc.class (already compiled class).
Use the Class.forName("abc") to "load" the desired class and then use the class.newInstace() to get an instance for this class.
You better make the user to implement an interface you made so when you create the new instace you can call the methods from the interface you made.
example:
1. make an interface:
--->public interface KUKU {
--- void myMethod();
--- }
* Take the class from the user...
2. 'load' the class by:
----> Class cl = Class.forName("userClassName");
3. create an instance of it:
----> Object obj = cl.newInstance();
4. cast the object to the interface you create
----> KUKU k = (KUKU)obj;
5. use it as:
----> k.myMethod();

your are actually calling the myMethod of the user class

I hope this answer your question...

-DanMan

thomas

Posts: 42
Nickname: turbomanic
Registered: Jul, 2002

Re: Urgent very high level help requires Posted: Jul 21, 2002 5:32 AM
Reply to this message Reply
Once you import the class then you would have to tell the programme exactly how to use this class therefore would have to add code to this programme that is all ready compiled. The compiled programme will not use this new class unless told exactly how to use it(through the use of code) hence you will eventually have to recompile it. I might be missing something but I don't see any purpose in having a running programme add a new class to it. I am no expert but am in my third year of university so could you explain why you would want to import a programme once it is compiled then the programme will start using the class without any additional code? To me this don't make sense but I could be missing the purpose from lack of experience?

Flat View: This topic has 4 replies on 1 page
Topic: Java getPrintJob Previous Topic   Next Topic Topic: Dynamic Casting || Dynamic Invocation of a method of a default class

Sponsored Links



Google
  Web Artima.com   

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