Computer Science 1710: Object- Oriented Programming 1 Spring 2007 Instructor: Andrew Vardy.

Slides:



Advertisements
Similar presentations
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
Advertisements

Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
COMP Computer Basics Yi Hong May 13, 2015.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Topics Introduction Hardware and Software How Computers Store Data
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computer Science.
CPU (CENTRAL PROCESSING UNIT): processor chip (computer’s brain) found on the motherboard.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Computer Terms. Computer A machine designed to run programs and store information that you create.
Chapter 1: Introduction to Computers and Programming.
MAC OS – Unit A Page: 10-11, Investigating Data Processing Understanding Memory.
Introduction to Computers
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.
Computer Parts. Two Basic Parts Hardware & Software.
Computers Are Your Future Eleventh Edition Chapter 2: Inside the System Unit Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall1.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Machine Architecture CMSC 104, Section 4 Richard Chang 1.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction.
Introduction to Computer Systems and the Java Programming Language.
ICOM 4015: Advanced Programming Lecture 1 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Reading: Chapter One: Introduction.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction ( ปรับปรุง )
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 1 - Introduction.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Mrs. Ulshafer August, 2013 Java Programming Chapter 1.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Lesson 3 — How a Computer Processes Data Unit 1 — Computer Basics.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
CSCI-100 Introduction to Computing Hardware Part I.
1 Course Title: IT IN BUSINESS Course Instructor: ADEEL ANJUM Chapter No: 04 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
Beginning Snapshots Chapter 0. C++ An Introduction to Computing, 3rd ed. 2 Objectives Give an overview of computer science Show its breadth Provide context.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Computer Systems. Bits Computers represent information as patterns of bits A bit (binary digit) is either 0 or 1 –binary  “two states” true and false,
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Chapter 1 - Introduction. Announcements Info Sheet Web Site: Lab Hours NotecardsPictures.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction To Computer Programming – 1A Computer Parts, Words, and Definition Herriman High School.
~How PC Parts Work~ (30 MARKS). List 4 External components you can see on the PC in front of you and describe the basic function of each one. 1) DVD Drive.
Computer Architecture and Number Systems
Java Programming: From the Ground Up
Lecture 1b- Introduction
John Woodward A Simple Program – Hello world
An Overview of the Computer System
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1 – Introduction
Java programming lecture one
Looking Inside the machine (Types of hardware, CPU, Memory)
Introduction to Computing Lecture # 1
An Overview of the Computer System
Computers: Hardware and Software
Topics Introduction Hardware and Software How Computers Store Data
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

Computer Science 1710: Object- Oriented Programming 1 Spring 2007 Instructor: Andrew Vardy

Programming: Writing the instructions to control a computer, causing it to perform some useful task What tasks do we want our programs to perform: Word processing, communicating, gaming, watching videos, listening to music, scientific experiments, creating videos/music, managing finances... Who needs to know how to program? Just about everyone uses computer programs Many people write computer programs as a small part of their jobs (especially scientists and engineers)‏ Some people write programs as the main part of their job What is this course about?

To understand the activity of programming To learn about the architecture of computers To learn how numbers are represented by computers To learn about machine code and high level programming languages To recognize syntax and logic errors To learn about the compilation process Chapter 1: Introduction (Chapter 1 from text, part of appendix K, plus additional material)‏

Computers are programmed to perform tasks Different tasks = different programs Program Sequence of basic operations executed in succession Contains instruction sequences for all tasks it can execute Sophisticated programs require teams of highly skilled programmers and other professionals What Is Programming?

Hardware is the physical aspect of the computer system It is composed of printed circuit boards, integrated circuits (i.e. chips), wiring, power supplies, cases, and mounting hardware It is rarely modified "The parts of a computer system that can be kicked." Henri Karrenbeld The programs that run on a computer are also known as software A program is a pattern of information, not a physical device Unlike hardware, software is frequently modified Hardware / Software

Schematic Diagram of a Computer

Central Processing Unit

Executes the instructions given in software Usually contained within a single integrated circuit Integrated circuit (a.k.a. a chip): Electronic circuitry housed within a small package, with metal pins sticking out Consists of millions of transistors Transistor: Tiny electronic components that can control whether current flows through a circuit or not Executes very simple instructions, very rapidly: e.g. copy this number from location A to B e.g. multiply these numbers General purpose device (used for all types of programs) Central Processing Unit

Programs and data are all represented as binary numbers (see later) and stored on various media Random-access memory (RAM)‏ Electronic storage which is lost when the power is turned off Called "random-access" because it is just as fast to access any (i.e. a random) position in memory The cost per byte (defined below) is high Access time is fast a.k.a. (Also Known As) primary storage Secondary storage: e.g. hard disk Information stored on a rotating magnetic disk (actually, a multi layered platter of disks)‏ The cost per byte is low Access time is much slower than RAM Programs are usually loaded from secondary storage into RAM when they are executed Removable storage devices: e.g. CDs, USB keys, memory cards Storage

RAM

A Hard Disk

