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

Slides:



Advertisements
Similar presentations
© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Types and Arithmetic Operators
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
String Escape Sequences
Basic Elements of C++ Chapter 2.
Expressions, Data Conversion, and Input
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.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
CIS Computer Programming Logic
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
2440: 211 Interactive Web Programming Expressions & Operators.
Computer Science 101 Introduction to Programming.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Lecture #5 Introduction to C++
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 7: Expressions and Assignment Statements
Chapter 12 Variables and Operators
BASIC ELEMENTS OF A COMPUTER PROGRAM
Java Primer 1: Types, Classes and Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Object Oriented Programming
Chapter 7: Expressions and Assignment Statements
Revision Lecture
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 12 Variables and Operators
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Chapter 4: Expression and Operator
Primitive Types and Expressions
OPERATORS in C Programming
OPERATORS in C Programming
Chapter 12 Variables and Operators
Presentation transcript:

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

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

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 ‏ 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 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 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 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 Data Types 8 64 bitsdouble Data TypeSizeRange byte8 bits-256 to 255 short16 bits-32,768 to 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 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 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 Operations, Operators and Operands. 11 Ex: an arithmetic operation 10+5=15. operand operator Arithmetic Relational Logical Operation

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

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 Other Operators 14 Assignment Operators Assignment operators are used to assign the values of an expression to a variable. Ex: a=10;.

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 Other Operators… 16. Bitwise Operator These operators are used for testing the bits, or shifting them to the right or left.

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 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()

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: * 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

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 = / 2 could be considered in two ways, 1. a = 6 + ( 8 / 2 ) → with a result of a = ( ) / 2 → with a result of 7 Order Of Precedence

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

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.

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).

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).

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.

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.

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.

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; }

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.