Download presentation
Presentation is loading. Please wait.
Published byCharla Smith Modified over 9 years ago
1
COSC 1P02 Intro. to Computer Science 1.1 Cosc 1P02 Week 1 Lecture slides "If a man does his best, what else is there?” General George S. Patton (1885-1945)
2
COSC 1P02 Intro. to Computer Science 1.2 COSC 1P02 Audience planning to major in COSC Staff instructors: Dave Hughes (J312) & Dave Bockus (J324) mentor: Baoling Bork (J304) tutorial leader: lab demonstrators: Lectures (AS216), labs (J301), tutorials (AS203) Web COSC: http://www.cosc.brocku.ca/http://www.cosc.brocku.ca/ COSC 1P02: http://www.cosc.brocku.ca/offerings/cosc1p02/http://www.cosc.brocku.ca/offerings/cosc1p02/ Email Dave Hughes: hughesd@brocku.cahughesd@brocku.ca Dave Bockus: bockusd@brocku.cabockusd@brocku.ca Succeeding in COSC 1P02 labs/assignments
3
COSC 1P02 Intro. to Computer Science 1.3 Course Content and Procedures All course documents available through Computer Science Website: www.cosc.brocku.ca/Offerings/1P02/ www.cosc.brocku.ca/Offerings/1P02/ COSC home page: www.cosc.brocku.cawww.cosc.brocku.ca Outline Instructional labs lab participation Assignment preparation Help Desk (J304) submission (outside J332) return (J333) plagiarism Exams/tests lab vs written course procedures plagiarism plagiarism students with computers Software: JCreator or Dr. JavaDr. Java Libraries BasicIO TurtleGraphics Media
4
COSC 1P02 Intro. to Computer Science 1.4 Class Room Ground Rules Lecture conduct Cell Phones Laptops Contact information: Email messages only accepted from a Brock server. Dave Bockus Open Door Policy (J324, Day Section) E-mail bockusd@brocku.ca MSN bockusd@hotmail.com
5
COSC 1P02 Intro. to Computer Science 1.5 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 Hardware Data InInfo Out Algorithm Software
6
COSC 1P02 Intro. to Computer Science 1.6 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
7
COSC 1P02 Intro. to Computer Science 1.7
8
COSC 1P02 Intro. to Computer Science 1.8 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
9
COSC 1P02 Intro. to Computer Science 1.9 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.
10
COSC 1P02 Intro. to Computer Science 1.10 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 Data Representation (2)
11
COSC 1P02 Intro. to Computer Science 1.11 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,000 cycles/second
12
COSC 1P02 Intro. to Computer Science 1.12
13
COSC 1P02 Intro. to Computer Science 1.13
14
COSC 1P02 Intro. to Computer Science 1.14
15
COSC 1P02 Intro. to Computer Science 1.15 Fetch/Decode Cycle
16
COSC 1P02 Intro. to Computer Science 1.16 Coding Schemes
17
COSC 1P02 Intro. to Computer Science 1.17 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.
18
COSC 1P02 Intro. to Computer Science 1.18 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
19
COSC 1P02 Intro. to Computer Science 1.19 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. DrJava, JCreator)
20
COSC 1P02 Intro. to Computer Science 1.20 Computer Programming
21
COSC 1P02 Intro. to Computer Science 1.21 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
22
COSC 1P02 Intro. to Computer Science 1.22 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
23
COSC 1P02 Intro. to Computer Science 1.23 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.methodName(parameters) e.g. yertle.forward(40)
24
COSC 1P02 Intro. to Computer Science 1.24 Turtle Graphics Simple graphics facility Derived from Logo TurtleDisplayer a class in the BasicIO 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
25
COSC 1P02 Intro. to Computer Science 1.25 Assembly and Machine Language
26
COSC 1P02 Intro. to Computer Science 1.26 Executing an Assembly Language Program
27
COSC 1P02 Intro. to Computer Science 1.27 Executing a High-Level Language Program
28
COSC 1P02 Intro. to Computer Science 1.28 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.
29
COSC 1P02 Intro. to Computer Science 1.29 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 DrawSquare class to begin execution
30
COSC 1P02 Intro. to Computer Science 1.30 package Example_2_1; import BasicIO.*; import Media.*; import static java.lang.Math.*; public class DrawSquare { private TurtleDisplayer display; // display to draw on private Turtle yertle; // turtle to do drawing public DrawSquare ( ) { display = new TurtleDisplayer(); yertle = new Turtle(); display.placeTurtle(yertle); yertle.penDown(); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.penUp(); display.close(); }; // constructor public static void main ( String[] args ) { new DrawSquare(); }; } Import, make libraries visible. Declare the variable display & yertle. Create the Objects we need to use, Drawing Surface -> display and the Turtle -> yertle. Use yertle by calling methods. Put the Turtle on the Surface. Basic Program Components
31
COSC 1P02 Intro. to Computer Science 1.31 Draw Square Program Flow package Example_2_1; import BasicIO.*; import Media.*; import static java.lang.Math.*; /** This class is a program to draw a square using Turtle Graphics. * * @author D. Hughes * * @version 1.0 (July 2007) * * new concepts: java program structure, declarations, constructor, object creation, * object assignment, method calls, turtle displayer, turtle graphics */ public class DrawSquare { private TurtleDisplayer display; // display to draw on private Turtle yertle; // turtle to do drawing public DrawSquare ( ) {/** The constructor. */ display = new TurtleDisplayer(); yertle = new Turtle(); display.placeTurtle(yertle); yertle.penDown(); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.forward(40); yertle.right(PI/2); yertle.penUp(); display.close(); }; // constructor public static void main ( String[] args ) { new DrawSquare(); }; } Program starts by creating a new Square Object Variables declared in the class body are called instance variables. Each new Object will have its own instance variables. display yertle Yertle is instructed to put its pen down and draw a square. Wait until the display close button is pressed, then exit Constructor finishes and program ends
32
COSC 1P02 Intro. to Computer Science 1.32 TurtleDisplayer Methods
33
COSC 1P02 Intro. to Computer Science 1.33 Turtle Methods
34
COSC 1P02 Intro. to Computer Science 1.34 The end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.