The CPU is connected to RAM, hard disk, and other devices through the bus Bus: A set of wires used for communication between various devices The CPU and bus are located on the motherboard Motherboard: A large printed circuit board that all of your computer's devices connect to Contains slots for RAM Slots for other devices Sound card Graphics card Network card The Bus, The Motherboard

A Motherboard

The ENIAC: The World's First Electronic Computer

Where is a program stored when it is not currently running? Answer: In secondary storage, typically a hard disk. Self Check 1.4

Which part of the computer carries out arithmetic operations, such as addition and multiplication? Answer: The central processing unit. Self Check 1.5

Numbers are represented in a computer using bistable devices, a device which can be in two stable states Electronic circuits can be designed such that the voltage in part of the circuit is either 0 or 5 volts and can be controlled by an external input signal. A tiny segment of a magnetic disk or tape can be magnetically polarized in up or down configuration by a "head". The head can also read the configuration. On a CD there are "pits" and "grounds". A laser hitting a pit will not get reflected. If the laser hits a ground it will get reflected. Bistable Devices

Bistable devices can be combined to represent binary numbers First, lets revisit what we mean by decimal numbers 346 = 3 x x x 10 0 We can write 346 decimal to make it clear we mean decimal Decimal numbers use base 10 but this is arbitrary. Some cultures have used number systems with bases of 12, 20, or 60. Binary numbers use base binary = 1 x x x x 2 0 = = 13 decimal Binary Numbers (Appendix K)‏

To convert from binary to decimal, sum up all of the powers of 2 corresponding to digits with value = 1, 2 1 = 2, 2 2 = 4, 2 3 = 8, 2 4 = 16, 2 5 = 32,... To convert from decimal to binary, apply the following procedure to the number X: – Divide X by 2 – The remainder is the next right-most digit in binary – Let X be the quotient – If X = 0 we are finished – Otherwise go to step 1 e.g. X = 6 6 / 2 = 3 remainder 0 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 6 decimal = 110 binary

e.g. X = 100e.g. X = / 2 = 50 remainder 0 50 / 2 = 25 remainder 0 25 / 2 = 12 remainder 1 12 / 2 = 6 remainder 0 6 / 2 = 3 remainder 0 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder decimal = binary The binary number system applies also to non-integer numbers binary = 1 x x x x 2 -3 = 1 + ½ + 1/8 = decimal

A single binary digit is called a bitA single binary digit is called a bit 8 bits makes a8 bits makes a byte A byte can represent one of the standard characters (a-z, A-Z, 0-9, plus special characters and punctuation)‏A byte can represent one of the standard characters (a-z, A-Z, 0-9, plus special characters and punctuation)‏ 10 3 bytes make up a kilobyte (kB)‏10 3 bytes make up a kilobyte (kB)‏ 10 6 bytes make up a megabyte (MB)‏10 6 bytes make up a megabyte (MB)‏ 10 9 bytes make up a gigabyte (GB)‏10 9 bytes make up a gigabyte (GB)‏ Typical file sizes:Typical file sizes: Small document: 100 kBSmall document: 100 kB PDF file: 1 MBPDF file: 1 MB Powerpoint presentation: 2.5 MBPowerpoint presentation: 2.5 MB Image: MBImage: MB MP3 Audio: MBMP3 Audio: MB Typical PC specification:Typical PC specification: 1 GB RAM1 GB RAM 160 GB Hard disk160 GB Hard disk Bits and Bytes

The instructions that a CPU executes are encoded as binary numbersThe instructions that a CPU executes are encoded as binary numbers A computer can be programmed simply by specifying instructions as numbersA computer can be programmed simply by specifying instructions as numbers Such instructions are known as machine codeSuch instructions are known as machine code It is slightly more intuitive to write a program using short commands that translate directly into machine codeIt is slightly more intuitive to write a program using short commands that translate directly into machine code Such instructions are known as assembly languageSuch instructions are known as assembly language e.g. add edx, eax mov eax, 1 jmp L2 edx and eax are places within the internal memory of the CPU. L2 is a label of a place in memory that the CPU is about to jump to (hence "jmp").e.g. add edx, eax mov eax, 1 jmp L2 edx and eax are places within the internal memory of the CPU. L2 is a label of a place in memory that the CPU is about to jump to (hence "jmp"). Machine Code and Assembly Language

Machine code and assembly language are difficult to use.Machine code and assembly language are difficult to use. Most programmers utilize a high-level language, which uses concepts like variables to refer to locations in memory and has a structure that looks more like English: if ( balance <= 0 ) { System.out.println("You have no money left!"); }Most programmers utilize a high-level language, which uses concepts like variables to refer to locations in memory and has a structure that looks more like English: if ( balance <= 0 ) { System.out.println("You have no money left!"); } This is an example of Java code. There are many other high- level languages: C, C++, Python, Perl, etc...This is an example of Java code. There are many other high- level languages: C, C++, Python, Perl, etc... For some of these languages the source code (i.e. instructions written by the programmer) is converted to machine code by a special program called the compilerFor some of these languages the source code (i.e. instructions written by the programmer) is converted to machine code by a special program called the compiler High-Level Languages

