HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

COMP425M Introduction to Programming
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
The Java Programming Language
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
ECE122 L2: Program Development February 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 2 Program Development.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Getting Started with Java
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Chapter 1 Introduction.
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2004 Pearson Addison-Wesley. All rights reserved August 22, 2007 Compiling and Compiler Errors ComS 207: Programming I (in Java) Iowa State University,
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java Language and SW Dev’t
Computer Science 101 Introduction to Programming.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Chapter 1 Introduction 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
The Java Programming Language
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Java Chapter 1 Problem solving: 1. Understanding the problem. 2. Breaking the problem into manageable pieces. 3. Designing a solution. 4. Considering alternatives.
HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Introduction to Java Java Translation Program Structure
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Introduction to Programming and Java. 2 The Central Processing Unit The speed of a CPU is controlled by the system clock which generates an electronic.
© 2011 Pearson Education, publishing as Addison-Wesley Monday  Class Requirements  Earn hawk points today with the Name Game  Network Login.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2006 Pearson Education Chapter 1: Computer Systems.
Programming in Java (COP 2250) Lecture 2 Chengyong Yang Fall, 2005.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
ZObject-Oriented Software Development yproblem solving yprogram design and implementation yobject-oriented concepts xobjects xclasses xinterfaces xinheritance.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Chapter 1 Introduction. 2 Focus of the Course Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Programming with Java. Chapter 1 Focuses on: –components of a computer –how those components interact –how computers store and manipulate information.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Working with Java.
Lecture 1 Introduction Richard Gesick.
Lecture 1B Introduction Richard Gesick
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Creating Objects & String Class
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
Hardware and Software Hardware Software
Chapter 1: Computer Systems
Compiling and Compiler Errors
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Beyond Base 10: Non-decimal Based Number Systems
Chap 2. Identifiers, Keywords, and Types
Instructor: Alexander Stoytchev
Presentation transcript:

HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital

1-2 Hardware and Software Hardware ◦ the physical, tangible parts of a computer keyboard, monitor, disks, wires, chips, etc. Software ◦ programs and data  a program is a series of instructions A computer requires both hardware and software; otherwise useless without the other

Digital Information Computers store all information digitally: ◦ numbers ◦ text ◦ graphics and images ◦ video ◦ audio ◦ program instructions In some way, all information is digitized - broken down into pieces and represented as numbers Coming up: Representing Text Digitally

Representing Text Digitally For example, every character is stored as a number, including spaces, digits, and punctuation Corresponding upper and lower case letters are separate characters H i, H e a t h e r Coming up: Binary Numbers

Binary Numbers Once information is digitized, it is represented and stored in memory using the binary number system A single binary digit (0 or 1) is called a bit Devices that store and move information are cheaper and more reliable if they have to represent only two states A single bit can represent two possible states, like a light bulb that is either on (1) or off (0) Permutations of bits are used to store values Coming up: Bit Permutations

Bit Permutations 1 bit bits bits bits Each additional bit doubles the number of possible permutations Coming up: Bit Permutations

Bit Permutations Each permutation can represent a particular item There are 2 N permutations of N bits Therefore, N bits are needed to represent 2 N unique items 2 1 = 2 items 2 2 = 4 items 2 3 = 8 items 2 4 = 16 items 2 5 = 32 items 1 bit ? 2 bits ? 3 bits ? 4 bits ? 5 bits ? How many items can be represented by Coming up: Java and Unicode

Java and Unicode How do we map from numbers to characters? In Java we use the Unicode specification which maps each character to a 16-bit number. So, how many possible characters can we have? 2 16 = ASCII is an older set that was 8-bits and thus could represent only 2 8 =256 Note: The creators of Unicode started with ASCII, so the 256 ASCII character codes are a subset of Unicode Coming up: Java and Unicode

Java and Unicode See: Unicode also includes some non-printable characters like null, tab, line feed, delete,… Why 65,000 characters? We only have 26 letters! Coming up: Binary – How does the computer see numbers? Unicode is International… and includes our alphabet, but many other countries (Russian, Asian, Arabic, etc…). For our alphabet we need both upper and lower case representations! Unicode is International… and includes our alphabet, but many other countries (Russian, Asian, Arabic, etc…). For our alphabet we need both upper and lower case representations!

Binary – How does the computer see numbers? Computers represent information digitally, but only using a series of 1s and 0s. Binary = Base 2 Decimal = Base 10 Hexadecimal = Base 16 Coming up: Decimal Numbers (normal)

Decimal Numbers (normal) In decimal (base 10) we represent a number between 0-9 with one digit. To get any higher we use another position 23 Coming up: Binary Conversions Place 0 Place 1 Place 0 means multiple by 0 In this case 10 0 = 1 Place 1 means multiply by 1 In this case 10 1 = 10 So 23 = 10 1 * *3 = 23 Place 0 means multiple by 0 In this case 10 0 = 1 Place 1 means multiply by 1 In this case 10 1 = 10 So 23 = 10 1 * *3 = 23

