University of Central Florida COP 3330 Object Oriented Programming

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

LECTURE 3: BASIC C OPERATORS. Objectives  In this chapter, you will learn about:  Arithmetic operators Unary operators Binary operators  Assignment.
Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Chapter 4: Basic C Operators
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
2440: 211 Interactive Web Programming Expressions & Operators.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
C Operators. CONTENTS CONDITIONAL OPERATOR SIMPLE ASSIGNMENT OPERATOR COMPOUND ASSIGNMENT OPERATOR BITWISE OPERATOR OPERATOR PRECEDENCE.
Java operatoriai sandbolts/operators.html
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Pemrograman Dasar Operators, Expressions & Statements PTIIK - UB 1.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Principles of Programming Chapter 4: Basic C Operators  In this chapter, you will learn about:  Arithmetic operators  Unary operators  Binary operators.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Operators & Expressions
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 4: Basic C Operators.
OperatorstMyn1 Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Programming Principles Operators and Expressions.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Operators & Expressions
CompSci 230 S Programming Techniques
CSE 220 – C Programming Expressions.
Chapter 7: Expressions and Assignment Statements
Lecture 3 Java Operators.
Operators And Expressions
Chap. 2. Types, Operators, and Expressions
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
Selections Java.
Lecture 2: Data Types, Variables, Operators, and Expressions
University of Central Florida COP 3330 Object Oriented Programming
Chapter 7: Expressions and Assignment Statements
Variable Declaration, Data types, Expressions
Precedence and Associativity
Java operatoriai
Operators and Expressions
Operators and Expressions
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
All the Operators 22-Nov-18.
All the Operators 4-Dec-18.
C Operators, Operands, Expressions & Statements
Chapter-3 Operators.
Associativity and Prescedence
Introduction to Programming – 4 Operators
Expressions.
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Chapter 4: Expression and Operator
C++ Programming Language Lecture 4 C++ Basics – Part II
OPERATORS AND EXPRESSIONS IN C++
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
Operator King Saud University
OPERATORS in C Programming
Presentation transcript:

University of Central Florida COP 3330 Object Oriented Programming

Agenda Operators

Operators

Operators  Operators are special symbols that perform specific operations on one, two, or three operands, and return a result Operators precedence Operators with higher precedence are evaluated before operators with relatively lower precedence Operators of equal precedence in the same expression are evaluated Binary operators except for the assignment operators are evaluated from left to right Assignment operators are evaluated right to left

Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=

Operators Assignment Operator =  Assigns the value on its right to the variable on the left The variable result stores the addition of 1 + 2

Operators Outputting to the console or screen use methods: System.out.print() No line break System.out.println() Includes line break

Operators Arithmetic Operator Perform addition, subtraction, multiplication, division, and modulus (i.e. "%", divides one operand by another and returns the remainder as the result) Operator Description + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator

Operators Arithmetic Operator addition subtraction multiplication division modulus

Operators Compound Assignments Combine the arithmetic operators with assignment operator Example x+=1; and x=x+1; both increment the value of x by 1

Operators The + operator also be used for concatenating (joining) two strings together or other data

Operators Unary Operators Operator Description + Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean

Operators Unary Operators require only one operand perform various operations incrementing/decrementing a value by one negating an expression inverting the value of a boolean

Operators Prefix and Postfix Prefix = increment/decrement operators applied before the operand Postfix = increment/decrement operators applied after the operand. Code result++; and ++result; will both end in result being incremented by one Difference prefix ++result evaluates to the incremented value postfix result++ evaluates to the original value performing a simple increment/decrement doesn't matter which version is used if this operator is part of a larger expression, the selected implementation may make a significant difference.

Operators Prefix and Postfix For the most part programmers will not notice a difference in behavior of prefix and postfix In the example to the right it would be noticeable where the prefix and postfix are passed as arguments to the println() method The printing is one independent action The incrementing is a second independent action

Operators Equality and Relational equality and relational operators determine if one operand is greater than, less than, equal to, or not equal to another operand == equal to != not equal to

Operators Equality and Relational > greater than >= greater than or equal to < less than <= less than or equal to

Operators Conditional && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions these operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed Ternary operator ?: shorthand for an if-then-else statement ternary operator because it uses three operands

Operators Conditional

Operators Conditional Ternary operator ?: Read as If the result of the condition (result1 == JOptionPane.YES_OPTION) is true then the result the behavior coded in between the ? and the : is executed If the result of the condition (result1 == JOptionPane.YES_OPTION) is false then the result the behavior coded in between the : and the ; is executed

Logical Operators && (AND) Expression on the left of the && is true (nonzero) AND Expression on the right of the && is true (nonzero) Truth table Expression 1 Expression 2 Expression 1 && Expression 2 false true

Logical Operators || (OR) OR Expression on the left of the || is true (nonzero) OR Expression on the right of the || is true (nonzero) Truth table Expression 1 Expression 2 Expression 1 && Expression 2 false False true True

Logical Operators ! (NOT) Logical negation, logical complement Reverses the evaluation of the condition Truth table Expression !Expression false True true False

Operators instanceof instanceof operator compares an object to a specified type use to test if an object is an instance of a class an instance of a subclass an instance of a class that implements a particular interface

Operators Using an inner class In the outer class create instances of the inner classes This declaration is in the main() method of class Operators

Operators Defining an inner class In object oriented programming classes can contain inner classes, classes that are defined within a class Are private to the class they are defined in

Operators Checking instanceof Using the instanceof operator each object is checked

Operators Checking instanceof obj1 is an instanceof inner class Parent because the statement called the Parent() constructor Parent obj1 = new Parent(); obj1 is NOT an instanceof inner class Child because the statement did not call the Child() constructor obj1 is NOT an instanceof inner interface MyInterface because the class Parent did not implement the interface MyInterface

Operators Checking instanceof obj2 is an instanceof inner class Parent because class Child extended class Parent Parent obj1 = new Parent(); obj2 is an instanceof inner class Child because the statement called the Child() constructor obj2 is an instanceof inner interface MyInterface because the class Child implemented the interface MyInterface