Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Similar documents
Introduction to Programming

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved.

Chapter 1 Introduction to Computers, Programs, and Java

An Introduction to Software Engineering. David Greenstein Monta Vista High School

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

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

Programming Languages and Program Development

LECTURE/ STUDY NOTES ON C

Chapter 1. Preliminaries

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Chapter 1. Preliminaries

Introduction. A. Bellaachia Page: 1

Lecture 1: Preliminaries

Chapter 1: Introduction

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Chapter 14 Operating Systems

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Chapter 1 Preliminaries

INFS 214: Introduction to Computing

Module 1: Introduction to Computers, Programs, and Java

Chapter 14 Operating Systems

Chapter 1 Introduction to Computers, Programs, and Java

CHAPTER 5 GENERAL OOP CONCEPTS

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

Comp 333: Concepts of Programming Languages Fall 2016

Chapter 1 Introduction to Computers, Programs, and Java

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Unit 1: Introduction to Programming. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

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

CSCI170 Lecture 1: Analysis of Programming Languages. John Magee 1 September 2011 Some material copyright Jones and Bartlett

Concepts of Programming Languages

Chapter 1: Introduction to Computers, Programs, and Java

Principles of Programming Languages. Lecture Outline

Low-Level Languages. Computer Programs and Programming Languages

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

Structured Languages. Rahul Deodhar

Computer Fundamentals : Pradeep K. Sinha& Priti Sinha

Visual Basic Primer A. A. Cousins

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

Introduction to Computers and Java

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

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

Introduction to Computers and Java

Lecture 1: Introduction to Java

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

Computer Software: Introduction

Computer Programming-I. Developed by: Strawberry

0 Introduction: Computer systems and program development

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


Part (04) Introduction to Programming

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Chapter 2. 5 * B => A V 6 7 (subscripts) S 1.n 1.n (data types)

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

1 The Catholic University of Eastern Africa P.o Box , Nairobi Kenya Edward Kioko 2013

Compiler Construction

Discovering Computers 2008

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

2. Evolution of the Major Programming languages

What is programming? What are computer languages and how have they evolved? What is the basic process of programming, including the tools involved?

Programming. Loriano Storchi.

Chapter 2. Pseudocodes: Speedcoding. 2.2 Minimal Hardware Programming: Pseudocodes. Evolution of the Major Programming Languages

ENT 189: COMPUTER PROGRAMMING. H/P: Home page:

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

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

PROGRAMMAZIONE I A.A. 2017/2018

Preview from Notesale.co.uk Page 6 of 52

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Compilers. Prerequisites

Introduction to Java Programming

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

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Programming Languages FILS Andrei Vasilateanu

1. Fundamental Concepts

Högnivåspråk och översättning

Problem Solving and Program Design - Chapter 1. Cory L. Strope

CS 113: Introduction to

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Chapter 1 Introduction to Computers, Programs, and Java

Why do we have to know all that? The stored program concept (the procedural paradigm) Memory

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

Introduction to Computer Programming Using FORTRAN 77

Administration Computers Software Algorithms Programming Languages

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

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

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Programming. Languages & Frameworks. Hans-Petter Halvorsen, M.Sc. O. Widder. (2013). geek&poke. Available:

Lecture 01 & 02 Computer Programming

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

2 rd class Department of Programming. OOP with Java Programming

Computers in Engineering COMP 208. Computer Structure. Computer Architecture. Computer Structure Michael A. Hawker

Transcription:

Computer Fundamentals Pradeep K. Sinha Priti Sinha Chapter 12 Computer Languages Slide 1/64 Learning Objectives In this chapter you will learn about: Computer languages or programming languages Three broad categories of programming languages machine, assembly, and high-level languages Commonly used programming language tools such as assembler, compiler, linker, and interpreter Concepts of object-oriented programming languages Some popular programming languages such as FORTRAN, COBOL, BASIC, Pascal, C, C++, C#, Java, RPG, LISP and SNOBOL Related concepts such as Subprogram, Characteristics of a good programming language, and factors to consider while selecting a language for coding an application Slide 2/64 Analogy with Natural Languages Slide 3/64 1

