EDITING, COMPILING, LINKING AND RUNNING JAVA PROGRAMS IN LINUX 1. Connecting into Linux: a) From home: i) Connect to heart via telnet. If telnet is not installed the follow these instructions to enable it. http://social.technet.microsoft.com/wiki/contents/articles/910.how-to-enable-telnet-client-in-windows-7.aspx If you are using a Microsoft operating system on your home computer, select Start | Run and type telnet heart.cecs.csulb.edu in the text box. ii) Login to heart at the prompts with your account and password. iii) At the prompt, type ssh linux and follow the login and password prompts. iv) You can repeat the telnet heart and ssh linux commands to open as many windows as you need. Typically, you might want one window per file you are editing and another window to compile and execute your program. v) Type logout to exit the linux server. vi) Type logout to exit heart. b) From school: i) Use the SSH Linux icon on the desktop. ii) Login using your cecs account username and password. iii) Type logout to exit Linux. You must logout from Linux; otherwise, other people will have access to your account. 2. Editing source files: a) Use either the vi or vim editor (can be difficult to use) or pico (easy to use). b) Save the source file with a .java extension. 3. Compiling and linking programs (done in one step): a) For one source file, enter javac filename. b) For multiple source files, enter javac filename1 filename2 filename_etc. c) Correct any compiler errors and use javac to recompile the file(s). d) The java compiler will create .class files for each of the respective .java files. The class file contains the bytecode. 4. Interpreting and running the program a) Type java filename to run the program where filename is the name of the file containing the main method. Whereas when compiling the program, you typed the .java extension as part of the file name (e.g. javac HelloWorld.java), when you run the program you omit the .java extension (e.g. java HelloWorld). b) To direct the output to a file, enter the command 'script'. Then everything you run will be output to a file named typescript until you type exit (or control-d). You can ftp this file to get it to post on Beachboard. 5. Submitting code and output. a) In lab i) Use FileZilla to transfer the code and output to the lab machine. Submit both to Beachboard. b) At home i) Start your web browser. ii) In the URL, type ftp://account@heart.cecs.csulb.edu, replacing account and password with your own account name and password. iii) You will see a display of all directories and files in your Linux account. Drag the files you want to your desktop and submit to Beachboard.