Presentation is loading. Please wait.

Presentation is loading. Please wait.

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Chapter 1 Introduction to Computers,

Similar presentations


Presentation on theme: "Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Chapter 1 Introduction to Computers,"— Presentation transcript:

1 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Chapter 1 Introduction to Computers, Programs, and Java COCS 202 Progrmming I Muhammad H. Alsharif FCITR, KAUR 1

2 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 2 Chapter 1 Introduction to Computers, Programs, and Java

3 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 3 What is a Computer? A computer consists of a CPU, memory, hard disk, floppy disk, monitor, printer, and communication devices.

4 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 4 CPU - The central processing unit (CPU) is the brain of a computer. - It retrieves instructions from memory and executes them. - The CPU speed is measured in megahertz (MHz).

5 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 5 Memory - Memory : store data and program instructions for CPU to execute. - A memory unit is an ordered sequence of bytes. - The current content of a memory byte is lost whenever new information is placed in it. - Memory is volatile, because information is lost when the power is off.

6 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 6 How Data is Stored? - Data of various kinds: such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones). - Computers use zeros and ones because digital devices have two stable states, which are referred to as zero and one by convention. - The encoding scheme varies. For example, character ‘J’ is represented by 01001010 in one byte. A small number such as three can be stored in a single byte.

7 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 7 Storage Devices Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. There are three main types of storage devices:Disk drives (hard disks and floppy disks), CD, DVD drives (CD-R, CD-RW and DVD), Tape drives and Compact Flash card.

8 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 8 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Programs are written using programming languages.

9 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 9 Programming Languages Machine Language Assembly Language High-Level Language - Machine language is a set of primitive instructions built into every computer. - The instructions are in the form of binary code. - Program are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010

10 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 10 Programming Languages Machine Language Assembly Language High-Level Language - Assembly languages were developed to make programming easy. - A program called assembler is used to convert assembly language programs into machine code. - For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3

11 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 11 Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415;

12 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 12 Popular High-Level Languages F COBOL (COmmon Business Oriented Language) F FORTRAN (FORmula TRANslation) F BASIC (Beginner All-purpose Symbolic Instructional Code) F Pascal (named for Blaise Pascal) F Ada (named for Ada Lovelace)  C (whose developer designed B first) F Visual Basic (Basic-like visual language developed by Microsoft) F Delphi (Pascal-like visual language developed by Borland) F C++ (an object-oriented language, based on C) F Java (We use it in the book)

13 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 13 Compiling Source Code - A program written in a high-level language is called a source program. - Program called a compiler is used to translate the source program into a machine language program called an object program. - The object program is often then linked and executed on the machine.

14 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 14 Compiling Java Source Code F Java was designed to run object programs on any platform. F In Java, you write the program once, and compile the source program into a special type of object code, known as bytecode. F The bytecode can then run on any computer with a Java Virtual Machine, as shown in Figure 1.5. F Java Virtual Machine is a software that interprets Java bytecode.

15 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 15 Why Java? The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. F Java is a general purpose programming language. F Java is the Internet programming language.

16 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 16 Java, Web, and Beyond F Java can be used to develop Web applications. F Java Applets F Java Servlets and JavaServer Pages F Java can also be used to develop applications for hand-held devices such as Palm and Smart phones (ANDROID)

17 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 17 Examples of Java’s Versatility F Standalone Application: TicTacToe F Applet: TicTacToe F Servlets: SelfTest Web site F Mobile Computing: Cell phones

18 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 18 TicTacToe Standalone

19 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 19 TicTacToe Applet

20 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 20 Characteristics of Java F Java Is Simple F Java Is Object-Oriented F Java Is Distributed F Java Is Interpreted F Java Is Robust F Java Is Secure F Java Is Portable F Java's Performance F Java Is Multithreaded

21 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 21 JDK (Java Development KIT) Editions F Java Standard Edition (J2SE) – J2SE can be used to develop client-side standalone applications or applets. F Java Enterprise Edition (J2EE) – J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. F Java Micro Edition (J2ME). – J2ME can be used to develop applications for mobile devices such as cell phones. This book uses J2SE to introduce Java programming.

22 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 22 Java IDE Tools F Borland JBuilder F NetBeans Open Source by Sun (Oracle) F Eclipse Open Source by IBM F Oracle JDeveloper

23 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 23 A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Listing 1.1

24 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 24 Creating and Editing Using NotePad To use NotePad, type notepad Welcome.java from the DOS prompt.

25 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 25 Creating and Editing Using WordPad To use WordPad, type write Welcome.java from the DOS prompt.

26 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 26 Creating, Compiling, and Running Programs

27 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 27 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Trace a Program Execution Enter main method animation

28 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 28 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Trace a Program Execution Execute statement animation

29 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 29 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Trace a Program Execution animation print a message to the console

30 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 30 Compiling and Running Java from the Command Window F Set path to JDK bin directory –set path=c:\Program Files\java\jdk1.7\bin F Set classpath to include the current directory –set classpath=. F Compile –javac Welcome.java F Run –java Welcome

31 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 31 Comments Comments are preceded by two slashes (//) in a line. Comments enclosed between /* and */ in one or multiple lines.


Download ppt "Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Chapter 1 Introduction to Computers,"

Similar presentations


Ads by Google