Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles What we will cover… • Basic Java Programming (Review) • Creating, Compiling, Executing a Java Program • Using an IDE • Textpad • Eclipse • JDK Creating Compiling, and Executing a Java Program • You have to create your own program • Make sure it works • If it doesn’t compile you will not be able to run it! • You can compile and run from a command window! Compiling and Running a File • Write your program • Save as .java • Type • javac filename.java • Javac = java compile • Compiles to a .class file(s) • Run • java classname.class • Runs this within a JVM (Java Virtual Machine) The Java Virtual Machine • The Java Virtual Machine (JVM) is the runtime environment • A virtual computer that runs your environment • Runs “around” the CPU • Creates a layer between the CPU and the Java Program • Java is compiled down to bytecode • Not machine language • JVM is run between the CPU and the Program • Slower than something run directly on the CPU • This makes the program portable • Different JVM’s for different computers (CPUs) Programming Style • Make sure you do the following: • Appropriate Comments • Proper Indentation and Spacing • Space operators • Block Styles • Next-line style • End of line style Errors • There are three possible errors in java • Syntax Errors • Problems with spelling • Missing characters • Runtime Errors • Abnormal termination • Logic Errors Using an IDE • Use Textpad or Netbeans • Eclipse is a very powerful IDE we will cover later • Good luck! Textpad • Go to Textpad • https://www.textpad.com/download/index.html • Download The IDE • Officially Shareware • (Free to download, should pay) Textpad (2) • Install and then run • Textpad will install on your computer. Compiling and Running Using the Command Line • Use a text editor (Whatever you choose) • Save the file as .java • Open a command window: • Click the start button • Type in cmd • (or look for command window in programs) Compiling and Running Using the Command Line (2) • Use DOS commands to locate your java file • http://www.colorado.edu/geography/gcraft/tips/doshelp.html • Get to the location of your file • Type javac filename.java • Should be the same name as your class Compiling and Running Using the Command Line (3) • Look at our example: • Class name is Hello • Filename should be Hello.java • When we compile, should result in the class name • Hello.class • To run the program, we must run the class through the JVM (called “java”) • java Hello • Note: don’t type in • java Hello.class (WRONG) Compiling and Running Using the Command Line (4) • Results: Compiling and Running Using the Command Line (5) • Note: If you just want to use the command javac automatically (without using the path name), you must add the path to the computer path • Type in “path” at the command line • Gives all folders to look for commands Compiling and Running Using the Command Line (6) • After you install the JDK, add the bin folder to the path • To change the system path (Windows), perform these steps: • Start the System Control Panel applet (Start - Settings - Control Panel - System). • Select the Advanced tab. • Click the Environment Variables button. • Under System Variables, select Path, then click Edit. • Other ways (try Windows version first): • After this, you can call javac and java (jvm) directly Using Eclipse • Eclipse is a very powerful IDE that can be used to develop Java programs • Very complicated to use at first • Complex now, later very convenient • Download • http://www.eclipse.org/ • Install • Very large file Eclipse (2) • Creating a new project • Instead of creating a new file, you must first create a project • Holds all files associated with the program • Not as necessary now, effective later • File -> New -> Java Project • Type demo in the Project Name field • Select “Use project folder as root for sources and class files” • Puts java and class files in same folder • Click Finish Eclipse (3) • Creating a new Class • File -> New -> Class • Opens New Java Class Wizard • Type Welcome • Our class name • Check option public static void main(String[] args) • Click Finish Eclipse (4) • Compiling and Running a Class • Right-click the Class in Project Display • Select Run -> Java Application • In context menu • Output is displayed in Console pane