CS 112
Java on Linux
Logon a Linux machine in the computer lab, using your 112 account.
You may have to reboot.
Developing applets in Java
- Go to the public_html directory (cd public_html).
- Create and go into a directory where you will be doing the current java
work (e.g. cd Lab1).
- Use emacs to create the HTML file and the java file. E.g.
emacs lab1.html
emacs myApplet.java
- Compile with the JDK compiler, javac. E.g.
javac myApplet.java
The resulting file will be a class file, e.g. myApplet.class.
- Make sure the permissions on the html and class files are OK
(i.e. everybody can read these files). Use
ls -l *.html *.class
to see these permissions. If they are not OK, change them with
chmod. E.g.
chmod a+r myApplet.class
or
chmod go+r myApplet.class
- To view the applet, launch a web browser. Go
to the html page you have created. E.g.
http://cs.smith.edu/~112a-aa/Lab1/lab1.html
- If you get an error, look into the Java console for more
details.
- To make corrections, go back to the terminal window. Edit and
compile again your java file.
CAREFUL: if you go back to
the web browser and reload the page, the applet may not be reloaded and you
will see the old version of your applet (before corrections). You
may have to close the browser and launch it again. To simplify this
process, set it to always go to the last visited page, from the Preferences
menu.
Developing applications in Java
- You do not need a web browser.
- Compile the application - as before - with the javac compiler.
javac myApplic.java
- Run it with java myApplic
java myApplic