2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Air Force Institute of Technology Electrical and Computer Engineering
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.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
VB .NET Programming Fundamentals
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Introduction to Computer Systems and the Java Programming Language.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Java operatoriai sandbolts/operators.html
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
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.
Java Programming The Language of Now & the Future* Lecture 0 An Introduction to Java Syntax for Non-C Programmers John Morris Department of Electrical.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Primitive Variables.
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.
Sahar Mosleh California State University San MarcosPage 1 Data Types and Operators.
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.
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
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
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.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Operator Kinds of Operator Precedence of Operator Type Casting.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
The Machine Model Memory
Chapter 7: Expressions and Assignment Statements
University of Central Florida COP 3330 Object Oriented Programming
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
University of Central Florida COP 3330 Object Oriented Programming
Chapter 7: Expressions and Assignment Statements
Fundamental of Java Programming Basics of Java Programming
Java operatoriai
Java Programming: From Problem Analysis to Program Design, 4e
Operators and Expressions
Lecture 5 from (Chapter 4, pages 73 to 96)
Operators Laboratory /11/16.
All the Operators 22-Nov-18.
More about Numerical Computation
All the Operators 4-Dec-18.
Chapter-3 Operators.
Introduction to Programming – 4 Operators
Chapter 3 Operators and Expressions
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Herbert G. Mayer, PSU CS Status 7/19/2015
OPERATORS in C Programming
OPERATORS in C Programming
Presentation transcript:

2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)

2015/8/22 2 Review An introduction to Object-oriented programming Arithmetic Operators Bitwise operators Relational Operators Boolean Logical Operator Assignment Operator

2015/8/22 3 An introduction to Object Oriented Programming - Object-oriented Programming is the core of Java. All java programms are object-oriented. We need to understand what an object is, what a class is, how objects and classes are related, and how objects communicate by using messages.

2015/8/22 4 An overview of Object-oriented programming (1) An object: An object is a software bundle of related variables and methods. Software objects are often used to model real-world objects you find in everyday life. Messages: Software objects interact and communicate with each other using messages. Class: A class is a prototype that defines the variables and the methods common to all objects of a certain kind.

2015/8/22 5 An overview of Object-oriented programming (2) An inherientence: A class inherits state and behavior from its superclass. Inheritance provides a powerful and natural mechanism for organizing and structuring software programs. An Interface: An interface is a contract in the form of a collection of method and constant declarations. When a class implements an interface, it promises to implement all of the methods declared in that interface.

2015/8/22 6 An object - We will introduce them one by one per week to build up your understanding There are many examples of real-world objects. For example, our book, cat, pet etc. These real-world objects share two characteristics, namely, : state and behavior. For example, cats have state (color, hungry) and behavior (running, eating, sleeping). Software objects are modeled following the real-world objects in that they too have state and behavior.  A software object maintains its state in one or more variables.variables  A variable is an item of data named by an identifier.  A software object implements its behavior with methods. A method is a function (subroutine) associated with an object.methods

7 Java Data Types Primitive Data Types:  boolean true or false  char unicode! (16 bits)  byte signed 8 bit integer  short signed 16 bit integer  int signed 32 bit integer  long signed 64 bit integer  float, double IEEE 754 floating point not an int!

2015/8/22 8 Arithmetic Operator – page 74 OperatorDescription +addition - Subtraction *Multiplication / Division % Modules ++Increment -- Decrement

2015/8/22 9 Example – addition and subtraction

2015/8/22 10 Example – multiplication and division

2015/8/22 11 Special operator ExpressionEquivalent expression a = a + 2;a +=2; a = a – 4;a -= 4; a = a*3; a *= 3; a = a/4;a /=4; a = a%2;a %=2;

2015/8/22 12 Example of special operator

2015/8/22 13 Increment and Decrement ExpressionEquivalent expression a = a + 1;++a; a = a – 1;--a;