The Java compiler translates Java source code into an intermediate form known as bytecodeThe Java compiler translates Java source code into an intermediate form known as bytecode A special program called the Java Virtual Machine (JVM) executes the bytecodeA special program called the Java Virtual Machine (JVM) executes the bytecode Actually, there are two ways in which bytecode can be executed:Actually, there are two ways in which bytecode can be executed: Interpreted line-by-lineInterpreted line-by-line This is slower but works the same on any computer running a JVMThis is slower but works the same on any computer running a JVM Compiled into machine code just before executionCompiled into machine code just before execution It takes a little bit of time for compilation, but the program will then run faster. However, the compilation has to be done differently for every type of computer.It takes a little bit of time for compilation, but the program will then run faster. However, the compilation has to be done differently for every type of computer. Bytecode

We refer to the individual instructions of bytecode as machine instructions – a typical sequence of machine instructions is: Load the contents of memory location 40. Load the value 100. If the first value is greater than the second value, continue with the instruction that is stored in memory location 240. Machine instructions are encoded as numbers: These instructions are shown in decimal, but inside the computer they are represented in binary Machine Instructions

What is the code for the Java virtual machine instruction "Load the contents of memory location 100"? Answer: Self Check 1.6

Does a person who uses a computer for office work ever run a compiler? Answer: No – a compiler is intended for programmers, to translate high-level programming instructions into machine code. Self Check 1.7

Java has a number of excellent qualities: Simplicity: Java bears a lot of similarity to the C++ language (its closest rival), but is simpler and therefore much easier to program in. Portability: Java code written on one computer can be compiled into bytecodes and executed on any computer that has a JVM ("write once, run anywhere") It has a rich library of packages for graphics, networking, input/output devices, etc... It was designed for the internet. A special type of JVM can run within a web browser and execute Java applets. The Java Programming Language

Applets on a Web Page

Library improvements20066 Generics, enhanced for loop, auto-boxing, enumerations20045 Assertions, XML Performance enhancements Swing, Collections Inner classes Important New FeaturesYearVersion Java Versions

1: public class HelloPrinter 2: { 3: public static void main(String[] args)‏ 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: } Output: Hello, World! Our First Java Program!

HelloPrinter in a Console Window

HelloPrinter in an IDE

The program HelloPrinter has four main parts: public class ClassName public static void main(String[] args) // comment Method call System class System.out object println method A Simple Program

object.methodName(parameters) Example: System.out.println("Hello, Dave!"); Purpose: To invoke a method of an object and supply any additional parameters. Syntax 1.1 Method Call

How would you modify the HelloPrinter program to print the words "Hello," and "World!" on two lines? Answer: System.out.println("Hello,"); System.out.println("World!"); Self Check 1.12

Would the program continue to work if you omitted the line starting with // ? Answer: Yes – the line starting with // is a comment, intended for human readers. The compiler ignores comments. Self Check 1.13

What does the following set of statements print? System.out.print("My lucky number is"); System.out.println( ); Answer: The printout is My lucky number is12 It would be a good idea to add a space after the is. Self Check 1.14

Syntax errors are violations of the rules of a language. For example, there is an error in the syntax of the following English- language sentence: "She to went the store." Here are two syntax errors in Java: System.ouch.print("..."); System.out.print("Hello); The compiler will print out a list of the syntax errors in your program. Always try and fix the first one in the list first. Syntax Errors (a.k.a. Compile-time Errors)‏

Logic errors are mistakes made in the logical flow of your program, with respect to what you want your program to do. For example, if it is raining outside and I want to tell someone, I don't say "It is Wednesday." The statement by itself is logical, but it does not achieve what I set out to do. Here is a logic error in a Java program: System.out.print("Hell"); The compiler will not tell you about logic errors because it does not know what you are trying to do. You must test your code to make sure it works! Logic Errors (a.k.a. Run-time Errors)‏

Suppose you omit the // characters from the HelloPrinter.java program but not the remainder of the comment. Will you get a compile-time error or a run-time error? Answer: A compile-time error. The compiler will not know what to do with the word Display. Self Check 1.15

How can you find logic errors in a program? Answer: You need to run the program and observe its behavior. Self Check 1.16

Create your program by typing it into an editor. An editor is a program that is used to view and modify source code files, as well as other simple types of files (word processors such as Microsoft Word are not considered editors)‏ e.g. notepad in Windows e.g. gedit in Linux A Java program should go in a file whose name ends with ".java" (without the quotes). Compile your program by running the Java compiler program javac javac will generate a class file from a ".java" file. e.g. from "HelloPrinter.java" we get "HelloPrinter.class" A class file contains the bytecode that will be executed by the JVM The Compilation Process

The Edit-Compile-Test Loop

What do you expect to see when you load a class file into your text editor? Answer: A sequence of seemingly random characters, some funny-looking. Class files contain virtual machine instructions that are encoded as binary numbers. Self Check 1.17

Why can't you test a program for run-time errors when it has compiler errors? Answer: When a program has compiler errors, no class file is produced, and there is nothing to run. Self Check 1.18