🗊Презентация Data Types and Operators (Java, Lecture 04)

Нажмите для полного просмотра!
Data Types and Operators (Java, Lecture 04), слайд №1Data Types and Operators (Java, Lecture 04), слайд №2Data Types and Operators (Java, Lecture 04), слайд №3Data Types and Operators (Java, Lecture 04), слайд №4Data Types and Operators (Java, Lecture 04), слайд №5Data Types and Operators (Java, Lecture 04), слайд №6Data Types and Operators (Java, Lecture 04), слайд №7Data Types and Operators (Java, Lecture 04), слайд №8Data Types and Operators (Java, Lecture 04), слайд №9Data Types and Operators (Java, Lecture 04), слайд №10Data Types and Operators (Java, Lecture 04), слайд №11Data Types and Operators (Java, Lecture 04), слайд №12Data Types and Operators (Java, Lecture 04), слайд №13Data Types and Operators (Java, Lecture 04), слайд №14Data Types and Operators (Java, Lecture 04), слайд №15Data Types and Operators (Java, Lecture 04), слайд №16Data Types and Operators (Java, Lecture 04), слайд №17Data Types and Operators (Java, Lecture 04), слайд №18Data Types and Operators (Java, Lecture 04), слайд №19Data Types and Operators (Java, Lecture 04), слайд №20Data Types and Operators (Java, Lecture 04), слайд №21Data Types and Operators (Java, Lecture 04), слайд №22Data Types and Operators (Java, Lecture 04), слайд №23Data Types and Operators (Java, Lecture 04), слайд №24Data Types and Operators (Java, Lecture 04), слайд №25Data Types and Operators (Java, Lecture 04), слайд №26Data Types and Operators (Java, Lecture 04), слайд №27Data Types and Operators (Java, Lecture 04), слайд №28Data Types and Operators (Java, Lecture 04), слайд №29Data Types and Operators (Java, Lecture 04), слайд №30Data Types and Operators (Java, Lecture 04), слайд №31Data Types and Operators (Java, Lecture 04), слайд №32Data Types and Operators (Java, Lecture 04), слайд №33Data Types and Operators (Java, Lecture 04), слайд №34Data Types and Operators (Java, Lecture 04), слайд №35Data Types and Operators (Java, Lecture 04), слайд №36Data Types and Operators (Java, Lecture 04), слайд №37Data Types and Operators (Java, Lecture 04), слайд №38

Содержание

Вы можете ознакомиться и скачать презентацию на тему Data Types and Operators (Java, Lecture 04). Доклад-сообщение содержит 38 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1






MODULE 1-05: Compact Course Programming
Lesson 4 
- Data Types and Operators -
Описание слайда:
MODULE 1-05: Compact Course Programming Lesson 4 - Data Types and Operators -

Слайд 2





Content
Simple Data Types, their Values and Operators 
Expressions
Type Conversions
Описание слайда:
Content Simple Data Types, their Values and Operators Expressions Type Conversions

Слайд 3





Try out / Answer: Overflow and Precision
Go to the following link to check your answer:
Описание слайда:
Try out / Answer: Overflow and Precision Go to the following link to check your answer:

Слайд 4





Simple Data Types, their Values and Operators
Simple Data Types in Java
Описание слайда:
Simple Data Types, their Values and Operators Simple Data Types in Java

Слайд 5





Simple Data Types, their Values and Operators 
Simple Data Types in Java
In difference to some other programming languages, all simple data types in Java have an agreed fixed size in memory
For every simple data type a default value is defined, which is of importance with the initialisation of object and class variables (note: local variables are not automatically initialised with the default value)
Описание слайда:
Simple Data Types, their Values and Operators Simple Data Types in Java In difference to some other programming languages, all simple data types in Java have an agreed fixed size in memory For every simple data type a default value is defined, which is of importance with the initialisation of object and class variables (note: local variables are not automatically initialised with the default value)

Слайд 6





Simple Data Types, their Values and Operators
Operators
Are special symbols that are used to link operands to determine a new value
According to their number of operands we can distinguish three types of operators
Single digit (monadic oder unary) operators
  example: the negative sign -
Two digit (dyadic oder binary) operators                       
  example: the addition sign +
Three digit (triadic oder ternary) operatores  
   example: conditional operator ? :
