- A Concurrent Affair - https://www.concurrentaffair.org -

Simpler ACM Java Task Force Programs in DrJava

Daniel L. Schuster [1], Professor of Computer Science & Mathematics at Western State College of Colorado and author of The Free Java Book [2], had asked me at SIGCSE 2010 [3] if we could simplify runing ACM Java Task Force programs in DrJava [4]. Other IDEs can run ACM Java Task Force [5] 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 [6][ ] 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 [7] (direct link: drjava-weekly-20100508-r5249 [8]).

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 [9] 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.

[10] [11]Share [12]
6 Comments (Open | Close)

6 Comments To "Simpler ACM Java Task Force Programs in DrJava"

#1 Comment By StephenGilbert On May 27, 2010 @ 16:49

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 Comment By Mathias On May 27, 2010 @ 17:06

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

#3 Comment By Mathias On May 27, 2010 @ 17:46

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

#4 Pingback By A Concurrent Affair » Blog Archive » Fixed DrJava “Smart Run” Problem On May 28, 2010 @ 04:49

[…] Yesterday, Steve Gilbert notified me of a problem with the “smart run” feature I had introduced to simplify running applets and ACM Java Task Force…. […]

#5 Comment By Mathias On May 28, 2010 @ 04:50

Thanks for your help, Steve. You can download a preliminary DrJava version from my own web server: [13]

#6 Pingback By Another Bugfix for Smart Run | A Concurrent Affair On July 30, 2010 @ 00:15

[…] while ago, I introduced what was supposed to be a “Smart Run” feature, a simpler way of running Java programs, ACM Java Task Force programs, and applets. It sort of […]