Often you may want to test a single piece of code. For example, say you forget how the % operator works with negative numbers, or you must determine how a certain API call operates. Writing, compiling, and running a small program repeatedly just to test small things can prove annoying.
With that in mind, in this Java Tip, I present a short program that compiles and runs Java code statements simply by using tools included in Sun’s JDK 1.2 and above.
Note: You can download this article’s source code from Resources.
Use javac inside your program
You’ll find the javac compiler in the tools.jar library found in the lib/ directory of your JDK 1.2 and higher installation.

