Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Similar documents
Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Introduction to Computers and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Introduction to Computers and Java

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

Introduction to Java Programming

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

Object-Oriented Programming in C++/Handout 01 Page 1 of 8

Chapter 1 Introduction to Computers, Programs, and Java

8/16/12. Computer Organization. Architecture. Computer Organization. Computer Basics

Computer Principles and Components 1

From High Level to Machine Code. Compilation Overview. Computer Programs

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

C H A P T E R 1. Introduction to Computers and Programming

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

2 rd class Department of Programming. OOP with Java Programming

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

CHAPTER 5 GENERAL OOP CONCEPTS

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Copyright 2005 Department of Computer & Information Science

For 100% Result Oriented IGNOU Coaching and Project Training Call CPD TM : ,

Programming Languages FILS Andrei Vasilateanu

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

CS112 Lecture: Primitive Types, Operators, Strings

Programming 1 - Honors

Lecture 1 - Introduction (Class Notes)

Computer Software: Introduction

CHAPTER 1 Introduction to Computers and Java

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

What are the characteristics of Object Oriented programming language?

Lecture Notes on Programming Languages

CSCI 253. Outline. Background. George Blankenship 1

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

Objectives: 1. Introduce the course. 2. Define programming 3. Introduce fundamental concepts of OO: object, class

Computer Fundamentals

Java and Software Design

Class List. Java Must Have. Class Goals. Class Goals. Schedule

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

Sri Vidya College of Engineering & Technology

1) Which of the following is an example of a programming language? 1) A) Microsoft Word B) English C) HTML D) Java

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Chapter 11 Program Development and Programming Languages

1. Write two major differences between Object-oriented programming and procedural programming?


Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

VALLIAMMAI ENGINEERING COLLEGE

Programming & Computers

An Introduc+on to Computers and Java CSC 121 Spring 2017 Howard Rosenthal

Chapter 1: Introduction to Computers, Programs, and Java

Computer is an electronic machine that can receive, store, transform and output data of all kinds (image, text, numeric, graphics and sound).

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Introduction to Object-Oriented Programming

Programming 1. Lecture 1 COP 3014 Fall August 28, 2018

Introduction to Computers and Java

1. BlueJ bank example with subclasses of BankAccount 2. Transparency of UML diagram for BankAccount class hierarchy

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

Module 1: Introduction to Computers, Programs, and Java

Computer Science (330)

The Programming Process Summer 2010 Margaret Reid-Miller

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

CPS122 Lecture: Course Intro; Introduction to Object-Orientation

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

JAVA: A Primer. By: Amrita Rajagopal

Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952. Computing for Biomedical Scientists

Structured Programming

Computer Programming-1 CSC 111. Chapter 1 : Introduction

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started

Data Structures (list, dictionary, tuples, sets, strings)

OO design. Classes, Responsibilities, Collaborations (CRC) 13/9/1999 COSC

CHAPTER 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING. 1 Muhalim Mohamed Amin Faculty of

INTRODUCTION TO THE COURSE

INTRODUCTION TO Object Oriented Systems BHUSHAN JADHAV

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Object-Oriented Programming Paradigm

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Object Oriented Programming

An Introduction to Computers and Java CSC 121 Spring 2015 Howard Rosenthal

Object Oriented Programming

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Introduction to Unified Modelling Language (UML)

Programming Languages 2nd edition Tucker and Noonan"

Chapter 1. Introduction

Appendix A - Glossary(of OO software term s)

CS112 Lecture: Working with Numbers

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

AP Computer Science A: Java Programming

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

COS 140: Foundations of Computer Science

Transcription:

Introduction to Computers and Programming Languages CS 180 Sunil Prabhakar Department of Computer Science Purdue University 1

Objectives This week we will study: The notion of hardware and software Programming paradigms Java portability Fundamentals of Object-Oriented Programming classes and objects inheritance The software lifecycle 2 2

Computer Systems There are two main components of a computer: Hardware The physical device including the IC chips, hard disks, displays, mice, etc. Generally stuff that you can touch. Software The information stored on the computer Includes programs and data Stored in binary (0s and 1s) 3 3

Computer Architecture (simplified) Network Devices CPU brains Monitor Keyboard Mouse Memory Printer Storage Devices More in CS250: Computer Architecture. 4 4

Software Everything is in binary -- 0s and 1s Two types of information Instructions(programs) -- executed by the CPU Data -- manipulated by CPU These are stored in memory The software provides a means to access and control the hardware This is done through a very important piece of software called the Operating System The OS is always running. More in CS354 5 5

Programs A program is simply a set of instructions to the CPU to perform one of its operations Arithmetic, Logic, Tests, Jumps, A program typically takes input data, e.g. input keywords to a browser mouse clicks as input to the operating system It also produces output, e.g. the display of search results in a browser launching a program The program is stored in memory. It is read and executed by the CPU 6 6

