Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth.

Similar presentations


Presentation on theme: "© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth."— Presentation transcript:

1 © 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Chapter 1: Introduction to Computers and Java

2 © 2010 Pearson Addison-Wesley. All rights reserved. 1-2 1.3 Software Software refers to the programs that run on a computer. There are two classifications of software: –Operating Systems ( 作業系統 ) –Application Software ( 應用軟體 )

3 © 2010 Pearson Addison-Wesley. All rights reserved. 1-3 1.4 Programming Languages A program( 程式 ) –a set of instructions a computer follows in order to perform a task. – 我們來觀察電腦中的應用程式: Winword.exe A programming language( 程式語言 ) –a special language used to write computer programs. 別以為微波爐與遙控器上的文字是給機器看的 –Java 語言比中文嚴謹許多 – 要吃蘋果嗎 = 蘋果要吃嗎 = 你要吃蘋果嗎 = 蘋果你 要吃嗎

4 © 2010 Pearson Addison-Wesley. All rights reserved. 程式執行的基本過程 Central Processing Unit Main Memory USB Disk Hard Disk Secondary memory devices provide long-term storage Information is moved between main memory and secondary memory as needed Hard disks Floppy disks ZIP disks Writable CDs Writable DVDs Tapes 觀察 WinWord.exe 進入記憶體

5 © 2010 Pearson Addison-Wesley. All rights reserved. 1-5 Programming Languages The binary numbers are encoded as a machine language ( 機器 語言 ). Each CPU has its own machine language. –Motorola 68000 series processors –Intel x86 series processors –DEC Alpha processors, etc. Example of a machine language instruction: –1011010000000101 (ADD) –1011010000000101 (MOV) In the distant past, programmers wrote programs in machine language.

6 © 2010 Pearson Addison-Wesley. All rights reserved. 1-6 Programming Languages High level programming languages ( 高階語言 ) followed that were not processor dependent. Some common programming languages: Java BASICC++ C Python COBOL JavaScript Ruby PHP C# Visual Basic Pascal

7 © 2010 Pearson Addison-Wesley. All rights reserved. 1-7 Program Development Process Text editor Source code (.java ) Saves Java statements Java compiler Is read by Byte code (.class ) Produces Java Virtual Machine Is interpreted by Program Execution Results in 平台依賴性 平台無關性

8 © 2010 Pearson Addison-Wesley. All rights reserved. Translating Languages English: Display the sum of A times B plus C. Java: System.out.println(A*B+C) Assembly Language: mov eax,A mul B add eax,C call WriteInt Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000

9 © 2010 Pearson Addison-Wesley. All rights reserved. 1-9 1.5 What is a Program Made of? Common Language Elements There are some concepts that are common to virtually all programming languages. Common concepts: –Key words ( 關鍵字 ) Reserved words ( 保留字 ) –Operators ( 運算子 ) –Punctuation ( 標點符號 ) –Programmer-defined identifiers ( 自訂識別字 ) –Strict syntactic rules. ( 語法規則 )

10 © 2010 Pearson Addison-Wesley. All rights reserved. 1-10 Programming Languages Sample Program public class HelloWorld { public static void main(String[] args) { String message = "Hello World"; System.out.println(message); }

11 © 2010 Pearson Addison-Wesley. All rights reserved. 1-11 Programming Languages Sample Program Key words in the sample program are: Key words are lower case (Java is a case sensitive language). – 課堂活動:讓我們試試把 public 改成 PUBLIC… Key words cannot be used as a programmer-defined identifier. – 課堂活動:讓我們試試把 main 改成 public… – 課堂活動:讓我們試試把 main 改成 class… public class static void

12 © 2010 Pearson Addison-Wesley. All rights reserved. 1-12 Programming Languages Semi-colons are used to end Java statements( 敘 述 ) not all lines of a Java program end a statement. Part of learning Java is to learn where to properly use the punctuation.

13 © 2010 Pearson Addison-Wesley. All rights reserved. 1-13 Programming Languages Lines vs Statements There are differences between lines ( 行 ) and statements when discussing source code. System.out.println( message); This is one Java statement written using two lines. A statement is a complete Java instruction that causes the computer to perform an action.

14 © 2010 Pearson Addison-Wesley. All rights reserved. 1-14 Programming Languages Variables ( 變數 ) Data in a Java program is stored in memory. Variable names ( 變數名稱 ) represent a location in memory. Variables are created by the programmer who assigns it a programmer-defined identifier. example: int hours = 40; In this example, the variable hours is created as an integer (more on this later) and assigned the value of 40. 請幫我把右邊第三個抽屜裡面 的東西拿給我

15 © 2010 Pearson Addison-Wesley. All rights reserved. 1-15 Programming Languages Variables Variables are simply a name given to represent a place in memory. 0x000 0x001 0x002 0x003 0x004 0x005 0x006 0x007

16 © 2010 Pearson Addison-Wesley. All rights reserved. 1-16 Programming Languages Variables 0x000 0x001 0x002 0x003 0x004 0x005 0x006 0x007 The Java Virtual Machine (JVM) actually decides where the value will be placed in memory. 72 Assume that the this variable declaration has been made. int length = 72; The variable length is a symbolic name for the memory location 0x003.


Download ppt "© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth."

Similar presentations


Ads by Google