Binary Conversions 5037 = 10 3 * * * *7 Now, what about Binary, which is Base 2? Available digits then are 1 and 0 only. Binary 101 is what in decimal? Coming up: Binary Conversions Place 0 Place 1 Place *1+2 1 *0+2 0 *1 = 4*1 + 2*0 + 1*1 = 5 in decimal = 2 2 *1+2 1 *0+2 0 *1 = 4*1 + 2*0 + 1*1 = 5 in decimal =

Joke There are only 10 kinds of people in this world. Those who know binary and those who don’t. Coming up: Hexadecimal – base 16

Hexadecimal – base 16 Base sixteen means we need 16 digits is 10 digits, how do I get more? A,B,C,D,E,F are valid “digits” in Hex. A=10, B=11, C=12, D=13, E=14, F=15 So, a hex number looks like: ◦ 3A or FFF or A2C4B What is 1A in decimal? ◦ 16 1 * *10 = 26 decimal Normally hexadecimal numbers are preceded by “0x” which means it is a hex number. Coming up: What is 0x20 in decimal?

How to convert from decimal to binary Given a number (24) find the largest place value that is lower than the number 2 6 = = = = = = = 1 Coming up: Convert 9 into binary Next divide the number by the place value to determine the digit for that position 24/16 = 1 Repeat process with remainder (8 in this example) 8/8 = 1 So I need a 1 in the 16 position and 8 position: = 11000

Convert 9 into binary 2 6 = = = = = = = 1 Coming up: Convert 7 into binary? 8 is the largest placevalue that fits inside 9, so 9/8 = 1 Remainder is 1 1 is the largest place value that fits in 1, so 1/1 = 1 Remainder is = 9

Convert 35 to hexadecimal 16 3 = = = =1 Coming up: Conclusions 16 is the largest placevalue that fits inside 35, so 35/16 = 2 Remainder is 3 3/1 = 3 Remainder is 0 0x23 = 35

Conclusions You should understand the math to do conversions to/from binary/decimal/hexadecimal We’ll use this later in a project and lab. You may even see a question on it on the exam End of presentation

1-19 Java A programming language specifies the words and symbols that we can use to write a program A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements It was introduced in 1995 and it's popularity has grown quickly since

1-20 Java Program Structure In the Java programming language: ◦ A program is made up of one or more classes ◦ A class contains one or more methods ◦ A method contains program statements A Java application always contains a method called main See HelloWorld.java HelloWorld.java

1-21 Java Program Structure public class HelloWorld {}{} // comments about the class class header class body Comments can be placed almost anywhere

1-22 Java Program Structure public class HelloWorld {}{} // comments about the class public static void main (String[] args) {}{} // comments about the method method header method body

1-23 Identifiers An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, programmers use different case styles for different types of identifiers, such as ◦ title case for class names - Lincoln ◦ upper case for constants - MAXIMUM

1-24 Program Development The mechanics of developing a program include several activities ◦ writing the program in a specific programming language (such as Java) ◦ translating the program into a form that the computer can execute investigating and fixing various types of errors that can occur Software tools can be used to help with all parts of this process

1-25 Language Levels There are four programming language levels: ◦ machine language (CPU specific) ◦ assembly language ◦ high-level language ◦ fourth-generation language The other levels were created to make it easier for a human being to read and write programs

1-26 Programming Languages Each type of CPU executes only a particular machine language A program must be translated into machine language before it can be executed A compiler is a software tool which translates source code into a specific target language Often, that target language is the machine language for a particular CPU type The Java approach is somewhat different

1-27 Java Translation The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral

1-28 Syntax and Semantics The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do

1-29 Errors A program can have three types of errors The compiler will find syntax errors and other basic problems (compile-time errors) ◦ If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)

1-30 Basic Program Development errors Edit and save program Compile program Execute program and evaluate results

1-31 Problem Solving The purpose of writing a program is to solve a problem Solving a problem consists of multiple activities: ◦ Understand the problem ◦ Design a solution ◦ Consider alternatives and refine the solution ◦ Implement the solution ◦ Test the solution These activities are not purely linear – they overlap and interact

1-32 Problem Solving The key to designing a solution is breaking it down into manageable pieces When writing software, we design separate pieces that are responsible for certain parts of the solution An object-oriented approach lends itself to this kind of solution decomposition We will dissect our solutions into pieces called objects and classes

1-33 Object-Oriented Programming Java is an object-oriented programming language As the term implies, an object is a fundamental entity in a Java program Objects can be used effectively to represent real-world entities For instance, an object might represent a particular employee in a company Each employee object handles the processing and data management related to that employee

1-34 Objects An object has: ◦ state - descriptive characteristics ◦ behaviors - what it can do (or what can be done to it) The state of a bank account includes its current balance The behaviors associated with a bank account include the ability to make deposits and withdrawals Note that the behavior of an object might change its state

1-35 Classes An object is defined by a class A class is the blueprint of an object The class uses methods to define the behaviors of the object The class that contains the main method of a Java program represents the entire program A class represents a concept, and an object represents the embodiment of that concept Multiple objects can be created from the same class

1-36 Objects and Classes Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class