Machine Language A computer only runs programs that are specified in its own machine language (ML) For example, for the 8085 microprocessor: 11000011 1000010100100000 Instruction Address Also called binary or executable code. This instruction tells the CPU to pick its next instruction from memory location 133200. The ML is specific to the CPU, e.g. Pentium, 386, PowerPC G3, G4, A program written for one CPU will not run on another CPU -- i.e. it is not portable. 7 7

Assembly language Machine language codes are not easy to remember Assembly language uses mnemonics and symbols to ease programming, e.g. JMP L2 A special program called an assembler must be used to convert the assembly code to machine code The assembly code is also hardware-specific. Eases programming but still requires one to think in terms of low-level steps taken by the CPU. Humans think at a higher level. 8 8

High-Level Languages Allow programmers to work with constructs that are closer to human language. E.g. Java, C, C++, Basic, Fortran, COBOL, Lisp, Need a special purpose program to convert the high-level program to machine language. This program is called a compiler. Can write programs in many different HLLs for the same CPU. Need a compiler for each language and CPU (OS). Efficient conversion is still an issue. More in CS352 Compilers 9 9

High-Level Languages (cont.) Since the language is not specific to the hardware, HLL programs are more portable Some hardware, OS issues limit portability All we need is the program and a compiler for that language on the given hardware platform E.g. a C compiler for Mac OSX Thus we can write a program once in a HLL and compile it to run on various platforms, e.g. Netscape 10 10

Source Code A program written in a machine language is called an executable, or a binary. It is not portable. A program written in a HLL is often called source code. Given an executable, it is difficult to recover the source code (not impossible). Thus, companies release only the executables. This makes it hard for someone else to replicate the software and also to modify it (maybe even to trust it completely) Open-Source is an alternative approach. 11 11

Algorithms Humans tend to think of programs at a higher level than HLL -- more in terms of algorithms. An algorithm is a well-defined, finite set of steps that solves a given problem E.g. the rules for multiplying two numbers Algorithms are sometimes described using flow charts, or pseudo-code. This avoids the details of a particular HLL s syntax rules. 12 12

HLL Paradigms Procedural A program is composed of packets of code called procedures, and variables. A procedure is at full liberty to operate on data that it can see. E.g. C, Pascal, COBOL, Fortran Object-Oriented Programs are composed of Objects, each of a specific class with well defined methods. Data and programs are tightly coupled -- better design. E.g. Java, C++, Objective-C, C# Functional Programs are composed of functions. E.g. Lisp More in CS456 Programming Languages. 13 13

Java Java is based upon C++ (which in turn is based on C). Unlike C++ which is really a hybrid language, Java is purely Object-Oriented. This results in significant advantages. Most HLL programs are compiled to run on a single platform. Java programs can run on multiple platforms after compilation -- i.e. its compiled format is platformindependent. This design choice comes from its history. 14 14

History of Java Java was developed by J. Gosling at Sun Microsystems in 1991 for programming home appliances (variety of hardware platforms). With the advent of the WWW (1994), Java s potential for making web pages more interesting and useful was recognized. Java began to be added to web pages (as applets) that could run on any computer (where the browser was running). Since then it has been more widely accepted and used as a general-purpose programming language, partly due to its platform-independence, and it is a truly OO language (unlike C++) 15 15

Platform-Independence Notion of a Java Virtual Machine (JVM) Java programs are compiled to run on a virtual machine (just a specification of a machine). This code is called Byte Code Each physical machine that runs a Java program (byte code) must pretend to be a JVM. This is achieved by running a program on the machine that implements the JVM and interprets the byte code to the appropriate machine code. This interpreting is done at run-time which can cause a slow down! 16 16

Regular Programming Languages C program Fortran program C-OSX Compiler C-Linux Compiler For-OSX Compiler FOR-Linux Compiler 0101 0110 0101 1010 0110 1111 1101 0010 0111 1101 0010 0111 17 17

Java Java Program Java Compiler Java Byte Code 0101 0110 0101 OSX Interpreter Linux Interpreter 1101 0010 0111 18 18

Programs A program is composed of two important pieces: data and instructions Instructions tell the CPU what steps to take, and on what data items to operate. Data may be part of the program, supplied as input, or produced as the output 19 19

Data All data is eventually stored in binary. In a HLL we treat data as having a type, e.g. integer, character, etc. Within a program every piece of data is stored at some location in memory. We use identifiers to refer to these locations or to the data itself. Program instructions manipulate the various pieces of data accessible to the program. An object is a collection of some data along with pieces of code that can manipulate that data. 20 20