Описание слайда:
Simple Data Types, their Values and Operators Operators Are special symbols that are used to link operands to determine a new value According to their number of operands we can distinguish three types of operators Single digit (monadic oder unary) operators example: the negative sign - Two digit (dyadic oder binary) operators example: the addition sign + Three digit (triadic oder ternary) operatores example: conditional operator ? :

Слайд 7





Simple Data Types, their Values and Operators
Logic Values (boolean)
Unary Operator (Operator Operand)
	Operator	Description
	!       	logische Negation
Binary Operator (Operand1 Operator Operand2)
	Operator	Description	            Example
	==	Equality		            false == true   results in false
	!=	Inequality	            false != true  results in true
	&	logic AND
	|	logic OR
	^	logic XOR
Описание слайда:
Simple Data Types, their Values and Operators Logic Values (boolean) Unary Operator (Operator Operand) Operator Description ! logische Negation Binary Operator (Operand1 Operator Operand2) Operator Description Example == Equality false == true  results in false != Inequality false != true  results in true & logic AND | logic OR ^ logic XOR

Слайд 8





Simple Data Types, their Values and Operators
Logic Value (boolean)
Notation
Properties of the Operators (truth table)
Описание слайда:
Simple Data Types, their Values and Operators Logic Value (boolean) Notation Properties of the Operators (truth table)

Слайд 9





Simple Data Types, their Values and Operators
Truth Table (boolean)
Boolean Expressions with & and | evaluate both terms completely
In practise complete evaluation is often not required
& - operation: is one expression false, then the overall result is false 
| - operation: is one expression true, then the overall result is true
The operators && and || ensure a shortened evaluation
Example
int m = 3; 
int n = 5;
boolean b = (m < 5) || (n > 3); 
The shortened evaluation is important to reduce the computation time for example with large arrays
Описание слайда:
Simple Data Types, their Values and Operators Truth Table (boolean) Boolean Expressions with & and | evaluate both terms completely In practise complete evaluation is often not required & - operation: is one expression false, then the overall result is false | - operation: is one expression true, then the overall result is true The operators && and || ensure a shortened evaluation Example int m = 3; int n = 5; boolean b = (m < 5) || (n > 3); The shortened evaluation is important to reduce the computation time for example with large arrays

Слайд 10





Try out / Answer: use boolean operators!
What is the value of the following expressions?
 (true & true) | false
 !!true
 true & !true 
 (true || false) && true
Описание слайда:
Try out / Answer: use boolean operators! What is the value of the following expressions? (true & true) | false !!true true & !true (true || false) && true

Слайд 11





Simple Data Types, their Values and Operators
Binary Operators (char, byte, short, int, long)
	Operator	Description		Example
	+	Addition			5 + 6    	yields	11
	-	Subtraction		9 - 3     	yields	6
	*	Multiplication		10 * 15 	yields	150
	/	Whole Number Division	13 / 3   	yields 	4
	%	Modulo (remainder of     20 % 7 	yields 	6
                              a whole number division)
 	<	smaller			3 < 5    	yields 	true
	<=	smaller equal		3 <= 3  	yields	true
	>	bigger			2 > 10  	yields 	false
	>= 	bigger equal		5 >= 6  	yields	false
	==	equal		           	3 == 3  	yields 	true
	!=	not equal		5 != 5 	yields 	false
Описание слайда:
Simple Data Types, their Values and Operators Binary Operators (char, byte, short, int, long) Operator Description Example + Addition 5 + 6 yields 11 - Subtraction 9 - 3 yields 6 * Multiplication 10 * 15 yields 150 / Whole Number Division 13 / 3 yields 4 % Modulo (remainder of 20 % 7 yields 6 a whole number division) < smaller 3 < 5 yields true <= smaller equal 3 <= 3 yields true > bigger 2 > 10 yields false >= bigger equal 5 >= 6 yields false == equal 3 == 3 yields true != not equal 5 != 5 yields false

Слайд 12





Try out / Answer: use boolean operators!
What is the value of the following expressions?
7 / 5
7 % 5
5 / 7
5 % 7
Описание слайда:
Try out / Answer: use boolean operators! What is the value of the following expressions? 7 / 5 7 % 5 5 / 7 5 % 7

Слайд 13





Simple Data Types, their Values and Operators
Unary Operators (char, byte, short, int, long)
	Operator	Description		Example
	-		Unary Negation		-i 
	++		Increment		++i  is the same as  i = i+1
	--		Decrement		--i  is the same as  i = i-1
