4.1 Object Operations. 4.1.1 operators Dot (. ) and new operate on objects The assignment operator ( = ) Arithmetic operators + - * / % Unary operators.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Chapter 5 Selection Statements. Topics Controlling program flow selection –if –switch Boolean expressions –boolean primitive type –comparison operators.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
Visual C++ Programming: Concepts and Projects
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Control Statements.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
1 Chapter 4 Simple Selections and Repetitions INTRODUCTION The majority of challenging and interesting algorithms necessitate the ability to make.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
CONTROL STATEMENTS IF-ELSE, SWITCH- CASE Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
Flow of Control Part 1: Selection
© 2000 Scott S Albert Selection Structures Structured Programming 256 Chapter 4.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
JAVA (something like C). Object Oriented Programming Process orientated – code acting on data Object oriented – data controls access to code Encapsulation.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 03 – Operators, Algorithm Design, Programming Constructs Richard Salomon.
Control statements Mostafa Abdallah
CONTROL STRUCTURE. 2 CHAPTER OBJECTIVES  Learn about control structures.  Examine relational and logical operators.  Explore how to form and evaluate.
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Lecture 3 Selection Statements
Operators and Expressions
Chapter 3: Decisions and Loops
Selections Java.
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Java Statements Java control structure is entrenched in statements:
Control Statements: Part 1
Multiple variables can be created in one declaration
Operator Precedence Operators Precedence Parentheses () unary
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
Introduction to MATLAB
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Chapter 7 Additional Control Structures
Computer Science Core Concepts
Chapter 4: Control Structures I (Selection)
Control Structure Chapter 3.
Chapter 2 Programming Basics.
Program Flow.
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Control Structure.
Presentation transcript:

4.1 Object Operations

4.1.1 operators Dot (. ) and new operate on objects The assignment operator ( = ) Arithmetic operators + - * / % Unary operators ++, --, *=, %= Operator precedence Arithmetic expressions are left associative Assignment operators are right associative

4.2.6 Boolean data and comparison operators boolean values are true or false ( not 1 or 0) Less than, equal to ==, less than or equal to =, not equal != AND &, OR |, XOR ^ Short curcuit AND &&, OR ||

4.2.8 Conditional operator Alternative for if - else y = x > 4 ? 99: 9; Is the same as: if(x > 4) y = 99; else y = 9;

4.2.9 Bitwise operators Perform shifting of bits on integral types, preferably int of long <<3 shifts all bits left 3 places. All new bits are 0 >>>3 shifts all bits right 3 places. All new bits are 0 >>3 shifts all bits right 3 places. The new bits are the same as the most significant bit before the shift.

4.3.1 Casting and conversion Casting assigns a value of one type to a variable of another type If it is possible to lose information, an explicit cast is required long bigValue = 99L; int squashed = (int)bigValue;

4.4.2 String and StringBuffer class The String object can be used to store an arbitrary number of textual characters Strings are immutable: They do not change Concatenating two Strings results in the creation of another String Use StringBuffer to hold Strings that will change

4.5.1 Decision making and repetition Control structures control the flow of statement execution Three control structures: Sequence, selection or decision, repetition In OOP, control structures exist within methods only Selection control structure provides conditional execution (if-else) Repitition control structure causes the computer to repeat certain actions (for, while, do )

4.5.3 If statement Basic if(x == 3) { System.out.println(“x equals 3”); } else { System.out.println(“x does not equal 3”); }

4.5.4 Multiple condition If Multiple condition if(a < b) { System.out.println(“a is less than b”); } else if (a < c) { System.out println(“a is less than c”); } else { System.out.println(“a is not less than b or c”); }

4.5.5 Nested if Nested If if(x == 3) { System.out.println(“x equals 3”); if( y == 4) { System.out.println(“ …and y equals 4”); } else { System.out.println(“x does not equal 3”); }

4.5.6 Switch statements A conditional control structure that allows a value to be compared to more than one other value switch(test) { case 1: System.out.println(“test equals 1”); break; case 2: System.out.println(“test equals 2”); break; case 3: System.out.println(“test equals 3”); break; default: System.out.println(“test does not equal 1, 2 or 3”); break; }

4.5.7 Loop do while: Execution loops. Conditional evaluation at the end of the loop while: Execution loops through the block. Conditional evaluation occurs at the start of the loop for next: Specifies an initialization block, a conditional evaluation and a block that is executed in every loop

Use of break, continue, and label break is used to exit a block continue is used to return to the start of the loop label can be applied to a statement or block, then used with continue or break break can be used to exit a labeled block continue can be used to resume at a statement

4.6.1 The java.lang.System class