Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and...

57

Transcript of Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and...

Page 1: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 2: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

Introduction to Computers and Java

Page 3: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 4: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 5: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 6: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 7: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

INPUT

Page 8: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

INPUTCOMPUTING

Page 9: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

INPUT Output

Page 10: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 11: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 12: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 13: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

CPU Memory

Page 14: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 15: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 16: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 17: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 18: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RAM

Page 19: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

Secondary

Page 20: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 21: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

Memory

Addresses Values

256 01000001

260 01000010

264 01000010

268 01000001

Page 22: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• Bit – a digit with a value of 0 or 1• Byte – Consists of 8 bits• Address – The numbered location where

each byte resides• All data is encoded as a 0 or 1

– Everything is a number

• When more than 1 bytes is needed then several adjacent addresses are used

Memory

Addresses Values

256 01000001

260 01000010

264 01000010

268 01000001

Page 23: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• File – large group of bytes stored in secondary (auxiliary) memory– Files have names– Most files have extensions

• Folder (Directory) – group together multiple files

• Java programs are stored in files– Source code have the extension “.java”– Byte-Code have the extension “.class”

Memory

Addresses Values

256 01000001

260 01000010

264 01000010

268 01000001

Page 24: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

CPUMainSecondary

Page 25: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

CPUMainSecondary

Load

Page 26: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

CPUMainSecondary

RunCodeLoad

Page 27: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

CPUMainSecondary

RunCode

LoadStoreInfo

Page 28: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 29: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 30: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 31: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 32: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 33: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

LOW LEVEL

Page 34: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

LOW LEVEL

Page 35: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

LOW LEVELMachineCode

Page 36: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

High Level

Page 37: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

High Level

Page 38: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

High Level

Page 39: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

High LevelNouns and Verbs

Page 40: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

High LevelSyntax

Page 41: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 42: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

111010100010101000

Compiler

Page 43: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.
Page 44: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

Project

Page 45: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

ProjectClasses

Page 46: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

ProjectClasses

Methods

Page 47: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

ClassesMethods

• Source Code in files with “.JAVA” extension• The filename must MATCH the name of the class• Everything is an “Object”

Page 48: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RunningCompilation

JavaSourceCode

(.JAVA)

Page 49: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RunningCompilation

JavaCompiler

JavaSourceCode

(.JAVA)

Page 50: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RunningCompilation

JavaCompiler

JavaSourceCode

(.JAVA)

Intermediate Byte Code(.CLASS)

Page 51: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RunningCompilation

JavaCompiler

JavaSourceCode

(.JAVA)

Intermediate Byte Code(.CLASS)

Java Virtual Machine(JVM)

Page 52: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

RunningCompilation

JavaCompiler

JavaSourceCode

(.JAVA)

Intermediate Byte Code(.CLASS)

Java Virtual Machine(JVM)

Page 53: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• Running (Executing) – Is when the computer is following the instructions in a program

• Statement – An instruction to the computer. Most end with a semicolon “;”– int i;– double j;

• Syntax – The grammar rules for a programming language

• Comments – Code ignored by the compiler that is generally used to explain the code.– Single line comments use the “//”– Multiline comments use “/* */”

• Arguments – Information found inside of parenthesis “()” that provide information for methods or other statements– if(<<ARGUMENT>>)– System.out.println(<<ARGUMENT>>)

• Bug – an error in a program• Debugging – the process of removing errors• There are 3 major classes of errors

– Syntax– Runtime– Logic

Page 54: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• Syntax Errors– Grammatical mistakes in a program– Very common at first– These prevent a program from compiling and

running– Common

• Missing a Semicolon at the end of a statement• Using the wrong, misspelled, repeated, or

incorrectly capitalized identifier• Mismatched curly braces “{}”, parenthesis “()”,

single quotes “‘’”, double quotes ““””, etc.

Page 55: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• Runtime Errors – Errors detected when the program is running but not during compilation– The code will compile but crashes at some

point– When this happens the computer detects the

error and terminates the program– Common

• Divide by 0• Calling a method from a NULL object• An index going outside the bounds of an Array

Page 56: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

• Logic Errors – despite the program compiling and running, it produces incorrect results– Arguably the hardest to fix – Common:

• Order of operations error• Round off mistakes• Incorrectly using types or methods

Page 57: Introduction to Computers and Javashephejj/csce145/LectureSlides/...Introduction to Computers and Java. INPUT. INPUT. COMPUTING. INPUT. Output. CPU. Memory. RAM. Secondary. Memory.

HELLO WORLD!