Analogy with Natural Languages Language is a means of communication Programmer uses a computer language to instruct a computer what he/she wants it to do Set of words allowed in a language is called its vocabulary Each word in the vocabulary has a definite unambiguous meaning Most computer languages use a very limited vocabulary Words and symbols of a computer language must be used as per the set rules, known as syntax rules Ref. Page 220 Slide 4/64 Broad Classification of Computer Languages Machine language Assembly language High-level language Ref. Page 221 Slide 5/64 Machine Language Slide 6/64 2

Machine Language Machine language programs are written normally as strings of binary 1s and 0s Circuitry of a computer is wired in a manner that it recognizes the machine language instructions and converts them into electrical signals needed to execute them A machine language instruction normally has a two-part format: operation code tells the computer what function to perform, and operand tells where to find or store the data OPCODE (operation code) OPERAND (address/location) Instruction format (Continued on next slide ) Ref. Page 221 Slide 7/64 Machine Language Every computer has a set of operation codes called its instruction set Typical operations included in the instruction set are: Arithmetic operations Logical operations Branch operations Data movement operations between memory locations and registers Data movement operations from/to input/output devices Ref. Page 221 Slide 8/64 A Sample Machine Language Program 001000000000001100111001 001100000000010000100001 011000000000011100101110 101000111111011100101110 000000000000000000000000 10001471 14002041 30003456 50773456 00000000 In Binary (Difficult to read and understand) In Decimal (Easier to read and understand) Ref. Page 222 Slide 9/64 3

Advantages & Limitations of Machine Language Advantage Can be executed very fast Limitations Machine dependent Difficult to program Error prone Difficult to modify Ref. Page 222 Slide 10/64 Assembly Language Slide 11/64 Assembly Language Assembly language programming helped in overcoming limitations of machine language programming By using alphanumeric mnemonic codes instead of numeric codes for instructions in instruction set Allowing use of alphanumeric names instead of numeric addresses Providing additional instructions, called pseudo-instructions A language that allows use of letters and symbols instead of numbers for representing instructions and storage locations is called assembly language or symbolic language A program written in an assembly language is called assembly language program or symbolic program Ref. Page 223 Slide 12/64 4

Sample Assembly Language Program START PROGRAM AT 0000 START DATA AT 1000 SET ASIDE AN ADDRESS FOR FRST SET ASIDE AN ADDRESS FOR SCND SET ASIDE AN ADDRESS FOR ANSR CLA FRST ADD SCND STA ANSR HLT Ref. Page 223 Slide 13/64 Assembler We must convert an assembly language program into its equivalent machine language program before executing it Translator program called assembler does this translation Assembler is system software supplied by computer manufacturers Assembly language program Input Assembler Output Machine language program (Source program) One-to-one correspondence (Object program) Ref. Page 224 Slide 14/64 Advantages of Assembly Language Over Machine Language Easier to understand and use Easier to locate and correct errors Easier to modify No worry about addresses Easily relocatable Efficiency of machine language Ref. Page 226 Slide 15/64 5

Limitations of Assembly Language Machine dependent Knowledge of hardware required Machine level coding Ref. Page 227 Slide 16/64 Typical Uses of Assembly Language Mainly used today to fine-tune important parts of programs written in a high-level language to improve the program s execution efficiency Ref. Page 228 Slide 17/64 Assembly Languages with Macro Instructions Any assembly language instruction that gets translated into several machine language instructions is called a macro instruction Several assembly languages support such macro instructions to speed up the coding process Assemblers of such assembly languages are designed to produce multiple machine language instructions for each macro instruction of the assembly language Ref. Page 228 Slide 18/64 6

High-level Language Slide 19/64 High-Level Languages Machine independent Do not require programmers to know anything about the internal structure of computer on which high-level language programs will be executed Deal with high-level coding, enabling the programmers to write instructions using English words and familiar mathematical symbols and expressions Ref. Page 228 Slide 20/64 Compiler Translator program (software) that translates a highlevel language program into its equivalent machine language program Compiles a set of machine language instructions for every program instruction in a high-level language Ref. Page 229 Slide 21/64 7

