120 likes | 211 Views
Java Programming. Compiling and Interpreting Java. Compile the Program. Enter the source program with an editor such as notepad [Start/Programs/Accessories/Notepad] Save the program on a diskette or zip disk: “ Exer1ii.java ” where the ii are your initials
E N D
Java Programming Compiling and Interpreting Java
Compile the Program • Enter the source program with an editor such as notepad [Start/Programs/Accessories/Notepad] • Save the program on a diskette or zip disk: “Exer1ii.java” where the ii are your initials • Must be the same name as the class name (line two of program) • Must have the java extension • Use quotation marks as shown to avoid the txt extension with notepad • Program must be saved before compiling • Window can be left open [for ease in modifying the program]
Compile the Program from the C: /java 1.5/jdk/bin directory • To compile the program: • Start/Run Type in cmd and press enter • At the C: prompt: • CD \java 1.5\jdk\bin [enter] • If the source program is not in this directory: • At the C:\java 1.5\jdk\bin> prompt: copy a:Exer1ii.java *.* • At the C:\java 1.5\jdk\bin> prompt: javac Exer1ii.java where Exer1ii is the name exactly as it appears on the public class line • If you get an error, • Open or maximize the notepad window; correct the error; save it • Recompile the program • Note example in class: • How to determine line in error • Crimson’s file editor versus notepad • Crimson’s editor is available
Executing the Program • At the c:\java 1.5\jdk\bin prompt: • java Exer1ii
Exiting/Copying Files • Before exiting the cmd session: • Remember to copy the program from the C drive back to the flash drive. It will be deleted from the C drive when the computer is turned off and rebooted • At the c:\java 1.5\jdk\bin prompt: copy Exer1kk.java x:*.* (where x is the flash drive) • OR you may copy the java file to your disk after exiting cmd using My Computer • When finished with the “cmd” session, • exit the window by clicking on the x in the upper right corner OR • type exit and press enter.
Check/Debug • Check the output of your program: • If you use 7% interest rate and a $150,000 loan for thirty years, the payment should be $597.96 • Total payments should be approximately 360 * $597.96 [last payment is a little less] • If the totals are incorrect, correct the source coding with notepad, re-compile and re-execute the program.
There’s an easier wayTo compile/execute Java • In Lumkin Labs, the crimson editor has already been installed. • There is a short cut on the desktop • Double click on the short cut • Under the file menu, • Either open your program (with a .java extension) OR • Create a NEW file • Be sure to save your file in the java 1.5/jdk/bin folder with the .java extension. In Lumpkin Labs, it MUST be in this folder to work! • To compile your program: Ctrl -1 • To execute your program: Ctrl-2 • Be sure to copy your program to your drive before turning off the machine.
To install java on your home machine • Download java from www.java.sun.com. Be sure to select the windows edition. Select the EE (enterprise edition) of the sdk (software development kit) version 1.5 • This will be demonstrated in class. • Install the software • Notice the name of the folder in which the software is installed. It may not be java 1.5 Name the folder something that you will remember.
To install the crimson editor on your home machine • Download the crimson editor from www.crimsoneditor.com • Install the editor • First time your click on the desktop icon: • You will receive a message that the file is corrupted – but to ignore the message if it is the first time. • Change the preferences • Top menu: tools/preferences • New window: Select user tools • Select the first “empty slot” in the control at the top-center. It is usually ctrl -1 • Menu text: java compile • Command: C:\java 1.5\jdk\bin\javac.exe (note: C is capitalized) • Argument: $(FileName) • Initial Dir: $(FileDir) • Hot Key: None • Be sure capture output is checked
To install the crimson editor on your home machine(continued) • First time your click on the desktop icon: • Change the preferences (continued) • Select the second “empty slot” in the control at the top-center. It is usually ctrl -2 • Menu text: java execute • Command: C:\java 1.5\jdk\bin\java.exe (note: C is capitalized) • Argument: $(FileTitle) • Initial Dir: $(FileDir) • Hot Key: None • Be sure capture output is checked • NOTE: on both ctrl-1 and ctrl-2….that name of the directory (java 1.5\jdk\bin) is the folder name in which you installed java!
Objects • In the future, we will have a second java file for an object. • When you have multiple java files (for the object and the executable) • Compile the object file(s) first: • Compile the executable: • Execute the executable:
Short Program for Demonstration public class JavaRules { public static void main (String[] args) { System.out.println(“Java Rules”); } }