Object-Oriented Programming The OOP paradigm uses the notion of objects and classes as basic building blocks Other important components of OOP are Encapsulation Inheritance Polymorphism (later) Dynamic binding (later) 21 21

Classes and Objects Object-oriented programs use objects. An object represents a concept that is part of our algorithm, such as an Account, Vehicle, or Employee Similar objects share characteristics and behavior. We first define these common characteristics for a group of similar objects as a class. A class defines the type of data that is associated with each object of the class, and also the behavior of each object (methods). A class is a template for the objects. Woodcuts. An object is called an instance of a class. Most programs will have multiple classes and objects. 22 22

Banking Example In a banking application, there may be numerous accounts. There is common behavior (as far as the bank is concerned) for all these accounts Deposit Check balance Withdraw Overdraw? There are also common types of data that the bank in interested in Account holder s name(s), SSN Current balance, recent transactions, Instead of defining these data and behavior for each account separately, we simple define them once -- this is the notion of the account class. Each account will be an instance of this class and will have its own values for the data items, but the same behavior (defined once). 23 23

Graphical Representation of a Class <Class Name> We use a rectangle to represent a class with its name appearing inside the rectangle. Example: Account Motorcycle The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. 24 24

Graphical Representation of an Object <Object Name> We use a rectangle to represent an object and place the underlined name of the object inside the rectangle. Example: SV198 This is an object named SV198. 25 25

An Object with the Class Name <Object Name> : <Class Name> This notation indicates the class which the object is an instance of. Example: SV198 : BankAccount This indicates that object SV198 is an instance of the BankAccount class. 26 26

Messages and Methods To instruct a class or an object to perform a task (behavior), we send a message to it. You can send a message only to the classes and objects that understand that message. A class or an object must possess a matching method to be able to handle the received message. A method defined for a class is called a class method, and a method defined for an object is called an instance method. A value we pass to an object when sending a message is called an argument of the message. 27 27

Encapsulation An object not only holds data, it can only perform actions that are defined for its class. This restriction of behavior is also called encapsulation -- an important part of OOP. The data and behavior are encapsulated. This greatly improves reliability and manageability of code. 28 28

Sending a Message Message deposit with the argument 250.00 is sent to a BankAccount object SV198. deposit (250.00) SV198 : BankAccount 29 29

Sending a Message and Getting an Answer Ask for the current balance of this particular account. getcurrentbalance() SV198 : BankAccount current balance The current balance of SV198 is returned. 30 30

Calling a Class Method Ask for the maximum possible speed for all MobileRobot objects. getmaximumspeed() MobileRobot maximum speed 31 31

Class and Instance Data Values An object is comprised of data values and methods. An instance data value is used to maintain information specific to individual instances each BankAccount object maintains its balance A class data value is used to maintain information shared by all instances or aggregate information about the instances Avoids repeated storage Easy to modify Less prone to errors E.g. minimum balance 32 32

Sample Instance Data Value SV129 : BankAccount SV098 : BankAccount SV211 : BankAccount current balance current balance current balance 908.55 1304.98 354.00 All three BankAccount objects possess the same instance data value current balance. The actual dollar amounts are, of course, different. 33 33

Sample Class Data Value BankAccount minimum balance 100.00 There is one copy of minimum balance for the whole class and shared by all instances. This line is an instance-of relationship. SV129 : BankAccount SV098 : BankAccount SV211 : BankAccount current balance current balance current balance 908.55 1304.98 354.00 34 34

Object Icon with Class Data Value SV129 : BankAccount minimum balance 100.00 current balance 908.55 When the class icon is not shown, we include the class data value in the object icon itself. 35 35

Inheritance Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. Features common to all classes are defined in the superclass. The classes that inherit common features from the superclass are called subclasses. We also call the superclass an ancestor and the subclass a descendant. 36 36

A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Superclass (Ancestor) Subclass (Descendant) Checking Savings 37 37

Inheritance (cont.) The account class may define Owner s Name(s) Getbalance The Checking class may define Minimum (checking) balance ATM transactions The Savings class may define Minimum (savings) balance Interest rate Pay interest 38 38

Inheritance Hierarchy An example of an inheritance hierarchy among different types of students. Student Graduate Undergrad Masters Doctoral Law Commuting Resident 39 39

Software Engineering Much like building a skyscraper, we need a disciplined approach in developing complex software applications. Software engineering is the application of a systematic and disciplined approach to the development, testing, and maintenance of a program. In this class, we will learn how to apply sound software engineering principles when we develop sample programs. 40 40

Software Life Cycle The sequence of stages from conception to operation of a program is called the software life cycle. Five stages are Analysis Design Coding Testing Operation and Maintenance More in CS307, 407 Software Engg. 41 41