1 / 15

2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE

2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE . 2.3 Use operator to modify values. FP301 OBJECT ORIENTED PROGRAMMING. Learning Outcome Subtopic 2.3. FP301 OBJECT ORIENTED PROGRAMMING. STANDARD MATHEMATICALS OPERATORS. FP301 OBJECT ORIENTED PROGRAMMING. Cont.

truda
Télécharger la présentation

2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE 2.3 Use operator to modify values.

  2. FP301 OBJECT ORIENTED PROGRAMMING Learning Outcome Subtopic 2.3

  3. FP301 OBJECT ORIENTED PROGRAMMING STANDARD MATHEMATICALS OPERATORS

  4. FP301 OBJECT ORIENTED PROGRAMMING Cont..

  5. FP301 OBJECT ORIENTED PROGRAMMING INCREMENT AND DECREMENT OPERATORS ( ++ and -- ) • The long way : age = age + 1; • The short way :

  6. FP301 OBJECT ORIENTED PROGRAMMING Cont..

  7. FP301 OBJECT ORIENTED PROGRAMMING LOGICAL OPERATORS • The boolean operators are: ! : NOT & : AND | : OR ^ : XOR • The short-circuit boolean operators are: && : AND || : OR • You can use these operators as follows: MyDated = reservation.getDepartureDate(); if ( (d != null) && (d.day > 31) { // do something with d }

  8. FP301 OBJECT ORIENTED PROGRAMMING BITWISE LOGICAL OPERATORS • The integer bitwise operators are: • ~ : Complement (vice versa) • & : AND (only true will become true) • ^ : XOR (x+y) % 2 • | : OR (only false will become false) • • Byte-sized examples include: 1 1 0 1 1 0 0 1 ~ 0 1 0 0 1 0 1 1 1 1 & 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 | 1 1 0 0 1 1 1 1 1 1 ^ 0 0 0 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0

  9. FP301 OBJECT ORIENTED PROGRAMMING RIGHT-SHIFT OPERATORS • Arithmetic or signed right shift (>>) operator: • Examples are: 128 >> 1 returns 128/21= 64 256 >> 4 returns 256/24= 16 -256 >> 4 returns -256/24= -16 • The sign bit is copied during the shift. • Logical or unsigned right-shift (>>>) operator: • This operator is used for bit patterns. • The sign bit is not copied during the shift.

  10. FP301 OBJECT ORIENTED PROGRAMMING LEFT-SHIFT OPERATORS Left-shift (<<) operator works as follows: 128 << 1 returns 128 * 21= 256 16 << 2 returns 16 * 22= 64

  11. FP301 OBJECT ORIENTED PROGRAMMING SHIFT OPERATOR EXAMPLES

  12. FP301 OBJECT ORIENTED PROGRAMMING STRING CONCATENATION WITH ‘+’ • The + operator works as follows: • Performs String concatenation • Produces a new String: String salutation = "Dr."; String name = "Pete" + " " + "Seymour"; String title = salutation + " " + name; • One argument must be a String object. • Non-strings are converted to String objects automatically.

  13. FP301 OBJECT ORIENTED PROGRAMMING APPLY THE RULES OF PRECEDENCE FOR AN EXPRESSION IN MODIFYING VARIABLES VALUES Example :- Applying the operator precedence and associativity rule, the expression 3 + 4 * 4 > 5 * (4 + 3) - 1 is evaluated as follows:

  14. FP301 OBJECT ORIENTED PROGRAMMING TYPE CASTING AND PROMOTIONS IN JAVA PROGRAMS Type Casting  refers to changing an entity of one datatypeinto another. • Example of potential issue: int num1 = 53; // 32 bits of memory to hold the value int num2 = 47; // 32 bits of memory to hold the value byte num3; // 8 bits of memory reserved num3 = (num1 + num2); // causes compiler error • Example of potential solution: int num1 = 53; int num2 = 47; long num3; num3 = (num1 + num2);

  15. FP301 OBJECT ORIENTED PROGRAMMING Cont.. • Variables are promoted automatically to a longer form (such as intto long). • Expression is assignment-compatible if the variable type is at least as large (the same number of bits) as the expression type. long bigval = 6; // 6 is an int type, OK intsmallval = 99L; // 99L is a long, illegal double z = 12.414F; // 12.414F is float, OK float z1 = 12.414; // 12.414 is double, illegal

More Related