ch01 show 1 computers - uchs apcsn solid state drive –no moving parts, electronic components that...

29
Big Java Chapter 1 Introduction

Upload: others

Post on 31-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

Big JavaChapter 1 Introduction

Page 2: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

2

Chapter Goals

1. Describe the relationship between hardware & software

2. Identify the basic computer hardware components and explain what each does

3. Know the steps involved in Java program compilation and execution.

4. Become familiar with your Java programming environment.

5. Describe the building blocks of a simple program

6. Understand bits, bytes, and the Binary Number system.

Page 3: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

3

Computer

u Computers are programmed to perform many different tasks.

u Computers execute very basic instructions in rapid succession.

Page 4: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

4

Computer Programs

u A computer program is a sequence of instructions and decisions.

u Programming is the act of designing and implementing computer programs.

Page 5: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

5

Hardware and Software

u The physical computer and peripheral devices are collectively called the hardware.

u The programs the computer executes are called the software.

Page 6: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

6

Computer components

Page 7: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

7

CPU – Central Processing unit

v Made up of several hundred million transistors

v Program control (locates the program instructions)

v Data processing (executes the program instructions)

v BRAIN OF THE COMPUTER

Page 8: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

8

Main(primary) Memory

u When a computer performs calculations, it often needs to save intermediate results.

u It saves those intermediate results in the main memorystorage area.

u Main memory is often called RAM (Random Access Memory).

main memory

storage devices(auxiliary memory)

CPUoutput

devicesinput

devices

Page 9: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

9

Main Memory

u The capacity (size) of memory is described in terms of number of bytes.

u RAM capacities in a typical computer range from 512 MB (megabyte) to 3+ GB (gigabyte).

u RAM is volatile – data is lost when power is turned off.

Page 10: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

10

Auxiliary(Secondary) Memory

u Auxiliary memory is for saving data permanently. It's non-volatile.

u Auxiliary memory comes in many different forms, the most common of which are hard disks, compact discs, and USB flash drives. Those things are called storage devices.

n Storage capacities:n Typical hard disk: 80 GB up to 1 TB.n Compact discs:

n For CD-ROMs, CD-Rs, and CD-RWs: » 700 MBn For DVDs, DVD-Rs, and DVD-RWs: 4.7 GB up to 8.5 GB

n Typical USB flash drives: 128 MB up to 64 GB.n Solid state drive – no moving parts, electronic components that can

retain information without power.

Page 11: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

11

Drives

u A drive is a mechanism that enables the computer system to access (read from and write to) data on a storage device.

u When using your computer, you’ll sometimes need to copy data from one place to another. To specify the storage media on which the data resides, you’ll need to use the storage media’s drive letter followed by a colon.

u Diskette drives are referred to as A:.

u Hard disk drives are usually referred to as C: or D:

u CD-ROM drives are usually referred to as D: or E:

u USB flash drives are usually referred to as E: or F:

7

Page 12: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

12

Common Computer-Hardware Vocabulary

u "Disk space" usually means the capacity/size of your hard disk.

u "Memory" (said by itself) usually means main memory/RAM.

u "Computer" (said by itself) usually refers to the big box that contains the CPU, the main memory, and the hard disk.

8

Page 13: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

13

Self Check 1.4

Where is a program stored when it is not currently running?

Answer: In secondary storage, typically a hard disk.

Page 14: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

14

Self Check 1.5Which part of the computer carries out arithmetic operations, such as addition

and multiplication?

Answer: The central processing unit.

Page 15: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

15

TO WRITE A PROGRAM

You need to provide a sequence of instructions that the CPU can execute.

A program consists of a large number of CPU instructions and its tedious and error prone to specify them one by one.

High level programming languages –programmer specifies the actions, COMPILER translates the high-level instructions into machine code required by the CPU

Page 16: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

16

Programming languages

Page 17: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

17

Programming languages

Page 18: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

18

Programming languages

Page 19: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

19

The java programming language is different than most other languages

Page 20: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

20

The Java Programming Language

§ Safe

§ Portable

§ Platform-independent • Distributed as instructions for

a virtual machine

• “Write Once – Run Anywhere”

§ Vast set of library packages

§ Designed for the Internet

Page 21: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

21

The Compilation Process for Non-Java Programs

source code(programming

language instructions)

object code(binary

instructions)

Programmers write this.

Computers run this.

Compilers compile source code into object code.

Page 22: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

22

Object Code

u Object code is a set of binary-format instructions that can be directly run by a computer to solve a problem. A binary-format instruction is made up of all 0’s and 1’s, because computers understand only 0’s and 1’s. Here's an example of an object-code instruction:

0100001111101010

u This particular object-code instruction is referred to as a 16-bit instruction because each of the 0’s and 1’s is a bit, and there are 16 of them.

u Each object-code instruction is in charge of only a simple computer task. For example, an object-code instruction could possibly be in charge of copying a single number from some place in main memory to some place in the CPU.

u Programmers sometimes refer to object code as machine code. Object code is called machine code because it's written in binary and that's what a computer “machine” understands.

Page 23: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

23

You first must understand…

Platforms

u Platform = Computer (hardware) and Operating System

u Example Dell Computer with Windows Operating System

u Example Mac Computer with MacOS High Sierra

u In most programming languages, compilers generate code that can execute on a specific target machine.

u For example, compile C++ program on windows machine the executable file will only RUN on Windows computers.

Page 24: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

24

Portability

u A piece of software is portable if it can be used on many different types of computers.

u Object code is not very portable. As you know, object code is comprised of binary-format instructions. Those binary-format instructions are intimately tied to a particular type of computer. If you've got object code that was created on a type X computer, then the object code can run only on a type X computer.

Page 25: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

25

Bytecode!

u The Java solution to improve portability:

u Java compilers don't compile all the way down to object code. Instead, they compile down to bytecode, which possesses the best features of both object code and source code:

u Like object code, bytecode uses a format that works closely with computer hardware, so it runs fast.

u Like source code, bytecode is generic, so it can be run on any type of computer.

Page 26: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

26

Java Virtual Machine

u How can bytecode be run on any type of computer?

u As a Java program’s bytecode runs, the bytecode is translated into object code by the computer's bytecode interpreter program. The bytecode interpreter program is known as the Java Virtual Machine, or JVM for short. The next slide shows how the JVM translates bytecode to object code. It also shows how a Java compiler translates source code to bytecode.

Page 27: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

27

The Compilation Process for Java Programs

16

Java source code

object code

Java compilers compile source code into bytecode.

bytecodeWhen a Java program is run, the JVM translates bytecode to object code.

Page 28: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

28

To Run Java programs…

A user must install the JAVA JVM (Java Virtual Machine) on the computer ONE TIME. Then all Java programs will work from then on…

This is why you can write a Java program on your windows computer and send it to me, and I can run it on my MAC!

This is very different! Think of all the software you have purchased… you have to specify what operating system you want to operate it on!

Page 29: ch01 show 1 Computers - UCHS APCSn Solid state drive –no moving parts, electronic components that can retain information without power. 11 Drives u A driveis a mechanism that enables

29

Self Check 1.7

What are the two most important benefits of the Java language?

Answer: Safety and portability.