Compiler High-level language program Input Compiler Output Machine language program (Source program) One-to-many correspondence (Object program) Ref. Page 230 Slide 22/64 Separate Compiler for Each High-level Language Supported Program P1 in highlevel language L1 Compiler for language L1 Machine code for P1 Program P2 in highlevel language L2 Compiler for language L2 Machine code for P2 A computer supporting languages L1 and L2 (Continued on next slide) Ref. Page 230 Slide 23/64 A High-level Language is Machine Independent Compiler for language L1 on computer A Machine code for P1 that will run on computer A Executed on computer A Program P1 in highlevel language L1 Same results obtained Compiler for language L1 on computer B Machine code for P1 that will run on computer B Executed on computer B Ref. Page 231 Slide 24/64 8

Syntax Errors In addition to doing translation job, compilers also automatically detect and indicate syntax errors Syntax errors are typically of following types: Illegal characters Illegal combination of characters Improper sequencing of instructions in a program Use of undefined variable names Note : A compiler cannot detect logic errors in a program Ref. Page 231 Slide 25/64 START The Process of Removing Syntax Errors From A Source Program Edit source program Compile source program Source program Syntax errors detected? Yes No Generate list of coded error messages Generate object program STOP Object program Ref. Page 232 Slide 26/64 Linker For a large software, storing all the lines of program code in a single source file will be: Difficult to work with Difficult to deploy multiple programmers to concurrently work towards its development Any change in the source program would require the entire source program to be recompiled Hence, a modular approach is generally adapted to develop large software where the software consists of multiple source program files No need to write programs for some modules as it might be available in library offering the same functionality (Continued on next slide) Ref. Page 232 Slide 27/64 9

Linker Each source program file can be independently modified and compiled to create a corresponding object program file Linker program (software) is used to properly combine all the object program files (modules) Creates the final executable program (load module) Ref. Page 232 Slide 28/64 Linker Compilation process Prog-1.src Prog-2.src Prog-n.src Prog-1.obj Prog-2.obj Prog-n.obj Source programs Object programs Prog-i.lib Library modules Linking process Executable program file Load module Ref. Page 232 Slide 29/64 Interpreter Interpreter is a high-level language translator Takes one statement of a high-level language program, translates it into machine language instructions Immediately executes the resulting machine language instructions Compiler simply translates the entire source program into an object program and is not involved in its execution Ref. Page 233 Slide 30/64 10

Interpreter High-level language program Input (Source program) Interpreter (translates and executes statement-by-statement) Output Result of program execution Ref. Page 233 Slide 31/64 Interpreter As compared to compilers, interpreters are easier to write The main advantage of interpreters over compilers is that an interpreter flags a syntax error in a program statement to a programmer as soon as it interprets the program statement Main disadvantage of interpreters over compilers is that they are slower than compilers To combine the advantages of both interpreters and compilers, computer system provides both a compiler and an interpreter for a high-level language Assemblers, compilers, and interpreters are also referred to as language processors Ref. Page 233 Slide 32/64 Intermediate Language Compiler & Interpreter New type of compiler and interpreter combines the speed, ease, and control of both compiler and interpreter Compiler first compiles the source program to an intermediate object program Intermediate object program is not a machine language code but written in an intermediate language that is virtually machine independent Interpreter takes intermediate object program, converts it into machine language program and executes it Ref. Page 234 Slide 33/64 11

Benefits of Intermediate Language Compiler & Interpreter Intermediate object program is in compiled form and thus is not original source code, so safer and easier to share Intermediate object program is based on a standard Intermediate Definition Language (IDL) Interpreter can be written for any computer architecture and operating system providing virtual machine environment to the executing program Newer Interpreter compiles intermediate program, in memory, into final host machine language program and executes it This technique is called Just-In-Time (JIT) Compilation Ref. Page 234 Slide 34/64 Advantages of High-Level Languages Machine independent Easier to learn and use Fewer errors during program development Lower program preparation cost Better documentation Easier to maintain Ref. Page 234 Slide 35/64 Limitations of High-Level Languages Lower execution efficiency Less flexibility to control the computer s CPU, memory and registers Ref. Page 235 Slide 36/64 12

Object-Oriented Languages Slide 37/64 What is Object-Oriented Programming (OOP)? Essence of OOP is to solve a problem by: Identifying the real-world objects of the problem and the processing required of those objects Then creating simulations of those objects, their processes, and the required communications between the objects OOP makes programming simpler, easier, and faster OOP philosophy is now used in almost all popular programming languages Ref. Page 236 Slide 38/64 Fundamental Concepts of OOP Object An object is the primitive element of a program written in an OOP language Each object consists of a set of procedures and some data Method A method of an object defines the set of operations that the object will execute when it receives a message Methods are like function definitions Entire collection of methods of an object is called the message protocol, or message interface Message Mechanism to support communication between objects is through messages Ref. Page 236 Slide 39/64 13

