COSC 1 P 02 Cosc 1 P 02

  • Slides: 23
Download presentation
COSC 1 P 02 Cosc 1 P 02 Week 1 Lecture slides "If a

COSC 1 P 02 Cosc 1 P 02 Week 1 Lecture slides "If a man does his best, what else is there? ” General George S. Patton (1885 -1945) Intro. to Computer Science 1. 1

COSC 1 P 02 · Audience - planning to major in COSC · Staff

COSC 1 P 02 · Audience - planning to major in COSC · Staff - instructors: Dave Hughes (J 312) & Dave Bockus (J 324) - mentor: Baoling Bork (J 304) - tutorial leader: - lab demonstrators: · Lectures (AS 216), labs (J 301), tutorials (AS 203) · Web - COSC: http: //www. cosc. brocku. ca/ - COSC 1 P 02: http: //www. cosc. brocku. ca/offerings/cosc 1 p 02/ · Email - Dave Hughes: hughesd@brocku. ca - Dave Bockus: bockusd@brocku. ca · Succeeding in COSC 1 P 02 - labs/assignments Intro. to Computer Science 1. 2

COSC 1 P 02 Course Content and Procedures · · · · All course

COSC 1 P 02 Course Content and Procedures · · · · All course documents available through Computer Science Website: - www. cosc. brocku. ca/Offerings/1 P 02/ - COSC home page: www. cosc. brocku. ca Outline Instructional labs - lab participation Assignment preparation - Help Desk (J 304) - submission (outside J 332) - return (J 333) - plagiarism Exams/tests - lab vs written course procedures - plagiarism students with computers - Software: JCreator or Dr. Java - Libraries ° Basic. IO ° Turtle. Graphics ° Media Intro. to Computer Science 1. 3

COSC 1 P 02 Class Room · Ground Rules - Lecture conduct - Cell

COSC 1 P 02 Class Room · Ground Rules - Lecture conduct - Cell Phones - Laptops · Contact information: - Email messages only accepted from a Brock server. - Dave Bockus ° Open Door Policy (J 324, Day Section) ° E-mail bockusd@brocku. ca ° MSN bockusd@hotmail. com Intro. to Computer Science 1. 4

COSC 1 P 02 Computer Science What is it? · study of computer hardware

COSC 1 P 02 Computer Science What is it? · study of computer hardware and algorithms and data structures and how they fit into information systems. · computer - programmable machine. - processes data into information. · Algorithm - well-defined sequence of steps to produce an outcome · programming language - Java Data In Hardware Info Out Algorithm Software Intro. to Computer Science 1. 5

COSC 1 P 02 Hardware Components · processor (CPU) - control unit (CU) °

COSC 1 P 02 Hardware Components · processor (CPU) - control unit (CU) ° controls system ° follows instructions - arithmetic logic unit (ALU) ° performs operations (e. g. +, -, =, <) · main memory (RAM) - volatile · input devices - transformation - keyboard, scanner, sensor Intro. to Computer Science 1. 6

COSC 1 P 02 Hardware Components. · output devices - transformation - monitor, printer,

COSC 1 P 02 Hardware Components. · output devices - transformation - monitor, printer, actuator · auxiliary storage - hard disk, floppy disk, CD-ROM, DVD, Data Keys · communications - Networks ( wired, broadband) - modem, cable modem Intro. to Computer Science 1. 8

COSC 1 P 02 Data Representation · switches—bi-stable devices · binary system - positional

COSC 1 P 02 Data Representation · switches—bi-stable devices · binary system - positional (like decimal) - bit - byte - megabyte (MB) · memory organization - storage cell - address - store(write)/fetch(read) Address, where the info is located. Data, what is stored. Intro. to Computer Science 1. 9

COSC 1 P 02 Data Representation (2) · All information is represented in binary

COSC 1 P 02 Data Representation (2) · All information is represented in binary code - numbers - characters ° coding scheme - sound, images ° Digitization · Important: bytes of data only differ in how they are interpreted. - The same byte can be viewed as: - Simple representation ° Numbers (integers and floats) ° Characters (abc…) - Part of Complex Objects ° Pictures, sounds, video - Program ° Machine Code which instructs the hardware. - Its all in the interpretation Intro. to Computer Science 1. 10

COSC 1 P 02 Instruction Processing · machine language - Opcode (operation code) -

COSC 1 P 02 Instruction Processing · machine language - Opcode (operation code) - Operand (source data to be used in the operation) · CPU - registers ° Special Registers IAR, IR - bus · machine (fetch/decode/execute) cycle - fetch - decode - execute - system clock ° 1 megahertz (Mhz) = 1, 000 cycles/second Intro. to Computer Science 1. 11

COSC 1 P 02 Machine Language Assembly Language · · · First generation One-to-one

COSC 1 P 02 Machine Language Assembly Language · · · First generation One-to-one correspondence with hardware function Binary representation Operator (opcode) Operands · Developed into Assembly by allowing mnemonics to represent the actual machine instructions. - made life easier for the programmers. Intro. to Computer Science 1. 17

COSC 1 P 02 High-level Language · Closer to problem domain · One-to-many translation

COSC 1 P 02 High-level Language · Closer to problem domain · One-to-many translation - Code much easier to write and understand - Made writing large programs much easier. · Required: - Compiler ° Takes source program ° Converts to object program {something the machine can understand} - Libraries ° linker · Compile time vs Link time vs Execution time Intro. to Computer Science 1. 18

COSC 1 P 02 Software · Software - computer program - instructions for machine