Note the difference: Pre-increment vs. Post-increment
a = ++b;		// is the same as:
               // b = b+1; a = b;
a = b++; 	// is the same as:
               // a = b; b = b+1;
Описание слайда:
Simple Data Types, their Values and Operators Unary Operators (char, byte, short, int, long) Operator Description Example - Unary Negation -i ++ Increment ++i is the same as i = i+1 -- Decrement --i is the same as i = i-1 Note the difference: Pre-increment vs. Post-increment a = ++b; // is the same as: // b = b+1; a = b; a = b++; // is the same as: // a = b; b = b+1;

Слайд 14





Simple Data Types, their Values and Operators
Bitwise - Operators (char, byte, short, int, long)
Access to binary representation of whole number data types
Numbers are viewed as a set of consecutive bits, which may be manipulated
Unary Operator (Operator Operand)
	Operator		Description				
	~ 		Complement (bitwise negation)
Binary Operators (Operand1 Operator Operand2)
	Operator		Description				
	& 		bitwise AND
	|			bitwise OR
	^			bitwise XOR
 The operators >>, >>> and << are used to shift the bits to the right or the left
Описание слайда:
Simple Data Types, their Values and Operators Bitwise - Operators (char, byte, short, int, long) Access to binary representation of whole number data types Numbers are viewed as a set of consecutive bits, which may be manipulated Unary Operator (Operator Operand) Operator Description ~ Complement (bitwise negation) Binary Operators (Operand1 Operator Operand2) Operator Description & bitwise AND | bitwise OR ^ bitwise XOR  The operators >>, >>> and << are used to shift the bits to the right or the left

Слайд 15





Simple Data Types, their Values and Operators
Bitwise - Operators (char, byte, short, int, long)
Example for shift operator
Left-Shift-Operator <<
int a;
a = 10;   	00000000 00000000 00000000 00001010
a << 3; 	00000000 00000000 00000000 01010000
	
int a;
a = -10;	11111111 11111111 11111111 11110110
a << 3; 	11111111 11111111 11111111 10110000	
 Equivalent to: whole-number multiplication with 23
Описание слайда:
Simple Data Types, their Values and Operators Bitwise - Operators (char, byte, short, int, long) Example for shift operator Left-Shift-Operator << int a; a = 10; 00000000 00000000 00000000 00001010 a << 3; 00000000 00000000 00000000 01010000 int a; a = -10; 11111111 11111111 11111111 11110110 a << 3; 11111111 11111111 11111111 10110000  Equivalent to: whole-number multiplication with 23

Слайд 16





Simple Data Types, their Values and Operators
Floating-Point-Numbers (float, double)
Unary Operators (analog to whole-number types)
	-		++	-- 
Binary Operators (analog to whole-number types)
+ - * / % (arithmetic operators)
<   <=   >   >=   ==   != (comparison operators)
Note:
whole-number division: 	45 / 20 		Result: 2
floating-point division:     	45.0 / 20.0	Result: 2.25
Описание слайда:
Simple Data Types, their Values and Operators Floating-Point-Numbers (float, double) Unary Operators (analog to whole-number types) - ++ -- Binary Operators (analog to whole-number types) + - * / % (arithmetic operators) < <= > >= == != (comparison operators) Note: whole-number division: 45 / 20 Result: 2 floating-point division: 45.0 / 20.0 Result: 2.25

Слайд 17





Simple Data Types, their Values and Operators
Floating-Point-Numbers (float, double)
Arithmetic Operators
Both operands of type float
Result type float
In all other cases 
Result type double
Attention with equality checks
(x == y)   // possible rounding errors !
Описание слайда:
Simple Data Types, their Values and Operators Floating-Point-Numbers (float, double) Arithmetic Operators Both operands of type float Result type float In all other cases Result type double Attention with equality checks (x == y) // possible rounding errors !

Слайд 18





Simple Data Types, their Values and Operators
Composite Operators
E1 op= E2    is the same as    E1 = E1 op (E2)
Example
	counter = counter + 1;	
// abbreviated: counter += 1;
	counter = counter – 1;	
// abbreviated: counter –= 1;
analog: *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>=
Описание слайда:
Simple Data Types, their Values and Operators Composite Operators E1 op= E2 is the same as E1 = E1 op (E2) Example counter = counter + 1; // abbreviated: counter += 1; counter = counter – 1; // abbreviated: counter –= 1; analog: *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>=

Слайд 19





