【正文】
An Introduction to Java Application Yaoxiaoling Topic ? Our First java Program ? Output statements ? Variable ? Input statements ? Arithmetic operators ? Memory ? Decisionmaking statements ? Relational and equality operators Our first java Program ?Text out “Wele to java programming” Talking ? What was wrong with your program? ? What will you do if we want to edit and run our java program? ? What is function of your program? Edit java program in notepad public class Message { /** * 這是一個 main 方法。 */ public static void main(String [] args) { /* 輸出此消息 */ (歡迎來到 Java 世界! )。 } } 演示編輯和保存 Java程序 …… 依次選擇 程序 ?附件 ?記事本 單擊 開始 編譯和運行 Display how to pile and run java program…… 單擊 開始 進入程序所 保存的目錄 依次選擇 程序 附件 命令提示符 編譯 Javac 運行 java Message 輸出結(jié)果 Before you begin ?We need Java development Environment ? J2SE Development kit ? ? Editor ?notepad editplus UltraEdit ? IDE ?Jcreator Eclipse NetBean Let us install JDK ? JDK Environment ? Java directories ? bin : executable files such as ? lib: java library classes files. ? include: local files. ? demo: display programs. ? jre: java running environment After we installed jdk…. ? Setting environmental variables ? Path variable ? Classpath variable Setting the Path Variable 選擇高級 Setting the classpath Variable 選擇高級 classpath C:\Program Files\Java\\lib\。 C:\Program Files\Java\\lib\tools.jar。 What the function of our program? ?Output a literal word ? Wele to java progaramming. What we learn from this program ? Java program structure ? Output statement java program structure ? source file, class , method ,statement Put a class in a source file Put methods in a class Put statements in a method Our first java program ? What goes in a source file? ? What goes in a class files? ? What goes in a method files? public class Wele1{ } Class public static void main(String args[]){ } method (“Wele to java programming”)。 statements Reading time ? ment ? Comment is used to enhance your program readability Questions: 1. How many kinds of ment methods does Java provided? 2. Tell us difference among these ments? ? Class ? class is a logical unit of java program. Questions: 1. How should we declare a class? 2. How should we name a legal identifier? 3. What is a good classname? 4. How should name a Java file? Reading Time – Method – What is feature of main method? – What is function of this method? – Output statement – What is ? – What is println? – How should we pile and execute a java program? – How should we enhance our program readability? First Program in Java: Printing a Line of Text (Cont.) ? Comments start with: // ?Comments ignored during program execution ?Document and describe code ?Provides code readability ? Traditional ments: /* ... */ /* This is a traditional ment. It can be split over many lines */ Another line of ments ? Note: line numbers not part of program, added for reference 1 // Fig. : 2 // Textprinting program. First Program in Java: Printing a Line of Text (Cont.) ? Blank line ? Makes program more readable ? Blank lines, spaces, and tabs are whitespace characters ? Ignored by piler ? Begins class declaration for class Wele1 ? Every Java program has at least one userdefined class ? Keyword: words reserved for use by Java ? class keyword followed by class name ? Naming classes: capitalize every word ? SampleClassName 3 4 public class Wele1 First Program in Java: Printing a Line of Text (Cont.) ? Java identifier ?Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) ?Does not begin with a digit, has no spaces ?Examples: Wele1, $value, _value, button7 ? 7button is invalid ?Java is case sensitive (capitalization matters) ? a1 and A1 are different ? In chapters 2 to 7, use public class ?Certain details not important now ?Mimic certain features, discussions later 4 public class Wele1 First Program in Java: Printing a Line of Text (Cont.) ? Saving files ?File name must be class name with .java extension ? ? Left brace { ?Begins body of every class ?Right brace ends declarations (line 13) 4 public class Wele1 5 { First Program in Java: Printing a Line of Text (Cont.) ? Part of every Java application ? Applications begin executing at main ? Parentheses indicate main is a method (Ch. 3 and 6) ? Java applications contain one or more methods ? Exactly one method must be called main ? Methods can perform tasks and return information ?void means main returns no information ? For now, mimic main39。s first line ? Left brace begins body of method declaration ? Ended by right brace } (line 11) 7 public static void main( String args[] ) 8 { First Program in Java: Printing a Line of Text (Cont.) ? Instructs puter to perform an action ? Prints string of characters ? String series characters inside double quotes ? Whitespaces in strings are not ignored by piler ? ? Standard output object ? Print to mand window (., MSDOS prompt) ? Method ? Displays line of text ? This line known as a statement ? Statements must end with semicolon 。 9 ( Wele to Java Programming! )。 First Program in Java: Printing a Line of Text (Cont.) ? Ends method declaration ? Ends class declaration ? Can add ments to keep track of ending braces 11 } // end method main 13 } // end class Wele1 First Progr