COSC 1 P 02 Software · Software - computer program - instructions for machine execution · Compiler - Translation of a high level language into machine language. · Program preparation - edit ° editor - compile ° compiler ° syntax errors - link ° add in resources (code) from library - execute ° execution (logic) errors (bugs) · Development environment (IDE, e. g. Dr. Java, JCreator) Intro. to Computer Science 1. 19

COSC 1 P 02 Computer Programming Intro. to Computer Science 1. 20

COSC 1 P 02 Computer Programming Intro. to Computer Science 1. 20

COSC 1 P 02 Java · Gosling (1990 -92) · Originally for consumer electronics

COSC 1 P 02 Java · Gosling (1990 -92) · Originally for consumer electronics - embedded systems · Platform independence · Object-oriented - programming as modeling - Java as a better C++ · Execution of Java programs - platform independence ° machine language? - Java bytecode ° Java interpreter Intro. to Computer Science 1. 21

COSC 1 P 02 Java Programming Concepts · library (package) - e. g. Media

COSC 1 P 02 Java Programming Concepts · library (package) - e. g. Media - collection of useful classes - imported to be used · class - e. g. Turtle - definition of a kind of entity (object) - defines operations (methods) entities can perform · object - one entity from a class (a turtle) - created using new Intro. to Computer Science 1. 22

COSC 1 P 02 · variable - e. g. yertle - name that refers

COSC 1 P 02 · variable - e. g. yertle - name that refers to an object or value · method - e. g. forward - an operation that can be performed by an object · statement - a line of Java code · method call statement - request for an object to perform a method - object. method. Name(parameters) ° e. g. yertle. forward(40) Intro. to Computer Science 1. 23

COSC 1 P 02 Turtle Graphics · Simple graphics facility · Derived from Logo

COSC 1 P 02 Turtle Graphics · Simple graphics facility · Derived from Logo · Turtle. Displayer - a class in the Basic. IO library - canvas of 300 by 300 drawing units · Turtle - a class in the Media library - draws on a canvas · Drawing a square - create displayer - create turtle - put turtle on canvas - put pen down - draw line - turn corner - repeat Intro. to Computer Science 1. 24

COSC 1 P 02 Turtle Displayer · This is equivalent to a piece of

COSC 1 P 02 Turtle Displayer · This is equivalent to a piece of paper which the turtle will draw on. - Create the Displayer - Put the turtle on the Displayer - This also implies we can have more then 1 turtle on the same displayer. · Displayer and Turtle are resources provided by libraries. - We do not make the paper we use. We let someone else do this for us. - Code is linked in to our program ° If you want a piece of paper you have to have a access to it. ° Same for a pencil - Import statement allows us access to these libraries. Intro. to Computer Science 1. 28

COSC 1 P 02 A Java Program · Draw a square · Framework -

COSC 1 P 02 A Java Program · Draw a square · Framework - a program is a class - code for a class is stored in a file - a class is part of a package - establish (import) environment (libraries) - define names (variables) being used - constructor is a method that is executed when an object is created ° contains actions (statements) to be performed - main method creates an instance of the Draw. Square class to begin execution Intro. to Computer Science 1. 29

COSC 1 P 02 Basic Program Components package Example_2_1; Import, make libraries visible. import

COSC 1 P 02 Basic Program Components package Example_2_1; Import, make libraries visible. import Basic. IO. *; import Media. *; import static java. lang. Math. *; public class Draw. Square { private Turtle. Displayer private Turtle display; yertle; // // public Draw. Square ( ) { display = new Turtle. Displayer(); yertle = new Turtle(); display. place. Turtle(yertle); yertle. pen. Down(); yertle. forward(40); yertle. right(PI/2); yertle. pen. Up(); Declare the variable display to draw on & yertle. turtle to display do drawing Create the Objects we need to use, Drawing Surface -> display and the Turtle -> yertle. Put the Turtle on the Surface. Use yertle by calling methods. display. close(); }; // constructor public static void main ( String[] args ) { new Draw. Square(); }; } Intro. to Computer Science 1. 30

COSC 1 P 02 package Example_2_1; Draw Square Program Flow Variables declared in the

COSC 1 P 02 package Example_2_1; Draw Square Program Flow Variables declared in the class body are import Basic. IO. *; import Media. *; import static java. lang. Math. *; /** * * * This class is a program to called instance variables. Each new Object will haveusing its own variables. draw a square Turtle instance Graphics. @author D. Hughes @version 1. 0 (July 2007) Yertle is new concepts: java program structure, declarations, constructor, object assignment, instructed to putmethod calls, turtle displayer, turtle graphics public class Draw. Square its pen down and{ yertle private Turtle. Displayer display; // display to draw on draw a square. private Turtle yertle; // turtle to do drawing public Draw. Square ( ) {/** The constructor. */ creation, */ yertle display = new Turtle. Displayer(); yertle = new Turtle(); display. place. Turtle(yertle); yertle. pen. Down(); Wait yertle. forward(40); until the display yertle. right(PI/2); closeyertle. forward(40); button is yertle. right(PI/2); yertle. forward(40); pressed, then exit yertle. right(PI/2); display yertle. forward(40); yertle. right(PI/2); yertle. pen. Up(); display. close(); }; // constructor public static void main ( String[] args ) { new Draw. Square(); }; } Program starts by creating a new Square Object Constructor finishes and program ends Intro. to Computer Science 1. 31

COSC 1 P 02 The end Intro. to Computer Science 1. 34

COSC 1 P 02 The end Intro. to Computer Science 1. 34