CompileJava.net
overview
CompileJava is a barebones online Java IDE and compiler that was created out of a need to allow students to compile their “in-class” (no pun intended) Java programs on computers that did not have Java installed.
requirements
Since this application was initially designed for use in a single high-school classroom, I was given these specific requirements:
- application should be web-based because we cannot install new software on the classroom laptops
- it must support Java 7 (at the time it was written; it has since been updated to use the latest Java version)
- students should not need to create accounts or register to use the application
- applet support would be nice to have, but is not essential since it’s beyond the curriculum; some of the advanced students may wish to play around with it
- ability to paste source code to Pastebin or similar, so that it can be shared with (the instructor) and other students
- ability to download the current project for submission
solution
Implementation. This could have been done, trivially, in a number of languages, but I chose to use PHP because that’s what I am familiar with.
Security. You could imagine that, if this a public web service, some people might try to abuse it. They might try to run infinite-loops (or accidentally), perhaps try to read and write to the file system, download things over the network, or run code that would in some way harm the server or affect the service for other users.
I am not a Java expert; I can write Java programs and work in Java projects with other people, but I certainly do not know all of the ins and outs of how the JVM works or anything beyond the basics. However, I know that some hard limits had to be set: no filesystem access, no network access, and execution would have a hard time-limit.
The first two requirements can be achieved with a basic Java security policy, shown below:
grant {
permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";
permission java.util.PropertyPermission "java.specification.version", "read";
permission java.util.PropertyPermission "java.specification.vendor", "read";
permission java.util.PropertyPermission "java.specification.name", "read";
permission java.util.PropertyPermission "java.vm.specification.version", "read";
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name", "read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";
};Permissions are otherwise pretty liberal; you can see the network interfaces (though nothing useful will appear), and you can weasel around the system if you really put your mind to it. This is what happens if you try to make a network request, and similarly for filesystem operations:
Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "<<ALL FILES>>" "execute")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkExec(SecurityManager.java:799)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1018)
at Test.doCommand(Test.java:26)
at Test.main(Test.java:17)The execution time limit is very simple – we use the built-in timeout command in Linux which will kill a process if it is still running after a specified amount of time has passed.
The nuclear option is to simply restore that virtual machine from a previous backup, which amounts to less than 10 seconds of downtime.
features
Beyond the original requirements, I allow for some neat keyboard shortcuts, dozens of editor themes, importing of Gists, and more. The biggest feature is that CompileJava is fast, free, and lets you compile code right from the homepage.
One interesting feature that none of the “competing” applications use, is the ability to edit multiple classes in the same editor window. This makes it possible to quickly test and share code without having to worry about multiple files, and you can see everything in one place. The application splits each public class into its own file before it compiles and executes your program.
results
For its intended purpose, I would say CompileJava has been a tremendous success. I still receive emails from high-school teachers and sometimes even the occasional college professor telling me how useful CompileJava is to their students because of its simplicity.
And to this day, I receive a few emails every week from people asking for the source code, asking to integrate with their own software, or general use questions. I truly appreciate the interest, but sometimes I feel downright guilty when I have to tell someone that I can’t help them because CompileJava wasn’t designed to do what they are trying to do.
Anyway, quite a few organizations are using CompileJava every day. Here are a few that run dedicated installations:



update 1
Here’s an article I wrote about the long-term effect of this project.
update 2
This site was mentioned in the O’Reilly book Think Java: How to Think Like a Computer Scientist (2016) by Allen B. Downey and Chris Mayfield.
update 3
This site was mentioned in the Apress book Regex Quick Syntax Reference: Understanding and Using Regular Expressions (2018) by Zsolt Nagy.
update 4
This site was mentioned in the Wiley book Practical Java Programming for IoT, AI, and Blockchain (2019) by Perry Xiao.
screenshots
Main View…