Content
Simple Data Types, their Values and Operators 
Expressions
Type Conversions
Описание слайда:
Content Simple Data Types, their Values and Operators Expressions Type Conversions

Слайд 20





Expressions
Expressions: Definition and Features
Expression: Processing specification, that delivers a value after execution
In the simplest case a variable or a constant
Through combination of operands, operations and round brackets we get complex expressions
Examples
radius = 5.5;
area = PI * radius * radius;
counter = counter + 1;
Описание слайда:
Expressions Expressions: Definition and Features Expression: Processing specification, that delivers a value after execution In the simplest case a variable or a constant Through combination of operands, operations and round brackets we get complex expressions Examples radius = 5.5; area = PI * radius * radius; counter = counter + 1;

Слайд 21





Expressions
Brackets
The evaluation of expressions in brackets always takes place first
Just like the rules in mathematics 
Expressions may be arbitrarily nested
Notation of the nested structure is done with round brackets
All expressions are provided in linear notation
 Expression are provided in line format
Описание слайда:
Expressions Brackets The evaluation of expressions in brackets always takes place first Just like the rules in mathematics Expressions may be arbitrarily nested Notation of the nested structure is done with round brackets All expressions are provided in linear notation  Expression are provided in line format

Слайд 22





Expressions
Example
	Mathematic format 		Line format
Описание слайда:
Expressions Example Mathematic format Line format

Слайд 23





Expressions
Operator Priority Rules
Well-known from mathematics:
„Point before Line“
example 6 + 7 * 3 equals 27 and not 39
In Java:
Linking of operators is governed by priorities:
An operator with high priority links stronger than an operator with a lower priority
If the priority is the same than then the associativity of the operators is evaluated  
op is is left associative: X op Y op Z equals (X op Y) op Z
op ist right associative: X op Y op Z equals X op (Y op Z)
Obviously, brackets do control the evaluation order
example (6 + 7) * 3 ist 39
Описание слайда:
Expressions Operator Priority Rules Well-known from mathematics: „Point before Line“ example 6 + 7 * 3 equals 27 and not 39 In Java: Linking of operators is governed by priorities: An operator with high priority links stronger than an operator with a lower priority If the priority is the same than then the associativity of the operators is evaluated op is is left associative: X op Y op Z equals (X op Y) op Z op ist right associative: X op Y op Z equals X op (Y op Z) Obviously, brackets do control the evaluation order example (6 + 7) * 3 ist 39

Слайд 24





Expressions
Priority and Associativity
Описание слайда:
Expressions Priority and Associativity

Слайд 25





Expressions
Priority and Associativity
Описание слайда:
Expressions Priority and Associativity

Слайд 26





Try out / Answer: use priority and associativity!
For the following expressions, set brackets such that they yield the same result as the expressions without brackets
1. e = --c - d / a;
2. f = b <= a || c > 16;
3. h = a < 5 || b > 10 && d - c >= 0;
Описание слайда:
Try out / Answer: use priority and associativity! For the following expressions, set brackets such that they yield the same result as the expressions without brackets 1. e = --c - d / a; 2. f = b <= a || c > 16; 3. h = a < 5 || b > 10 && d - c >= 0;

Слайд 27





Expressions
Mathematical Constants and Functions
The class Math provides important mathematical constants and functions (see online documentation)

Constants
public static final double E	(basis e of nat. logarithm)
public static final double PI           	()
Usage: Math.E and  Math.PI	

Methods (Selection)
public static double abs(double x)			|x|
public static double cos(double x)			cos(x)
public static double sin(double x)			sin(x)
public static double tan(double x)			tan(x)
public static double sqrt(double x)		√x
public static double exp(double x)			ex
public static double pow(double x, double y)	xy
Usage: for example result = Math.pow(a,b);
Описание слайда:
Expressions Mathematical Constants and Functions The class Math provides important mathematical constants and functions (see online documentation) Constants public static final double E (basis e of nat. logarithm) public static final double PI () Usage: Math.E and Math.PI Methods (Selection) public static double abs(double x) |x| public static double cos(double x) cos(x) public static double sin(double x) sin(x) public static double tan(double x) tan(x) public static double sqrt(double x) √x public static double exp(double x) ex public static double pow(double x, double y) xy Usage: for example result = Math.pow(a,b);

Слайд 28





Definition of Constants
Constants in Java
Constants are defined and initialised like variables with the keyword „final“
their names are typically written in capital letters
they can not be changed
Example:
Statement and definition of constants:
Statement rewritten with constants:
              red = Math.min(red + ADDED_RED, MAX_RED)
