Introduction to Computing Using Java Java language basics K凶心 2008-20092a Michael Fung, Cs&E, The Chinese University of HK
2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 1 Introduction to Computing Using Java Java Language Basics
Common Syntax/ Grammar Notations Arrow-bracketed item <someName> or <someName> Fill in this blank Without the arrows This is a place-holder DO NOT type the arrows in actual codel k Brackets and punctuations Type carefully and place in appropriate location K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK 2
2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 2 Common Syntax/ Grammar Notations Arrow-bracketed item – <someName> or <someName> – Fill in this blank WITHOUT the arrows – This is a place-holder – DO NOT type the arrows in actual code! Brackets and punctuations – { } ( ) [ ] , ; . – Type carefully and place in appropriate location
Quotes and Brackets Single Quote 單帝引號 * Double Quote 雙引號 *() Brackets,/ Parentheses括號/小括號 Square brackets 方括號/中括號 *{} Curly Brackets/ Braces花括號/大括號 *: Semi-colon 分號 * Dot/ Full-stop 點 Comma 逗號 K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK 3
2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 3 Quotes and Brackets ' Single Quote 單弔引號 " Double Quote 雙引號 ( ) Brackets/ Parentheses 括號/ 小括號 [ ] Square Brackets 方括號/ 中括號 { } Curly Brackets/ Braces 花括號/ 大括號 ; Semi-colon 分號 . Dot/ Full-stop 點 , Comma 逗號
ava Naming convention /Capitalization) Examples keyword class. if double. int. for. while packagename javax. swing, javaapplication 12 ClassName String. JOptionPane. Double FileName Hello world. java, JOption Pane class methodName0 showMessage Dialog(), parseInt() fieldName System. out, Drink Dispenser. coke Stock variableName numberOfStudents, body Weight CONSTANT JFrame HEIGHT. Math. PI K|心心 2008-20092a Michael Fung, CS&E, The Chinese University of HK
2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 4 Java Naming Convention (Capitalization) Examples keyword class, if, double, int, for, while packagename javax.swing, javaapplication12 ClassName String, JOptionPane, Double FileName HelloWorld.java, JOptionPane.class methodName() showMessageDialog( ), parseInt( ) fieldName System.out, DrinkDispenser.cokeStock variableName numberOfStudents, bodyWeight CONSTANT JFrame.HEIGHT, Math.PI
Java Program Structure import <packagename>.<someclassname>i import <packagename>* class <className> <type> <fieldName1>i Field (Data Member) <type> <fieldName2>; Declarations <type> <methodName1>(.. Method declarations <type> <methodName2> K国 Michael Fung, CS&E, The Chinese University of HK
2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 5 Java Program Structure Field (Data Member) Declarations Method Declarations import <packagename>.<someclassname>; import <packagename>.*; class <ClassName> { <type> <fieldName1>; <type> <fieldName2>; <type> <methodName1> ( ... ) { } <type> <methodName2> ( ... ) { } }