当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

Introduction to Computing Using Java(PPT讲稿)Java Language Basics

资源类别:文库,文档格式:PPT,文档页数:41,文件大小:295KB,团购合买
点击下载完整版文档(PPT)

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 or 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 – or – 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 .i import * class i Field (Data Member) ; Declarations (.. Method declarations 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 .; import .*; class { ; ; ( ... ) { } ( ... ) { } }

Java Program Examp import java.util. Vector import javax. swing. class CurrencyConverter double rateHktoEuro =0.0885: Field (Data Member) double rateHKtoUS =0.128; Declarations double convertEuro2us( double amoun tEuro / details skipped Method declarations double convertUS2HK( double amountS / details skipped K国 Michael Fung, CS&E, The Chinese University of HK 6

2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 6 Java Program Example Field (Data Member) Declarations Method Declarations import java.util.Vector; import javax.swing.*; class CurrencyConverter { double rateHKtoEuro = 0.0885; double rateHKtoUS = 0.128; double convertEuro2US ( double amountEuro ) { // details skipped } double convertUS2HK ( double amountUS ) { // details skipped } }

Data Item declaration x Data items are used to store data Such as fields. local variables. constants t We give name(an identifier) to each data item e. g. Ma liu shui, Tai Po road, shatin is a piece of data This information is called CUHKaddress k Each data item must bear a type e.g. CUHKaddress is of type String(text) K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK

2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 7 Data Item Declaration  Data items are used to store data. – Such as fields, local variables, constants, …  We give name (an identifier) to each data item. – e.g. “Ma Liu Shui, Tai Po Road, Shatin.” is a piece of data. This information is called CUHKaddress.  Each data item must bear a type. – e.g. CUHKaddress is of type String (text)

Identifier Names introduced by programmers in computer languages are called identifiers e Address he11。Wor1d One2Free just say hi Ring K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK 8

2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 8 Identifier Names introduced by programmers in computer languages are called identifiers. – e.g. Address hello_World One2Free j_u_s_t___2___say___hi Ring

Java identifiers t Valid components ABCDEFGHIUKLMNOPORSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 underscore Space is disallowed x Must start with a letter or underscore e.g. 12Free is disallowed while One 2Free is okay x Case sensitive e.g. Hello is not equal to hello nor HellO K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK

2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 9 Java Identifiers Valid components – ABCDEFGHIJKLMNOPQRSTUVWXYZ – abcdefghijklmnopqrstuvwxyz – 1234567890 – _ “underscore” Space is disallowed. Must start with a letter or underscore. – e.g. 12Free is disallowed while One2Free is okay Case sensitive. – e.g. Hello is not equal to hello nor HellO

Choice of Identifiers t easy to understand and remember e.g. noofEnquiries, Trees, timeToLive name, address, count isok, Listi experimentl2 t May use multiple words(without space!) e.g. grade point average, myBirthday numberofstuder七s Dont be laz e.g. i,j,k,a b, c d e K凶心 2008-20092a Michael Fung, CS&E, The Chinese University of HK

2008-2009 2a Michael Fung, CS&E, The Chinese University of HK 10 Choice of Identifiers Easy to understand and remember. – e.g. noOfEnquiries, Trees, timeToLive, name, address, count, isOK, List, experiment12 May use multiple words (without space!). – e.g. grade_point_average, myBirthday, numberOfStudents Don’t be lazy! – e.g. i, j, k, a, b, c, d, e, …

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共41页,可试读14页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有