2015/8/22 14 Bitwise Operators – page 81 OperatorDescription ~Bitwise unary NOT & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR >> Shift Right << Shift LEFT >>>Shift Right with zero fill

2015/8/22 15 Operation - examples OperatorExpression AND 1 & 1 = 1; 1& 0 = 0 OR 1 |1 = 1; 1| 0 = 1; 0|0 = 0 ~ 0 =~1; 1 =~0; ^ 0^ 0 = 0; 1^1 = 0; 1^0 =1; 0^1 = 1 >> 0x0010 = 0x0001 >>1 << 0x0001 = 0x0010 <<1 >>> 0x1001 = 0x0100 >>>1

2015/8/22 16 AND Example – bits, 0x (hexadecimal) (0xf2) (0xfe) (and) & (0xf2) byte c = 0xf2; byte d = 0xfe; byte e = c & d; //e is 0xf2

2015/8/22 17 OR Example (0xf2) (0xfe) (or) | (0xfe) Example byte c = 0xf2; byte d = 0xfe; byte e = c | d; //e is 0xfe

2015/8/22 18 One ’ s complement (0xf2) ~ (0x0d) Example byte c = 0xf2; byte e = ~c; //e is 0x0d

2015/8/22 19 EXCLUSIVE OR (0xf2) (0xfe) (^) (0x0c) Example byte c = 0xf2; byte d = 0xfe; byte e = c ^ d; //e is 0x0c

2015/8/22 20 Example

2015/8/22 21 Relational Operators OperatorDescription ==Equal to != Not equal to >Greater than < Less than >= Grater than or equal to <= Less than or equal to

2015/8/22 22 Example int a = 3; int b = 4; boolean c = (a>b); //c is false boolean d = (a<b); //c is true boolean e = (a==b); //c is false boolean d = (a>=b); //c is false

2015/8/22 23 Example

2015/8/22 24 SHIFT >> (right) by one bit (0xf2) >> 1 (shift right by one bit) (0x79) Example byte c = 0xf2; byte e = c >>1; //e is 0x79

2015/8/22 25 SHIFT >> by two bits (0xf2) >> 2 (shift right by one bit) (0x3c) Example byte c = 0xf2; byte e = c >>2; //e is 0x3c

2015/8/22 26 SHIFT << (left) by one bit (0xf2) << 1 (shift right by one bit) (0xe4) Example byte c = 0xf2; byte e = c <<1; //e is 0xe4

2015/8/22 27 SHIFT << by two bits (0xf2) >> 2 (shift right by one bit) (0xc8) Example byte c = 0xf2; byte e = c <<2; //e is 0xc8

2015/8/22 28 Results or bit operation (example) ( 1 | 2) == 3 (1 | 3) == 3 (1 & 2) == 0 (1 & 3) == 1 (0 ^ 3) == 3 (1 ^ 3) == 2 (3 ^ 3) == 0 ~0 == -1 (signed) or 255 (unsigned)

2015/8/22 29 Example of shift

2015/8/22 30 Relational Operators OperatorDescription ==Equal to != Not equal to >Greater than < Less than >= Grater than or equal to <= Less than or equal to

2015/8/22 31 Example int a = 3; int b = 4; boolean c = (a>b); //c is false boolean d = (a<b); //c is true boolean e = (a==b); //c is false boolean d = (a>=b); //c is false

2015/8/22 32 ? operator It is used to replace if-then-else statement Expression1 ? Expression2: Expression 3; If (expression1) is true, it will evaluate Expression 2, else Expression 3 int i = 3; int j = 4; int k; (i > j)? k = 10: k = 20; // (i > j) is false, k =20

2015/8/22 33 Summary Object-oriented Programming is the core of Java. Each object consists of states and behaviour. Arithmetic Operators -- +, - * /, ++, --, % Bitwise operators -- ~, ^, &, ^, >>, >> Relational operators -- ==, !=, >, =, <= Boolean Logical Operator -- &. |, !, &= ? Operator – Exp1? Exp2: Exp3