GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to...
Transcript of GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to...
![Page 1: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/1.jpg)
COMP163Introduction to
Computer Programming
Introduction and
Overview of the Hardware
![Page 2: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/2.jpg)
Reading
• Read chapter 1 of the online textbook
![Page 3: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/3.jpg)
What is the difference between a simple calculator and a computer?
![Page 4: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/4.jpg)
Hardware and Software
• Hardware is the electronics of the computer. Hardware is physical stuff you can touch.
• Software is the program that runs on the hardware
• Software allow the same hardware to be used for many different purposes
• We will be writing software in this class
![Page 5: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/5.jpg)
Basic Computer Components
CPU
I/O Controller
I/O Device
MemoryBus
Cache
![Page 6: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/6.jpg)
Central Processing Unit
• Contains the control logic that initiates most activities in the computer
• The Arithmetic Logic Units of the CPU perform the math and logic calculations
• It is the CPU that executes a Java program
![Page 7: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/7.jpg)
Bus
• The bus is a set of parallel wires that connect the CPU, memory and I/O controllers
• It has logic to determine who can use the bus at any given instant
• Controlled by the chipset
![Page 8: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/8.jpg)
I/O Controllers
• Direct the flow of data to and from I/O devices
• The CPU sends a request to the I/O controller to initiate I/O
• I/O controllers run independently and in parallel with the CPU
• I/O devices include the screen, keyboard, network, printer, disk, mouse, etc.
![Page 9: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/9.jpg)
Memory
• The internal memory is Random Access Memory (RAM)
• Both data and program instructions are kept in RAM
• Instructions must be in RAM to be executed
• 8 binary bits are grouped into a byte
• 4 bytes (32 bits) are grouped into a word
• 8 bytes (64 bits) are grouped into a long word
![Page 10: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/10.jpg)
Memory Hierarchy
![Page 11: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/11.jpg)
Programming Languages
• We will be writing software in the Java programming language
• There are hundreds of programming languages
• Programs must be written EXACTLY correct
• Any syntax error (i.e. missing comma) will generate an error
• There is lots of punctuation
![Page 12: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/12.jpg)
Example Java Program
// A simple Java program
public class FirstDay {
public static void main( String[] args) {
System.out.println("My first program");
}
}
![Page 13: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/13.jpg)
Comments
• Programs are written for both computers and humans to read
• Comments are notes for humans that the compiler ignores
• There are two formats for comments
// the rest of the line is a comment
/* everything is ignored
until */
• Javadoc comments start with /** more to come */
![Page 14: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/14.jpg)
Reserved Words
• Some words are special in Java. They are part of the Java language. You cannot use reserved words for names.
• class public static void are reserved words used in the example program
• All Java reserved words are all lower case
• Java is case sensitive. Upper and lower case letters are different.
![Page 15: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/15.jpg)
Statements
• A statement is a line of a Java program
• One logical line can be spread over several lines on the screen.
System.out.println(
"My first program"
);
• Every Java statement ends with a semi-colon ;
![Page 16: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/16.jpg)
Blocks
• A block is a bunch of statements surrounded
by curly brackets { block stuff }• Every class has a class block
• Every method has a method block
• Almost any place you can put a Java statement, you can also put a block
• Blocks can be nested
{ outer {inner} more outer }
![Page 17: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/17.jpg)
Source Code
• What you type is called the source code of your program
• The source code is not directly run by the computer
• The source code must be compiled into an executable form before the computer can execute it
![Page 18: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/18.jpg)
Traditional Program Creation
Source Code
Compiler
Object File
Linker
Executable
OS Program Load
Libraries
![Page 19: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/19.jpg)
Traditional Java Programs
Source Code
Compiler
Bytecodes
Java Virtual Machine
Bytecode Libraries
![Page 20: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/20.jpg)
Modern Virtual Machines
Source Code
Compiler
Virtual Machine
BytecodesBytecode Libraries
JIT
machine language
![Page 21: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/21.jpg)
Errors
• When programming you will make mistakes.
• There are three types of programming errors
– Compile errors – When you compile your program, the compiler might detect an error (i.e. missing semicolon)
– Run time errors – An error can occur when you program is running (i.e. division by zero)
– Logic errors – Your program might not produce the correct results
![Page 22: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/22.jpg)
Errors in programs are often called “Bugs”
Grace Hopper coined the term
“bug” when she found a moth in
the relay of an early computer
![Page 23: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/23.jpg)
Keep Your Cool
• You will have errors
• You will correct them
• Seek help if you don’t understand the error
![Page 24: GEEN163 Introduction to Computer Programmingwilliams.comp.ncat.edu/COMP163/Intro.pdfIntroduction to Computer Programming Introduction and Overview of the Hardware. ... •The Arithmetic](https://reader030.fdocuments.in/reader030/viewer/2022040116/5edc7041ad6a402d66671852/html5/thumbnails/24.jpg)
Reading
Read chapter 1 of the online textbook