Simpler ACM Java Task Force Programs in DrJava

Daniel L. Schuster, Professor of Computer Science & Mathematics at Western State College of Colorado and author of The Free Java Book, had asked me at SIGCSE 2010 if we could simplify runing ACM Java Task Force programs in DrJava. Other IDEs can run ACM Java Task Force programs that just look like this

//HelloWorldConsole.java
import acm.program.*;

public class HelloWorldConsole extends ConsoleProgram {
public void run( ) {
println("Hello World");
}
}

In the past, DrJava needed a main method:

//HelloWorldConsole.java
import acm.program.*;

public class HelloWorldConsole extends ConsoleProgram {
public void run( ) {
println("Hello World");
}
public static void main(String[ ] args) {
new HelloWorldConsole( ).start(args);
}
}

This was, in my humble opinion, due to the rather twisted way the ACM Java library determines the main class using command line arguments, Java properties, OS-specific ways to determine the command line involving process IDs, etc.

I think I have nonetheless found a working solution. I’m using a bit of reflection behind the scenes of the “Run” button and the “java” command in the Interactions Pane.

There is a new option in Preferences/Interactions Pane called “Smart Run (‘java’) Command”. If enabled (default), the “Run” button and the “java” command in the Interactions Pane detects if the class (a) is an ACM Java Task Force
program (subclass of acm.program.Program) or (b) an applet (subclass of java.applet.Applet). If the former is the case, then DrJava runs the program’s main method, but inserts "code=MyClass" as argument 0. If the latter is the case, DrJava starts the
applet viewer. If neither is the case, the command behaves just as before.

With a program from the book, like the one above, all the students need to do now is compile and press the “Run” button.

I have created a new weekly build that is available from our DrJava Weekly Jar website (direct link: drjava-weekly-20100508-r5249).

If Dan determines that this solution works for him, this feature will definitely be in the next stable release, which we expect for the end of May.

There are two other new features in DrJava that Dan and his students may find interesting:

  1. DrJava doesn’t require the JDK anymore to compile programs. This
    could simplify the instructions in “Setting Up Your Computer”. To
    compile, DrJava now uses an integrated Eclipse compiler and needs just
    a JRE 6. To use the debugger or generate Javadoc, the JDK is still
    necessary, though.
  2. You can generate a custom drjava.jar file that already includes the
    ACM Java library classes from the acm.jar file. That way, those
    classes are already included on the classpath, and you don’t need to
    add it to the Extra Classpath under “Resource Locations”.

I’m convinced these two features, plus the smart “Run” command I just implemented, make DrJava an even better, simpler teaching tool.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in DrJava. Bookmark the permalink.

6 Responses to Simpler ACM Java Task Force Programs in DrJava

  1. Pingback: A Concurrent Affair » Blog Archive » Fixed DrJava “Smart Run” Problem

  2. Pingback: Another Bugfix for Smart Run | A Concurrent Affair

Leave a Reply