Package <Unnamed>

Deprecated, replaced by wcs.


Class Summary
System Deprecated. Replaced by Applet.

Package Description

Deprecated, replaced by wcs.

This is the homepage of js, a servlet to provide single-file compilation with javac and execution in an applet.


js can be accessed with the GET or POST methods of HTTP. It will reply with a request page, an applet page, or error messages from javac and jar. The table shows possible queries and responses.

? request page with sample program.
?source=java-source request page with Java source.
?url=java-source-URL request page with Java source. A partial URL is resolved against the HTTP referer. Only HTTP is supported.
?source=source&javac=true applet page to execute Java source.
?url=URL&javac=true applet page to execute Java source.
?applet=basename.jar archive for applet (once only).

Event Loop

By default js will return a request page with a sample, editable Java program.

The request page submits Java source text as value for the key source and true for javac.

Alternatively, a URL could be submitted for the key url so that the Java source text is read from the URL. A partial URL would be resolved against the referer which only exists if the submission comes from a page obtained via HTTP. The only protocol supported is HTTP. Further URLs can be specified with url0, url1 and so on; all the files are concatenated into one source.

If either of source or url is not accompanied by true for javac js replies with a request page presenting the Java source text for editing and submission. This is intended to present tutorial examples for execution within some other course material.

If javac has the value true js sets up a temporary directory and a package path, if any, with the source and System placed into the package and executes javac with jay.yydebug on the classpath (for the benefit of System).

If the compilation succeeds js builds a temporary archive file with the class files and jay.yydebug and replies with an applet page referencing the archive. If the compilation fails js replies with the error log from compilation and archiving. All files but the archive file are deleted in either case.

The applet page contains a request with a value for applet so that the archive file will be returned and deleted from the temporary file area.

System Spoofing

The Java source text is searched for the package path, if any, and the name of the first class, which must be public. The search uses pattern matching and accounts for comments and white space but it will fail if package or import paths contain white space or comments. The package may not be java.lang and the class name may not be System.

The applet class System is placed into the same package as the Java source text and is compiled together with the source text. This means that as long as there is no explicit reference to java.lang.System rather then System and as long as there is no reference from another class, System will take over.

System inserts a fresh yyInputStream and yyPrintStream each time the Java program is started in the applet. These streams emulate a terminal in a text area in the applet. System delegates all other methods to java.lang.System.

Apparently, the Java code has access to whatever libraries are available within the web browser, including, e.g., the AWT, as long as it sticks within the security constraints for an applet. Without a policy setup there can be no local file access and no network activity.

There seems to be no reliable way to really terminate a thread. However, standard i/o is disconnected from the Java program when it is "stopped" in the applet and the web browser will forcibly remove the remains once the applet page is closed.

It should be noted that a class is loaded into an applet only once, i.e., if a program is restarted in the applet, the static items of the program are not initialized again.



1.0.1, Ramsau, August 2004.
Axel T. Schreiner.