• 沒有找到結果。

Introduction to Object Oriented Programming

N/A
N/A
Protected

Academic year: 2022

Share "Introduction to Object Oriented Programming"

Copied!
24
0
0

加載中.... (立即查看全文)

全文

(1)

Introduction to Object Oriented Programming

Hsuan-Tien Lin

Deptartment of CSIE, NTU

OOP Class, February 24, 2009

(2)

Clarification: Who Am I?

台大資訊系,大學生,B86506054 1997 年甄試入學(程式設計:3x/100) 1999 年,ACM 世界賽第十名(亞洲冠軍) 2001 年畢業(成績還不錯)

只要肯學,資訊系可以把大家教得很好

加州理工學院,博士班,2003–2008 台大資訊系,助理教授,2008–Present

和大家一起,傳承一生的緣份

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 1 / 24

(3)

Clarifications

Clarification: Course Design

純為一般資訊系大一學生設計(內容、規定、成績) 先修:C 語言

我們不會花時間再教同樣的if/for/... : Check Homework 0 要先會寫基本程式,才能用不同的思維(導向)寫程式

—i.e. 要先會寫普通作文,才能思考寫出各式佳作 怎麼做一個Programmer

銜接:軟體設計模式

怎麼做一個好的Programmer

非一般資訊系大一的同學:

請配合我們的設計

(4)

Clarification: Late Policy

作業遲交:一天處罰20%

作業延期:授課教師決定,須不違反公平性 三天的免罰日

分三次用,一次一天

分兩次用,一次兩天一次一天 一次把三天用完

自行註明、謹慎使用、不能悔改

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 3 / 24

(5)

Clarifications

Clarification: Honesty

NO CHEATING NO LYING NO PLAGIARISM

very very very very serious consequences

(6)

Clarification: Enrollment

大一雙班生:已自動代入 大一單班生:只准一對一換班

重修、輔系、雙主修、醫工所:優先加簽

其他外系:總人數100 人以內管制

確 定了解課程要求再加簽

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 5 / 24

(7)

Clarifications

Clarification: TAs

黃韋誌、鄭琦霖、詹德剛 oop0902@csie.ntu.edu.tw 助教時間(R110)

韋誌 : Wednesdays 18:00–20:00 琦霖 : Thursdays 18:00–20:00 德剛 : Thursdays 18:00–20:00

多多利用助教

(8)

Clarification: Website

http://ceiba.ntu.edu.tw/972oop_even 資訊

作業 進度

投影片連結至討論區 連結至作業區

多多上討論區討論

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 7 / 24

(9)

Clarifications

Clarification: Textbook

(*) K. Sierra and B. Bates, Head First Java, 2nd Ed., O’Reilly, 2005.

(*) P. Wang, Java with Object Oriented Programming, 2nd Ed., Brooks/Cole, 2002.

K. Arnold, J. Gosling and D. Holmes, The Java Programming Language, 4th Ed., Addison-Wesley, 2006.

僅作參考用途

(10)

Questions?

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 9 / 24

(11)

About This Class

Historical

Once upon a time, when I was a freshman in NTU CSIE ...

計程有兩學期,上學期教C,下學期教C++

計概有兩學期,下學期計概教Lisp 和Java 物件導向剛開始流行,有一門研究所的選修課 Then, in my senior year ...

計程計概都變成一學期

每個人都在寫Java 程式:學校、打工、比賽 物件導向程式設計變成大一下必修課

Then, after I graduated from NTU CSIE ...

七年來我沒有再使用過Java

(12)

Should OOP/Java be Required?

Yes! 因為這是我的飯碗,也可能會變成你的 Yes! OOP 能幫助你從程式輸入員變成程式設計師 Yes! Java 能告訴你很多現代語言的先進思維 When I was interviewing for industrial jobs in the US ...

面試四家公司,四家都問了多型(會教到) 其中兩家問了virtual function(會教到)

待遇最好的那家還問了Java 和C 有何不同(會陸續提到)

