This chapter from 'object-oriented program development using java: a class-centered approach' covers additional features of java, including bit operators, conditional expressions, and command-line arguments. Learn about non-decimal number bases, the flush() method, and how to manipulate individual bits using and, or, and xor operators.
Download Java Programming: Object-Oriented Approach - Chapter 14: Additional Capabilities and more Slides Applications of Computer Sciences in PDF only on Docsity!
Chapter 14:
Additional Capabilities
Object-Oriented Program
Development Using Java: A
Class-Centered Approach
Objectives
Additional Features
Bit Operators
Command-Line Arguments
The flush() Method
When using print() method, arguments placed within the parentheses are sequentially put in a temporary holding area - Called a buffer
Buffer is continually used until it is forced to send its contents to an output stream
The flush() Method (continued)
Flush:
Forcing buffer contents to an output stream
Occurs whenever:
Line terminator character is encountered
End of program is reached
Explicit flush() method is called
Syntax:
System.out.flush();
Conditional Expressions
Conditional operator: -? :
Provides an alternative way of expressing a simple if- else statement
Syntax:
condition? expression1 : expression
Ternary operator
Conditional Expressions
(continued)
If the value of the condition is true:
expression is evaluated
Otherwise expression2 is evaluated
Conditional expressions are usually unclear
Only useful in replacing if-else statements
When expressions in equivalent if-else statement are not long or complicated
The AND Operator
Operator symbol: &
Result of each bit-by-bit comparison is 1
Only when both bits being compared are 1s
Otherwise result is 0
Useful in masking selected bits from an operand
The Inclusive OR Operator
Operator symbol: |
Result of comparison is 1
If either bit being compared is 1
Otherwise, result is 0
Useful in forcing selected bits to take on a 1 value