CSC 313 Java Chapter 2 continued Operators Notes to accompany Beginning Java 2 by Ivor Horton - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CSC 313 Java Chapter 2 continued Operators Notes to accompany Beginning Java 2 by Ivor Horton

Description:

Notes to accompany Beginning Java 2 by Ivor Horton. Relational operators. Standard relational operators for comparing values, return in true or ... deprecated ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 20
Provided by: gar59
Category:

less

Transcript and Presenter's Notes

Title: CSC 313 Java Chapter 2 continued Operators Notes to accompany Beginning Java 2 by Ivor Horton


1
CSC 313 JavaChapter 2 continued Operators
Notes to accompany Beginning Java 2 by Ivor Horton
2
Relational operators
  • Standard relational operators for comparing
    values, return in true or false gt greater
    than lt less than gt greater than or
    equal to lt less than or equal to
    equals ! and not equals
  • The equality operator should be used with caution
    on floating-point values and object references.

3
Logical Operators
  • Java has the standard logical operators and
  • inclusive-or ! not
  • Evaluation of a logical-and expression terminates
    with a value of false at the first false
    subexpression.
  • Evaluation of a logical-or expression terminates
    with a value of true at the first true
    subexpression.

4
Logical Operators
  • Logical expressions evaluate left to right.
  • The bit operators and behave as logical
    operators if their operands are booleans instead
    of integers.

5
Bitwise Operations
  • You can combine integer values by logically
    combining or operating on their bits using the
    bitwise operators.
  • Four bitwise operators are available to work on
    integers
  • Bitwise AND Bitwise OR
  • Bitwise XOR Bitwise complement

6
Bitwise Operations Illustrated
7
Bitwise Operations Illustrated
8
Shift Operators
  • Java has three shift operators
  • ltlt Shift left, filling with zeros from the right
  • gtgt Shift right, propagating the sign bit from
    the left
  • gtgtgt Shift right, filling with zeros from the left

9
Shift Operators Illustrated
10
Shift Operators Illustrated
11
Shift Operators Illustrated
12
op Operators
  • shortcut addition, given X 4 X 5
    // X equals 9
  • - shortcut subtraction, given X 4 X - 2
    // X equals 2
  • shortcut multiplication, X4 X - 3 // X
    equals 12
  • / shortcut division, X4 X / 2 // X equals 2

13
instanceof operator
  • This operator tests whether an object
    instantiates a class. Illustrated by this code
    segment
  • Date d new Date()
  • if ( d instanceof Object ) // false
  • ...
  • else if ( d instanceof Date ) // true
  • ...

14
Operator Precedence
15
Operator Precedence
16
Program Comments
  • Java supports 3 ways of including comments line
    comments, block comments and documentation
    comments.
  • // line comment, rest of line ignored by
    compiler
  • / .. / block comments, all text between /
    and / ignored by compiler.
  • /
  • This is a documentation comment.
  • /

17
Program Comments
  • Documentation Comments
  • /
  • This is a documentation comment.
  • /
  • Any asterisks at the beginning of each line in a
    documentation comment are ignored, as are any
    spaces
  • preceding the first .
  • A documentation comment can also include HTML
    tags, as well as special tags beginning with _at_
    that
  • are used to document methods and classes in a
    standard form. The _at_ is followed by a keyword
    that
  • defines the purpose of the tag.

18
Documentation Comments
19
Time to wake up.
Have a Nice Weekend!!
Write a Comment
User Comments (0)
About PowerShow.com