Samuel Marateck, 2008 Note that the jdk bundle is already on you MAC; it's pre-installed. To compile and execute your program using the command line on the MAC, do the following: 0. Get TextEdit from the Applications folder on the Finder. 1. On TextEdit menu choose Preferences, click the New Document tab, and then choose plain text. Then click the Open and Save tab and make sure that "Add '.txt' extension to plain text files" is unclicked. 2. Type your program and save to the desktop, e.g., saveAs Prog1.java. The ".java" part is essential. If the system asks whether you want to save your program as ".txt" or ".java", choose ".java". 3. Using the finder (it's the icon at the bottom left of your screen) get the utilities folder in the applications folder and there click the terminal icon. In terminal,type: cd desktop. 4. At what is called the "command line" Javac your program, i.e., type javac Prog1.java If your program compiles, you will get no message. 5. Execute your program, e.g., java Prog1 If you want to run an applet, do the following at the command line: 1. Compile your program, e.g., javac Hw2.java 2. Copy the Temp.html file from the class page or from the example directly below, substitute yout program name in the code line, e.g., code = "Hw2.class" 3. Save the html file to the desktop. If you don't do this, your applet will not execute. 4. Type: appletviewer Temp.html An example of a html file (where the background color is white) is
The command line uses the Unix operating system commands. According to the Apple web site: "Mac OS X is now a fully certified UNIX operating system, conforming to both the Single UNIX Specification (SUSv3) and POSIX 1003.1." Some commands are: ls -- lists the files in the present directory. pwd -- prints the present working directory. cd -- changes directory mkdir -- makes a new directory ls -a -- lists all the files including the hidden ones. ls *.java -- lists the files with extension .java. The * is the wild card character and here indicates any file name ending with .java. Can also be written here as ls *.j* . rm prog -- removes the program prog from the current directory rm *.class -- removes all .class files ps -u YourName -- On a time-sharing system, lists all the programs running under the user name "YourName" and gives the job number kill job number -- terminates execution of the program with job number appearing to the right of "kill". history -- lists the Unix commands you have used in the order you used them. !! -- repeats the last Unix command !ls -- repeats the last Unix command beginning with ls !r -- repeats the last Unix command beginning with r, most likely the rm command.