Question: I am currently working on a Java graphics API and want to enable easy customization. Part of what I have in mind is being able to replace standard code with custom code. To achieve this, I'm wondering if I can have the methods of my code reference code in external, swappable files (that may or may not be written in a different language, such as RhinoScript). For example, if someone using the API feels the code of a particular method is inefficient, they could replace the file that method references with their own file with code which they feel is more efficient.

I understand interfaces and abstract classes may be an option to achieve this, but I feel the approach I described, if achievable, would have the advantage of reusable code, easier implementations of the API using different scripting languages, and a generally easier way to modify code.

The bottom line of what I'm asking is this: is it possible to have a method execute code contained in a stand alone file (contains only the code the method would execute), which may or may not be written in a language separate from Java, and if so, how would I go about doing this or what subjects should I research for this?

In closing, I apologize if this is not an acceptable question to ask on this forum or I have not stated my question clearly enough.

Answer: 
I think this is not the way to go, if you want to offer customization to your library, interfaces and abstract classes are your best bet. Implementing wrappers for other languages will be very inefficient and probably relatively slow, not even starting with the complexity it add to your code. How are you going to pass arguments? Receive return values? Manage exceptions in case of run-time or syntax errors?

Of course it all possible, but as a developer, I would never use an API that works like you described.
Normally I'd suggest one of the following methods:

* Define an **interface** that the custom code needs to implement
* Provide a (possible abstract) **base class** that custom code can extend via inheritance

Which of these you choose is up to you, typically base classes are a bit easier for people to use (since they only need to override the specific methods they want to change), whereas interfaces give you better abstraction and can be a bit more flexible / maintainable in the long run.

If these solutions don't suit you, then you can always make your project **open source** - then people who have a better implementation can contribute their improvements back to the main code base.

If you really want to allow extension in another langauge then I still think that interfaces / base classes are the way to go: many other JVM languages allow you to extend a Java class or implement an interface. Then you leave it up to the user to generate whatever code they like.