70 likes | 216 Views
Creating a Java Program. by mr. Hanley 2/2/2007. How do we create a java program?. Steps Create a .java file with an editor Notepad, Jbuilder, BlueJ, JCreator, Eclipse AlgoPractice1.java saved Compile the program using javac javac AlgoPractice1.java
E N D
Creating a Java Program by mr. Hanley 2/2/2007
How do we create a java program? • Steps • Create a .java file with an editor • Notepad, Jbuilder, BlueJ, JCreator, Eclipse • AlgoPractice1.java saved • Compile the program using javac • javac AlgoPractice1.java • AlgoPractice1.class is created if successful • Execute the program by launching VM • javaw AlgoPractice1.class
How does the VM work? • The Java Virtual Machine is responsible for loading in your program and interpreting it on your current platform(Operating System) • Thus, java is compiled at build time and interpreted at run time
How does java live up to Sun’s “write once, run everywhere motto”? library and user .class AlgoPract1.class Sun JVM Windows JVM Mac JVM Solaris (Unix) Windows XP Mac OS Sun Server Hardware PC Hardware Mac Hardware
JVM interprets commands • The JVM must take the .class files that you create via the compiler and translate them into commands for the particular operating system you are running on
Jbuilder’s approach • New class = allows you to edit a .java file (src directory) • Note: Comments don’t compile • Make = attempts to compile your .java file and creates a .class file (classes directory) • Run Project = attempts to load .class file specified in project settings • must have a main method in order to execute
Run project • Choosing Run Project(F9) or the Play Button will attempt to do both of the 2nd and 3rd prior steps • It will compile any files that are changed • It will attempt to start up the JVM