Описание слайда:
Definition of Constants Constants in Java Constants are defined and initialised like variables with the keyword „final“ their names are typically written in capital letters they can not be changed Example: Statement and definition of constants: Statement rewritten with constants: red = Math.min(red + ADDED_RED, MAX_RED)

Слайд 29





Content
Simple Data Types, their Values and Operators 
Expressions
Type Conversions
Описание слайда:
Content Simple Data Types, their Values and Operators Expressions Type Conversions

Слайд 30





Type Conversion
Type Conflict
Values can only be assigned to variables, 
if their type is compatible with the type of the variable! 
Example
int a; 
float b = 10.5f;
a = b;  // Error because of incompatible types
Описание слайда:
Type Conversion Type Conflict Values can only be assigned to variables, if their type is compatible with the type of the variable! Example int a; float b = 10.5f; a = b; // Error because of incompatible types

Слайд 31





Type Conversion
Automatic (implicit) type extension
Rules
An automatic type extension is happening in the direction of the arrows
Example
double a, b;
float c;
a = b + c + 2.785f;
Описание слайда:
Type Conversion Automatic (implicit) type extension Rules An automatic type extension is happening in the direction of the arrows Example double a, b; float c; a = b + c + 2.785f;

Слайд 32





Type Conversion
Type extension and selection of operators in expressions
Each expression is evaluated step by step according to the priorities and associativity of its operators
The operators choosen are the operators that fit to the type of the operands
(example: whole number division OR division for floating point numbers)
Are the types of operands different, than the „smaller“ operand will receive an automatic type conversion
Are both operands of an operation, expressions themselves, then the left operand is calculated before the right operand
Описание слайда:
Type Conversion Type extension and selection of operators in expressions Each expression is evaluated step by step according to the priorities and associativity of its operators The operators choosen are the operators that fit to the type of the operands (example: whole number division OR division for floating point numbers) Are the types of operands different, than the „smaller“ operand will receive an automatic type conversion Are both operands of an operation, expressions themselves, then the left operand is calculated before the right operand

Слайд 33





Type Conversion
Type Extension and Selection of Operators in Expressions
Example

double a;
int b, c;
a = 3.0 + 2.785f + b / c;
Evaluation: Addition from left to right, point before line

 

a = ((3.0 + 2.785f)      +      (b / c));
Описание слайда:
Type Conversion Type Extension and Selection of Operators in Expressions Example double a; int b, c; a = 3.0 + 2.785f + b / c; Evaluation: Addition from left to right, point before line a = ((3.0 + 2.785f) + (b / c));

Слайд 34





Type Conversion
Explicit Type Conversion: Type Casting
Explicit type conversion happens when the desired type is explicitly requested
Example
	int a; 
float b = 10.25f;
	a = (int) b;
	float-value 10.25f is converted in the int-value 10
	a = (int)(b / 3.3f + 5.73f);
Note: Type casting takes place AFTER the calculation of the entire term 
b / 3.3f + 5.73f
Описание слайда:
Type Conversion Explicit Type Conversion: Type Casting Explicit type conversion happens when the desired type is explicitly requested Example int a; float b = 10.25f; a = (int) b; float-value 10.25f is converted in the int-value 10 a = (int)(b / 3.3f + 5.73f); Note: Type casting takes place AFTER the calculation of the entire term b / 3.3f + 5.73f

Слайд 35





Reading Input from the Console
Example code to read an integer and a double from the keyboard:
 Remember to import the utilisation class „Scanner“
Описание слайда:
Reading Input from the Console Example code to read an integer and a double from the keyboard:  Remember to import the utilisation class „Scanner“

Слайд 36





Formatted Output
Example code to print a number in a specific format:
Описание слайда:
Formatted Output Example code to print a number in a specific format:

Слайд 37





Try out / Answer: Overflow and Precision
Go to the following link to check your answer:
Описание слайда:
Try out / Answer: Overflow and Precision Go to the following link to check your answer:

Слайд 38





Homework Assignment 04 (2 Bonus Points)
(Assignment submission date provided in „Ilias … Homework Assignments“
Описание слайда:
Homework Assignment 04 (2 Bonus Points) (Assignment submission date provided in „Ilias … Homework Assignments“



Похожие презентации
Mypresentation.ru
Загрузить презентацию