Getting and using java J2SDK freely download from http://java.sun.com ●Your first cup of Java”: O detailed instructions to help you run your first program O http://java.sun.com/docs/books/tutorial/getStarted/cupojava/in dex.html oAll text editors support java O Vi/vim,emacs,notepad,wordpad O Just save to java file o Have IDEs that comparable to Visual Studio O JCreator(simple) O Eclipse (more complicated)
Getting and using java l J2SDK freely download from http://java.sun.com l “Your first cup of Java”: ¡ detailed instructions to help you run your first program ¡ http://java.sun.com/docs/books/tutorial/getStarted/cupojava/in dex.html l All text editors support java ¡ Vi/vim, emacs, notepad, wordpad ¡ Just save to .java file l Have IDEs that comparable to Visual Studio ¡ JCreator (simple) ¡ Eclipse (more complicated)
Compile and run an application oWrite java class Foo containing a main( method and save in file“Foo.java” OThe file name MUST be the same as class name Compile with:javac Foo.java Creates compiled .class file:Foo.class Run the program:java Foo ONotice:use the class name directly,no .class!
Compile and run an application lWrite java class Foo containing a main() method and save in file “Foo.java” ¡The file name MUST be the same as class name lCompile with: javac Foo.java lCreates compiled .class file: Foo.class lRun the program: java Foo ¡Notice: use the class name directly, no .class!
Hello World! File name:Hello.java /Our first Java program-Hello.java * Command line public class Hello arguments //main() public static void main String[]args ) System.out.println("hello world!"); Standard output,print with new line
Hello World! /* Our first Java program – Hello.java */ public class Hello { //main() public static void main ( String[] args ) { System.out.println( "hello world!" ); } } File name: Hello.java Command line arguments Standard output, print with new line
About class o Fundamental unit of Java program OAll java programs are classes oEach class define a unique kind of object a new data type) ● Each class defines a set of fields,methods or other classes opublic:modifier.This class is publicly available and anyone can use it
About class lFundamental unit of Java program lAll java programs are classes lEach class define a unique kind of object ( a new data type) lEach class defines a set of fields, methods or other classes lpublic: modifier. This class is publicly available and anyone can use it
Things to notice o Java is case sensitive o whitespace doesn't matter for compilation o File name must be the same as one of the class names,including capitalization! At most one public class per file o If there is one public class in the file,the filename must be the same as it oGenerally one class per file
Things to notice lJava is case sensitive lwhitespace doesn’t matter for compilation lFile name must be the same as one of the class names, including capitalization! lAt most one public class per file lIf there is one public class in the file, the filename must be the same as it lGenerally one class per file