Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.

Similar presentations


Presentation on theme: "DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS."— Presentation transcript:

1 DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS )‏

2 DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 2 ‏ Introduction to Computer Programming

3 3 ‏ Computer Program A set of instructions written in a computer understandable format. Computer Programming Language An artificial language that can be used to control the behavior of a computer. Source Code Any series of statements written in a computer programming language. Computer Programming The process of writing, testing, and maintaining the source code of computer programs.

4 4 ‏ High Level Programming Languages The source code cannot be directly understood by a computer. Therefore it must be converted into a computer understandable (executable) form before it can run. The translation of the source code into machine code can be done in two ways  Compilation – translates the entire high level language source code(into an executable file) before the execution.  Interpretation – translates the high level language source code line by line at the execution time.

5 5 Compilers and Interpreters 5 Computers cannot directly understand the source code. Instead they can understand their own language known as “Machine Language” or “Machine Code”. Different computer platforms (hardware + operating system) have different machine languages.  For example: each of Microsoft Windows on Intel Pentium hardware and Mac OS X on Apple Macintosh hardware would not understand each others machine language. Therefore a programming language's source code needs to be converted into Machine Code before it can be use to control the behavior of a computer. Need another computer program to make this conversion  Compiler.  Interpreter.

6 6 Compilers and Interpreters… 6 Compiler Compilers convert the entire source code into machine before the execution. The machine code is executed only after all the source code has been converted. Since, different computer platforms have different machine languages, source code compiled into machine code for one architecture might not run on another. Interpreter Does not convert the entire source code at once. Converts one source code statement, executes the resulting machine code and then coverts the next source code statement and so on.

7 7 7 Computer Program Can be treated in 3 basic processes. Steps available in a program 1. How and from where to get input data. 2. What are the operations and how to perform them on the input data. 3. How and where to output the resulting data. Data Can be considered in 3 types 1. Numeric 2. Character 3. Boolean

8 8 Data Types 8 64 bitsdouble Data TypeSizeRange byte8 bits-256 to 255 short16 bits-32,768 to 32767 int32 bits-2,147,483,648 to 2,147,483,647 long64 bits-9,223,372,036,854,775,808 to 9,223,372,036,854,775,808 float32 bits Represent numbers with fractional precision character16 bitsCan store one character booleanCan hold logical values; true and false

9 9 Data Types… 9 Is a classification identifying one of various types of data consists of 1. set of data values that can be under the data type. 2. set of operations that can be applied to those data values.  Example: Numeric Data Types 1. Integer contains positive and negative whole numbers including zero. 2. Real All the numbers on the number scale including all the Integers and all the fractions.

10 10 Data Types… 10 Operations that can be performed on numeric data − Integer : Addition (+), Subtraction (-), Multiplication (*), Division (/) and Modulus (%). − Real : Addition (+), Subtraction (-), Multiplication (*) and Division (/)

11 11 Operations, Operators and Operands. 11 Ex: an arithmetic operation 10+5=15. operand operator Arithmetic Relational Logical Operation

12 12 Operations, Operators and Operands.. 12 Operators 1.Arithmetic Operators 2.Relational Operators

13 13 Operations, Operators and Operands.. 13 Result of a relational operation is always true or false. Ex: 3= = 4 false3 =4 false 3<>4 true3 4 true 3. Logical Operators.

14 14 Other Operators 14 Assignment Operators Assignment operators are used to assign the values of an expression to a variable. Ex: a=10;.

15 15 Other Operators… 15. Increment and Decrement Operators The Increment Operator ++ adds 1 to the operand while subtract 1.They can by used in the following ways. m++ ++m is equivalent to m = m + 1; (or m += 1;) m– – – –m is equivalent to m = m – 1; (or m –=1;)

16 16 Other Operators… 16. Bitwise Operator These operators are used for testing the bits, or shifting them to the right or left.

