2. Java Basics. Data Types презентация

Содержание


Презентации» Информатика» 2. Java Basics. Data Types
2. Java Basics
 1. Data TypesJava Data Types
 Primitive
 Boolean
 Numeric
 Integer
 Float-point
 CharBoolean Type
 Type boolean
 Two possible values: true, false
 Use thisBoolean Operators
 =      	assignment
 == !=If-Then-Else Boolean Operator
 expression1 ? expression2 : expression3
 
 
 Examples:
AND Boolean Operator
 1. boolean a = false;
 2. boolean bAND Boolean Operator
 1. boolean a = false;
 2. boolean bInteger TypesInteger Literals
 Decimal constant should start with nonzero digit
 Leading zeroInteger Arithmetic Operations
 +		add
 -		subtract
 *		multiply
 /		divide
 % 		get reminderInteger Addition
 byte a = 120;
 byte b = 10;
 byteInteger Arithmetic Operations
 If one operand has long type then otherInteger Assignment
 The integer assignment performs implicit type conversion if neitherJava Overflow And Underflow
 In Java arithmetic operators don’t report overflowThe Overflow Problem
 In Java arithmetic overflow will never throw anInteger Division
 x = a / b
 r = a %Integer Division
 Division by 0 leads to runtime ArithmeticException:
 			int aThe Integer Unary Operators
 +		Unary plus operator
 -		Unary minus operator
 ++		IncrementWhat will be a value?
 int x = 8;
 int aWhat will be done?
 int c = 10;
 int d =What will be done?
 int c = 10;
 int d =Bitwise Operators
 ~	inverts a bit 
 &	bitwise AND 
 |	bitwise OR
Bitwise Operators
 int a = 45;
 int b = 34;
 intBit Shift Operators
 <<		signed left shift operator 
 >>		signed right shiftBit Shift Operators
 int a = 45;
 int b = aInteger Assignment Operators
 =
 +=, -=, *=, /=
 <<=, >>=, >>>=
Integer Assignment Operators
 x += 1; instead x = x +The Equality and Relational Operators
 == 	equal to 
 != 		notFloat point Data Types
 float – 32 bit   Float point Arithmetic Operations
 +		add
 -		subtract
 *		multiply
 /		divideFloat point Arithmetic Operations
 If one operand has double type thenWhat will be c and d value?
 double a = 2.2;
Special Float Point Values
 -Infinity
 +Infinity
 NaN
 In previous code cPrecision Problem I
 double a = 2.0;
 double b = aPrecision Problem II
 How many repetitions will be?
 double d =Debugging in Eclipse
 Start debugging: press Debug icon and use F6Precision Problem Source
 Above precision problems caused by the 
 factFloat point Literals
 Here are possible formats for float point constants
The Float point Unary Operators
 +		Unary plus operator
 -		Unary minus operator
