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

1
2
3
4
5
6
7
8
//HelloWorldConsole.java
import acm.program.*;

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

In the past, DrJava needed a main method:

1
2
3
4
5
6
7
8
9
10
11
//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. StephenGilbert says:

    Hi,
    The link to 5249 seems broken. However, I tried both 5253 and 5252 and, while both of them run ACM programs correctly now with the run button, I can no longer run regular programs with a main() method using the button or directly in the interactions pane. This is the error message on a simple “Hello world” program:

    java StaircasePrinter
    Static Error: No method in static SwingUtil with name ‘showApplet’ matches this invocation
    Arguments: (StaircasePrinter, int, int)
    Candidate signatures:
    void showApplet(String, URL, String, int, int, Map)
    void showApplet(URL, String, int, int)
    void showApplet(String, Applet, int, int)
    void showApplet(String, Applet, int, int, URL)
    void showApplet(String, Applet, int, int, URL, Map)
    void showApplet(Applet, int, int)
    void showApplet(String, URL, String, int, int)

    I didn’t post this on the bug tracker, because I wasn’t sure you wanted the weekly build bugs to show up there. If you do, I’ll go ahead and post it.

    –Steve

  2. Mathias says:

    Hi Steve, thanks for letting me know about this. There is a problem, and I will fix it.

  3. Mathias says:

    I believe I have a fix, but I’m on my notebook with not enough battery left to run the unit tests ;)

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

  5. Mathias says:

    Thanks for your help, Steve. You can download a preliminary DrJava version from my own web server: http://superscalar.org/stuff/drjava-smartrun.jar

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

Leave a Reply