1 / 20

Introduction to Java Programming Lecture 1: Introduction To Java And Computers

Introduction to Java Programming Lecture 1: Introduction To Java And Computers. 2/23 2010. Text Book For Lab (Not Required). Java 2 程式設計從零開始 作者 : 何嘉益、黃世陽 李篤易、張賀閔 附 CD 包含書中範例檔 本書使用 JDK 6.0 上奇科技 出版. Text Book For Lab (Not Required). 最新 Java2 程式設計實例入門 ( 增訂第三版 )

shino
Download Presentation

Introduction to Java Programming Lecture 1: Introduction To Java And Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Java ProgrammingLecture 1: Introduction To Java And Computers 2/23 2010

  2. Text Book For Lab (Not Required) • Java 2 程式設計從零開始作者 : 何嘉益、黃世陽 李篤易、張賀閔 • 附 CD 包含書中範例檔本書使用 JDK 6.0 • 上奇科技出版

  3. Text Book For Lab (Not Required) • 最新 Java2 程式設計實例入門(增訂第三版) 作者 : 高橋麻奈 • 附 CD 包含書中範例檔本書使用 JDK 5.0. • 博碩文化 出版 • 3

  4. Text Book Recommended • Java How To Program 8th Edition, by Deitel & Deitel • Book includes a CD-ROM with Java programs and other supplemental materials. • 全華圖書代理 • 4

  5. Text Book Recommended • Introduction to Java Programming, Brief (8th Edition), by D. Liang • Book includes a CD-ROM with Java programs and other supplemental materials. • 全華圖書代理

  6. 這門課會用到的軟體 • Sun’s JDK (Required 必備的Java 開發工具) : Java Development Kit, JDK 6 Update x • The JCreator IDE (Optional選用的編輯、編譯軟體) (IDE : Integrated Development Environment) • NetBeans IDE (Optional) • 6

  7. What Is a Computer? • Computer • 可以輸入、儲存資料,可以對資料進行計算與邏輯運算,可以輸出、顯示資料的機器 • Computer programs • 由一行一行的程式組成,用來處理資料 • Hardware • 電腦的實體設備,包括 : 主機板、CPU、顯示卡、硬碟、記憶體、光碟機 … 等 • Software • 可以在電腦上執行的 Programs

  8. Computer Organization • Six logical units of computer system • Input unit (輸入) • 滑鼠、鍵盤 • Output unit (輸出) • 螢幕、印表機、喇叭 • Memory unit (記憶體) • 電腦運作期間,用來放置資料 • Arithmetic and logic unit (ALU) • 執行計算與邏輯的運算 • Central processing unit (CPU) • 控制、指揮 軟硬體的運作 • Secondary storage unit (輔助儲存設備) • 硬碟、Floppy disk  2003 Prentice Hall, Inc. All rights reserved.

  9. Computer Instructions • 計算機程式(Computer programs)由一行一行的程式指令(instructions)組成 • 指令以二進位(binary)的數字存放在記憶體(RAM)中,稱之為機器語言(machine code)  例如 01001010 00001111 “add to” “register 15“ (加到) (暫存器 15) • 指令也可能包含資料(data) 例如 01001010 0000111100000000 01100100 (Add 100 to register 15)

  10. Computer Instructions • 記憶體中的每一個位元組(byte)都有相對應的地址 Address Contents 200 01001010 201 00001111 202 00000000 203 01100100 204 01011011 205 01100101 one computer instruction another instruction

  11. Execute a program • 執行(execute)一個程式時,作業系統(The operating system : Windows, Linux or MacOS) 有一個工具程式叫做 loader,會把程式從硬碟複製到記憶體中,我們只要“告訴” CPU 程式第一行的地址,然後讓程式從第一行開始執行就行了 • 但是我們怎麼知道什麼二進位的數字可以組成一個我們希望電腦執行的程式呢 • 這就是我們學像Java這種程式語言的目的

  12. Programming Languages • 高階程式語言(High-level programming languages)是利用我們平常所使用的語言(英文)及符號來寫程式 • 編譯器(compiler)是一個程式,可以把高階程式語言轉換成機器語言 • C++ C Fortran Java VB 都是高階程式語言

  13. Typical Compilation • z = x + y; 10010101 01100001 (load x into reg 1) 10100110 11010001 (add y to reg 1) 10111100 01010001 (store reg 1 into z) • 但是: compiler是針對某一種CPU設計的,所以這些機器語言的指令只能給這種CPU執行 編譯器把這些指令編譯成機器碼:

  14. Java Compilation • z = x + y; 0001 1010 (iload_0) 1010 1011 (iload_1) 0110 0000 (iadd) 0011 1101 (istore_2) 編譯器把這些指令編譯成“虛擬”的機器碼 (“virtual“ machine code),稱為“位元碼“(“byte codes”) :

  15. Java Execution • 位元碼可以經由直譯器(Java interpreter)來執行Java interpreter (JVM - Java virtual machine) 可以把位元碼轉換成適用於某種CPU的機器碼 • 所以,不管是哪一種電腦,只要這個電腦有安裝適用於這個電腦的JVM,就能執行任何的Java byte codes

  16. Java Code File 在這門課中我們會碰到 3 種 java 的檔案 • 原始程式碼(Source Code) : 副檔名為 .java 的檔案 • 位元碼(Byte Code) : 副檔名為 .class 的檔案 • Java Archive :副檔名為 .jar 的檔案(之後我們會解釋這個) 我們利用Java SDK (SE Development Kit) 把 .java 檔案編譯(compile) 成 .class 檔 而接著利用 JRE (Java Runtime Environment)來執行 .class檔

  17. History of Java • A group of 13 Sun employees including James Gosling started the “Green Project” in 1991 with the intention of planning for the next wave in computing. • Gosling’s contribution to the project was an entirely new processor independent language call “Oak”. • 17

  18. History of Java (continued) • To make a long story short, people at Sun decided to use this new language for the web. • At the Sun World conference in May 1995, Marc Andreessen of Netscape announced an agreement to integrate Java into its browser. This meant that webpages were no longer going to be static. • Over the next few years, java became very popular for writing applets (small programs included on webpages) • Today in addition to writing applets, Java is used for writing large applications as well as applications for mobile devices • For more on the history of Java, check out: http://java.sun.com/features/1998/05/birthday.html

  19. Basics of a Typical Java Environment • Java programs normally undergo five phases (Java 程式的執行) • Edit (編輯) • Programmer writes program (and stores program on disk) • Compile (編譯) • Compiler creates bytecodes from program • Load (載入) • Class loader stores bytecodes in memory • Verify (安全性驗證) • Verifier ensures bytecodes do not violate security requirements • Execute (直譯與執行) • Interpreter translates bytecodes into machine language  2003 Prentice Hall, Inc. All rights reserved.

  20. Another Basic Step for Java Programming • Debugging (除錯) • Check program execution and output to ensure program compiles and runs as expected • If it doesn’t, make corrections in the edit phase and repeat the remaining steps • 20

More Related