OOP/Java 和C 一樣,已成基本技

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 11 / 24

(13)

More on OOP

要做一台投影機,需要哪些零件?

bulb fan case button

image processor lens

remote elec. board screw wire

(14)

要做一個CPU ,需要哪些零件?

ic board heat sink wafer pin transister logic gate capacitor

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 13 / 24

(15)

More on OOP

要做一個POO BBS ,需要哪些零件?

machine space network user admin compiler login system manage system user system

board, gem, mail, edit, editor play, pet

vote, refer connection chat, message

(16)

模組化!

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 15 / 24

(17)

More on OOP

有好的模組才有好的系統

easy to debug make the goal clear divide and conquer easy to maintain/manage easy to modify/update easy to reuse

模組化:節省很多未來的時間和心力!

(18)

程 式輸入員v.s. 程式設計師

輸入員 : basic language skill

設計師 : good design skill + good language skill what’s the purpose of the program?

what’s the specialty of the language?

what’s the current need of the program?

what’s the future need of the program?

設計師:

願意用現在的專業付出,來節省未來的時間和心力!

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 17 / 24

(19)

More on OOP

不要只想寫出

用後即丟的程式

(20)

A Few Notes about Java

一個印尼地名和生產的咖啡

Sun Java Platform, 1995 (J. Gosling)

Java Applets, 1995–2001 (alone with .com bubble) Cross-Platform Ability During Running Time

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 19 / 24

(21)

Let’s Go Java

Java Virtual Machine

(courtesy of Prof. Chuen-Liang Chen)

Compile-time Environment

Hardware Environment (Java Platform) Class Loader

& ByteCode Verifier

Java Class Library Java

Source ( java)

( )

Java

Verifier Library

Java (.java)

Java

ByteCodes Just In Time

Virtual Machine Virtual Machine Java

Interpreter

Runtime System Java

Compiler

y

move locally or through

network

Just In Time Compiler

Runtime System Java

ByteCodes

( class) Operating System

(.class)

(.class) Operating System

Hardware Hardware

(22)

Your Java Environment

JRE (Java Runtime Environment): for users, JVM + basic libraries JDK (Java Development Kit): JRE + compilers + ...

—jdk-6u12-windows-i586-p.exe or other platform Document —jdk-6-doc.zip

some editions:

SE: Standard Edition EE: Enterprise Edition ME: Mobile Edition 課程網頁上有參考資料

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 21 / 24

(23)

Let’s Go Java

From HelloWorld.c to HelloWorld.java

/* HelloWorld.c */

#include <stdio.h>

int main(){

printf("Hello World\n");

return 0;

}

---

/* HelloWorld.java */

import java.lang.*;

public class HelloWorld{

/** The comment that will show up in the doc

*/

public static void main(String[] argv){

System.out.println("Hello World");

(24)

Your Work Cycle

1 edit your Java source file(s)

2 compile

javac HelloWorld.java output: HelloWorld.class

3 execute

java HelloWorld

4 generate document

javadoc -d doc/ HelloWorld.java

H.-T. Lin (NTU CSIE) Introduction OOP(even) 02/24/2009 24 / 24

參考文獻

相關文件

• The Java programming language is based on the virtual machine concept. • A program written in the Java language is translated by a Java compiler into Java

OOP: organized DATA + organized code (ACTION) using classes as the basic module. action are closely coupled

• Copy a value from the right-hand side (value or expression) to the space indicated by the variable in the left-hand side.. • You cannot write codes like 1 = x because 1 cannot

• Instead, static nested classes do not have access to other instance members of the enclosing class. • We use nested classes when it

• manipulating object status (partially done: instance variable assignments).. • deleting objects —[TODO 3]

• Instead, static nested classes do not have access to other instance members of the enclosing class. • We use nested classes when it

• Non-static nested classes, aka inner classes, have access to other members of the enclosing class, even if they are declared private. • Instead, static nested classes do not

Generic methods allow type parameters to be used to express dependencies among the types of one or more arguments to a method and/or its return type.. If there isn’t such a