example
Class Interpreter
java.lang.Object
|
+--example.Interpreter
- public class Interpreter
- extends java.lang.Object
Example that compiles and loads source files and runs the result.
This example behaves like the java
virtual machine
launcher but doesn't require the code to be precompiled (it supports
a "-sourcepath" as well as a "-classpath" option). It first compiles
and loads the source files in memory, and then executes the static
main(String[])
method of the class you specify, passing
your command line arguments to it.
For example, assuming you had a source file called "Echo.java" that
contained the following program:
public class Echo {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}
}
Invoking it from the command line could look something like this:
% java example.Interpreter -sourcepath . Echo "Hello World!"
% Hello World!
Method Summary |
static void |
main(java.lang.String[] argv)
Run the interpreter. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Interpreter
public Interpreter()
main
public static void main(java.lang.String[] argv)
throws java.lang.Throwable
- Run the interpreter.
- Parameters:
argv
-
<options> className <args>
where possible options include
- -classpath Specify where to find user class files
- -sourcepath Specify where to find input source files
- -bootclasspath Override location of bootstrap class files
- -source Provide source compatibility with specified release
- -target Generate class files for specific VM version
- -help Print a synopsis of standard options
- Throws:
java.lang.Throwable