Float point Assignment Operators
 =
 +=, -=, *=, /=The Equality and Relational Operators
 == 	equal to 
 != 		notChar Type
 The char data type is a single 16-bit UnicodeChar Literals
 A symbol: 'a', 'A', '9', '+', '_', '~' (exceptChar Examples
 char c = 'g';
 System.out.println(++c);
 char r = (char)(cExpressions.  Operator precedence 
 .    []    () 
Casting (1 of 2)
 Any integer type can be casted toCasting (2 of 2)
 Char type casting is the same asCasting operators (1 of 2) 
 Implicit casting:
   Casting operators (2 of 2) 
 int b = 168;
 Manuals
 Learning the Java Language. Language Basics
 Thinking in Java. Operators.



Слайды и текст этой презентации
Слайд 1
Описание слайда:
2. Java Basics 1. Data Types


Слайд 2
Описание слайда:
Java Data Types Primitive Boolean Numeric Integer Float-point Char

Слайд 3
Описание слайда:
Boolean Type Type boolean Two possible values: true, false Use this data type for simple flags Not compatible with other types (integer!) Even explicit cast is impossible Its "size" isn't something that's precisely defined

Слайд 4
Описание слайда:
Boolean Operators = assignment == != equal to, not equal to ! NOT && AND || OR ?: if-then-else & bitwise AND | bitwise OR

Слайд 5
Описание слайда:
If-Then-Else Boolean Operator expression1 ? expression2 : expression3 Examples: BestReturn = Stocks > Bonds ? Stocks : Bonds; LowSales = JuneSales < JulySales ? JuneSales : JulySales; Distance = Site1 - Site2 > 0 ? Site1 - Site2 : Site2 - Site1;

Слайд 6
Описание слайда:
AND Boolean Operator 1. boolean a = false; 2. boolean b = true; 3. boolean c = a && b; 4. boolean d = a & b; Will we get the same results for c and d?

Слайд 7
Описание слайда:
AND Boolean Operator 1. boolean a = false; 2. boolean b = true; 3. boolean c = a && b; Operation && calculates first operand. If it equals false, then returns false without second operand calculation 4. boolean d = a & b; Operation & calculates both operands and then returns the result

Слайд 8
Описание слайда:
Integer Types

Слайд 9
Описание слайда:
Integer Literals Decimal constant should start with nonzero digit Leading zero means octal constant (so 8 and 9 digits are impossible) Leading 0x means hexadecimal constant (you can use A-F or a-f as digits) Long constant ends with L or l symbols. Any number of underscore characters (_) can appear anywhere between digits in a numerical constants (since Java 7 only!)

Слайд 10
Описание слайда:
Integer Arithmetic Operations + add - subtract * multiply / divide % get reminder

Слайд 11
Описание слайда:
Integer Addition byte a = 120; byte b = 10; byte c = (byte)(a + b); What will be c value? Why we use (byte)(a + b)?

Слайд 12
Описание слайда:
Integer Arithmetic Operations If one operand has long type then other operand is converted to long. Otherwise both operands are converted to int type. The result of an operation has int type if it value does not need long type.

Слайд 13
Описание слайда:
Integer Assignment The integer assignment performs implicit type conversion if neither accuracy nor value is loss (e.g. int = byte or long = int) If implicit cast is impossible then explicit cast is needed, otherwise compilation error will occur ( e.g byte = (byte)int )

Слайд 14
Описание слайда:
Java Overflow And Underflow In Java arithmetic operators don’t report overflow and underflow conditions When the result of an arithmetic integer operation is larger than 32 bits then the low 32 bits only taken into consideration and the high order bits are discarded The same with long type (64 bits) It’s a shame of Java

Слайд 15
Описание слайда:
The Overflow Problem In Java arithmetic overflow will never throw an exception long a = 9223372036854775806L; long b = 2L; long c = a + b; c = -9223372036854775808L

Слайд 16
Описание слайда:
Integer Division x = a / b r = a % b int a = 20; int b = 3; int c = a / b; int d = a % b; What will be c and d values?

Слайд 17
Описание слайда:
Integer Division Division by 0 leads to runtime ArithmeticException: int a = 5; int b = 0; int c = a / b;

Слайд 18
Описание слайда:
The Integer Unary Operators + Unary plus operator - Unary minus operator ++ Increment operator -- Decrement operator For pre-increment and pre-decrement (i.e., ++a or --a), the operation is performed and the value is produced. For post-increment and post-decrement (i.e., a++ or a--), the value is produced, then the operation is performed.

Слайд 19
Описание слайда:
What will be a value? int x = 8; int a = x++ / x;

Слайд 20
Описание слайда:
What will be done? int c = 10; int d = c+++++c;

Слайд 21
Описание слайда:
What will be done? int c = 10; int d = c++ + ++c;

Слайд 22
Описание слайда:
Bitwise Operators ~ inverts a bit & bitwise AND | bitwise OR ^ bitwise inclusive OR

Слайд 23
Описание слайда:
Bitwise Operators int a = 45; int b = 34; int c = a ^ b; What will be c value? int d = c ^ b; What will be d value?

Слайд 24
Описание слайда:
Bit Shift Operators << signed left shift operator >> signed right shift operator >>> right shift operator

Слайд 25
Описание слайда:
Bit Shift Operators int a = 45; int b = a >> 3; b = ? int c = a << 3; c = ?

Слайд 26
Описание слайда:
Integer Assignment Operators = +=, -=, *=, /= <<=, >>=, >>>= &=, |=, ^=

Слайд 27
Описание слайда:
Integer Assignment Operators x += 1; instead x = x + 1; a *= 5; instead a = a * 5;

Слайд 28
Описание слайда:
The Equality and Relational Operators == equal to != not equal to > greater than >= greater than or equal to < less than <= less than or equal to

Слайд 29
Описание слайда:
Float point Data Types float – 32 bit (± 1E38, 7-8 dec. precision) double – 64 bit (± 1E308, 16-17 dec. precision) Accordingly IEEE 754-1985 standard

Слайд 30
Описание слайда:
Float point Arithmetic Operations + add - subtract * multiply / divide

Слайд 31
Описание слайда:
Float point Arithmetic Operations If one operand has double type then other operand is converted to double and result will be double type. If one operand has float type and other operand has any type differs from double then other operand is converted to float and result will be float type

Слайд 32
Описание слайда:
What will be c and d value? double a = 2.2; double b = -1.4; a = a - 2.2; double c = b / a; double d = Math.sqrt(b);

Слайд 33
Описание слайда:
Special Float Point Values -Infinity +Infinity NaN In previous code c = -Infinity, d = NaN

Слайд 34
Описание слайда:
Precision Problem I double a = 2.0; double b = a - 1.1; b will be 0.8999999999999999, not 0.9!

Слайд 35
Описание слайда:
Precision Problem II How many repetitions will be? double d = 0.1; while (d != 1.0) { System.out.println(d); d += 0.1; }

Слайд 36
Описание слайда:
Debugging in Eclipse Start debugging: press Debug icon and use F6 key for stepped debugging Use Cntr + Shift + B for breakpoint creation Use Cntr + R to run application to the next breakpoint

Слайд 37
Описание слайда:
Precision Problem Source Above precision problems caused by the fact that finite decimal fraction 0.1 is infinite periodical binary fraction: So 0.1 can be represented as binary fraction in a computer only approximately.

Слайд 38
Описание слайда:
Float point Literals Here are possible formats for float point constants 1003.45 .00100345e6 100.345E+1 100345e-2 1.00345e3 0.00100345e+6

Слайд 39
Описание слайда:
The Float point Unary Operators + Unary plus operator - Unary minus operator ++ Increment operator -- Decrement operator

Слайд 40
Описание слайда:
Float point Assignment Operators = +=, -=, *=, /=

Слайд 41
Описание слайда:
The Equality and Relational Operators == equal to != not equal to > greater than >= greater than or equal to < less than <= less than or equal to

Слайд 42
Описание слайда:
Char Type The char data type is a single 16-bit Unicode character Char data can be processed as unsigned short integers (0 – 65535) too.

Слайд 43
Описание слайда:
Char Literals A symbol: 'a', 'A', '9', '+', '_', '~' (except \) Unicode symbol: '\u0108' Escape sequences '\b' '\t' '\n' '\f' '\r' '\"' '\'' '\\' Don’t confuse char and string literals (e.g. ‘r’ and “r”)! The \uxxxx notation can be used anywhere in the source to represent unicode characters

Слайд 44
Описание слайда:
Char Examples char c = 'g'; System.out.println(++c); char r = (char)(c ^ 32);

Слайд 45
Описание слайда:
Expressions. Operator precedence .    []    () +    -    ~    !    ++    --    instanceof *    /    % +    - <<    >>    >>> <    <=    >=    > ==    !=

Слайд 46
Описание слайда:
Casting (1 of 2) Any integer type can be casted to any other primitive type except boolean Casting from larger integer type to smaller (from long to short for example) can lead to data loss Casting from integer type to float point type can lead to precision loss (if integer is not power of 2)

Слайд 47
Описание слайда:
Casting (2 of 2) Char type casting is the same as short integer type casting. Casting from float or double types to integer types returns integer part of the value without rounding

Слайд 48
Описание слайда:
Casting operators (1 of 2) Implicit casting: byte b = 18; int a = b; Explicit casting: int a = 18; byte b = (byte)a;

Слайд 49
Описание слайда:
Casting operators (2 of 2) int b = 168; double a = b; float p = 18.94f; byte b = (byte)p; // b = 18

Слайд 50
Описание слайда:
Manuals Learning the Java Language. Language Basics Thinking in Java. Operators.


Скачать презентацию на тему 2. Java Basics. Data Types можно ниже:

Похожие презентации