Fundamental Concepts of OOP Class A class is a description of one or more similar objects A class can have multiple instances Each instance of a class is known as an object of the class Class variables are variables stored in the class whose values are shared by all instances Instance variables are variables for which local storage is available in the instances (objects) Inheritance Inheritance is a mechanism to share code and behavior A child class inherits all of the instance variables, instance methods, and class methods of its parent class A child class can inherit from multiple parent classes. This is called multiple inheritance Ref. Page 237 Slide 40/64 Example of Class, Instance, and Inheritance Person Classes Male Female Boy Man Instances Ram Shyam Mohan Seeta Geeta Ref. Page 238 Slide 41/64 Example of Objects, Class, and Inheritance Class A Variables of A Class A Object a (Instance of A ) Methods of A Instance variables of A Class B (Sub-class of Class A ) Inherits from A Variables of B Methods of B Class B Object b (Instance of B ) Inherited instance variables of A Instance variables of B Ref. Page 239 Slide 42/64 14

Key Elements of Object-Oriented Paradigm Sr. No. Element Meaning 1 Abstraction Abstraction means that an object s characteristics are broken into manageable chunks as defined and documented in its class description. 2 Encapsulation Encapsulation stipulates that code and data are stored as one unit. Encapsulation also enables selective or total information hiding, since it can make portions of the code and data inaccessible from outside the unit. 3 Modularity Modularity defines the unit reuse. These units group abstractions together. 4 Hierarchy Hierarchy allows an object s behaviors to be refined (subclasses) without recoding of the parent object (the superclass). Some OO languages allow an object to have more than one superclass, a feature that is known as multiple inheritance. Inheritance hierarchies enable ranking/ordering of abstractions. 5 Messages Messages, similar in use to function calls, are requests to perform an operation on an instantiated object. Ref. Page 239 Slide 43/64 Some High-level Languages Slide 44/64 FORTRAN Stands for FORmula TRANslation Originally developed by John Backus and his team at IBM followed by several revisions Standardized by ANSI as FORTRAN-77 and FORTRAN-90 Designed for solving scientific & engineering problems Oriented towards solving problems of a mathematical nature Popular language amongst scientists and engineers Ref. Page 240 Slide 45/64 15

COBOL Stands for COmmon Business Oriented Language Originally developed started under Grace Hopper followed by COnference on DAta SYstems Languages (CODASYL) Standardized by ANSI as COBOL-74, COBOL-85, and COBOL-2002 Designed for programming business data processing applications Designed to have the appearance and structure of a business report written in English, hence often referred to as a self-documenting language Ref. Page 241 Slide 46/64 BASIC Stands for Beginners All-purpose Symbolic Instruction Code Developed by Professor John Kemeny and Thomas Kurtz at Darmouth College in the United States Standardized by ANSI as BASIC-78 Designed to be an interactive language and to use an interpreter instead of a compiler Simple to implement, learn and use language. Hence, it is a widely used language on personal computers Flexible and reasonably powerful language and can be used for both business and scientific applications Ref. Page 243 Slide 47/64 Pascal Named after the famous seventeenth-century French mathematician Blaise Pascal Developed by Professor Nicklaus Wirth of Federal Institute of Technology in Zurich Encourages programmers to write well-structured, modular programs, instills good program practices Recognized as an educational language and is used to teach programming to beginners Suitable for both scientific & business applications Has features to manipulate numbers, vectors, matrices, strings, sets, records, files, and lists Ref. Page 244 Slide 48/64 16