17 17 Other Operators… 17. Special Operators Java supports some special operators of interest such as instanceof operator and member selection operator (.) − Instanceof Operator The instanceof is an object reference operator and returns true if the object on the left hand side is an instance of the class given on the right-hand side. This allows to determine whether the object belongs to a particular class or not. E.g. st1 instanceof Student is true if the object st1 belongs to the class Student ; otherwise it is false.

18 18 Other Operators… 18. − Dot Operator The dot operator (.) is used to access the instance variables and methods of class objects. E.g. student1.age // Reference to the variable age employee1.calSalary() // Reference to the method calSalary()

19 06/26/10 An expression is any legal combination of symbols that represents a value. Each programming language and application has its own rules for what is legal and illegal. For example, in C programming language x+5 is an expression. Every expression consists of at least one operand and can have one or more operators. Operands are values, whereas operators are symbols that represent particular actions. Ex: In the expression x+5 x and 5 are operands + is an operator. Ex: 3 + 4 * 5 / 7 – 2 It is necessary to have rules which define the order in which the operations are carried out such rules are called the Order of Precedence of operators. Expressions

20 06/26/10 When writing complex expressions with several operands and operators it is possible to have doubts about which operation is evaluated first and which later. For Example the expression a = 6 + 8 / 2 could be considered in two ways, 1. a = 6 + ( 8 / 2 ) → with a result of 10 2. a = ( 6 + 8 ) / 2 → with a result of 7 Order Of Precedence

21 06/26/10 Order Of Precedence 1. a = 6 + ( 8 / 2 ) → result is 10

22 06/26/10 Syntax and Semantics Syntax The syntax of a programming language are the grammatical rules which controls the ways in which words, expressions and statements may be formed and combined. E.g. : in C int a syntactically incorrect. (syntax error) int a; syntactically correct. Every statement should end up with a semicolon. This type of errors are also known as compile time errors.

23 06/26/10 Syntax and Semantics… Semantics The semantics of a language are the rules which govern the meaning. E.g.: in C int a=5; int b=5; int c=10; int d=0; d=c/(a-b); semantically incorrect. here (a-b)=0 therefore d=c/0 this is semantically incorrect. These errors are also known as “Run time errors ”. (Fatal errors, Logical errors).

24 06/26/10 Syntax and Semantics… Semantics The semantics of a language are the rules which govern the meaning. E.g.: in C int a=5; int b=5; int c=10; int d=0; d=c/(a-b); semantically incorrect. here (a-b)=0 therefore d=c/0 this is semantically incorrect. These errors are also known as “Run time errors ”. (Fatal errors, Logical errors).

25 06/26/10 Data input & Storage The input data for a computer are need to be stored in the main memory for the processing. Once this data is stored, it is necessary to have an identifier to identify the place where the data is.

26 06/26/10 Data input & Storage… Identifiers An identifier is the name by which the data value can be referenced. The names which are associated with the stored data values in the memory. 2 types  constants  variables. Constants An identifier is a constant if it is associated with the same data value. Variable An identifier is a variable if its associated data value is allowed to change.

27 06/26/10 Data input & Storage… Variable Declaration Reserve a place in the memory before storing data. At the declaration two things should be mentioned. 1.Variable name (identifier name): − name assigned to the location where the value is stored. 2. Data type: − to declare the amount of memory to be reserved. E.g.: in C Int a; integer → 16 bits.

28 06/26/10 Data input & Storage… Data types can be categories into two groups Simple data type: also called predefined data type by the language. In C: Int float, double, char Abstract data type: a collection of simple data type. E.g.: Array structures struct student { int regNo; int age; }

29 06/26/10 Data input & Storage… Variable initialization Assigning a value to a variable before using it for the operations is called variable initialization. int a; → declaration a=10; → initialization. After storing data in the main memory Algorithms are used to perform some functionality to produce a desired output.


Download ppt "DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS."

Similar presentations


Ads by Google