C Developed in 1972 at AT&T s Bell laboratories, USA by Dennis Ritchie and Brian Kernighan Standardized by ANSI and ISO as C89, C90, C99 High-level programming languages (mainly machine independence) with the efficiency of an assembly language Language of choice of programmers for portable systems software and commercial software packages like OS, compiler, spreadsheet, word processor, and database management systems Ref. Page 245 Slide 49/64 C++ (C plus plus) Named C++ as ++ is increment operator and C language is incremented to its next level with C++ Developed by Bjarne Stroustrup at Bell Labs in the early 1980s Contains all elements of the basic C language Expanded to include numerous object-oriented programming features Provides a collection of predefined classes, along with the capability of user-defined classes Being a superset of C, it is an extremely powerful and efficient language. However, it is more difficult to learn than C Ref. Page 245 Slide 50/64 Java Development started at Sun Microsystems in 1991 by a team led by James Gosling Developed to be similar to C++ with fewer features to keep it simple and easy to use Compiled code is machine-independent and developed programs are simple to implement and use Uses just-in-time compilation Used in embedded systems such as hand-held devices, telephones and VCRs Comes in two variants Java Runtime Engine (JRE) and Java Software Development Kit (SDK) Ref. Page 247 Slide 51/64 17

C# (C Sharp) Object-oriented programming language developed by Anders Hejlsberg and released by Microsoft as part of Microsoft s.net technology initiative Standardized by ECMA and ISO Syntactically and semantically very close to C++ and adopts various object-oriented features from both C++ and Java Compilers target the Common Language Infrastructure (CLI) implemented by Common Language Runtime (CLR) of.net Framework CLR provides important services such as, memory management, exception handling, and security Ref. Page 248 Slide 52/64 RPG Stands for Report Program Generator Developed by IBM to meet customer requests for an easy and economic mechanism for producing reports Designed to generate the output reports resulting from the processing of common business applications Easier to learn and use as compared to COBOL Programmers use very detailed coding sheets to write specifications about input, calculations, and output Ref. Page 249 Slide 53/64 LISP Stands for LISt Processing Developed in 1959 by John McCarthy of MIT Designed to have features for manipulating nonnumeric data, such as symbols and strings of text Due to its powerful list processing capability, it is extensively used in the areas of pattern recognition, artificial intelligence, and for simulation of games Functional programming language in which all computation is accomplished by applying functions to arguments Ref. Page 249 Slide 54/64 18

SNOBOL Stands for StriNg Oriented symbolic Language Used for non-numeric applications Powerful string manipulation features Widely used for applications in the area of text processing Ref. Page 249 Slide 55/64 Selecting a Language for Coding an Application Slide 56/64 Characteristics of a Good Programming Language Simplicity Naturalness Abstraction Efficiency Structured Programming Support Compactness Locality Extensibility Suitability to its environment Ref. Page 250 Slide 57/64 19

Factors for Selecting a Language for Coding an Application Nature of the application Familiarity with the language Ease of learning the language Availability of program development tools Execution efficiency Features of a good programming language Ref. Page 251 Slide 58/64 Subprogram Slide 59/64 Subprogram Program written in a manner that it can be brought into use in other programs and used whenever needed without rewriting Also referred to as subroutine, sub-procedure, or function Subprogram call statement contains the name of the subprogram followed by a list of parameters enclosed within a pair of parentheses Intrinsic subprograms (also called built-in-functions) are those provided with the programming language Programmer-written subprograms are written and used as and when they are needed Ref. Page 251 Slide 60/64 20

Structure of a Subprogram Subprogram name Parameter sqrt (x) Subprogram header Set of instructions that perform the intended task Subprogram body Ref. Page 252 Slide 61/64 Flow of Control in Case of Subprogram Calls 1 2 subprogram header subprogram call statement next statement 4 6 3 5 7 subprogram body subprogram call statement next statement 9 8 A program that calls the subprogram twice Flow of control A subprogram Ref. Page 252 Slide 62/64 Key Words/Phrases Assembler Assembly language BASIC Built-in function C C++ C# COBOL Coding Compiler Computer language FORTRAN Function High-level language HotJava Interpreter Intrinsic subprogram Intermediate compiler and Interpreter Java Just-in-time compilation Language processor Linker LISP Load module Logic error Low-level language Machine language Macro instructions Object program Object-oriented programming Opcode Operand Pascal Programmer Programming Programming language Pseudo instruction RPG Self-documenting language (Continued on next slide) Slide 63/64 21

Key Words/Phrases SNOBOL Source program Sub-procedure Subprogram Subroutine Symbolic language Syntax error Syntax rules Programmer-written subprograms Slide 64/64 22