Integer Bitwise Operators: ~, &, |, ^ – Basic Elements, Primitive Data Types, and Operators

2.16 Integer Bitwise Operators: ~, &, |, ^ A review of integer representation (p. 33) is recommended before continuing with this section on how integer bitwise operators can be applied to values of integral data types. Integer bitwise operators include the unary operator ~ (bitwise complement) and the binary operators & (bitwise AND), | (bitwise … Read more

Examples of Bitwise Operator Application – Basic Elements, Primitive Data Types, and Operators

Examples of Bitwise Operator Application Click here to view code image char v1 = ‘)’;          // Unicode value 41byte v2 = 13;int result1 = ~v1;      // -42int result2 = v1 & v2;  // 9int result3 = v1 | v2;  // 45int result4 = v1 ^ v2;  // 36 Table 2.32 shows how the result is … Read more

Boolean Logical Operators: !, ^, &, | – Basic Elements, Primitive Data Types, and Operators

2.14 Boolean Logical Operators: !, ^, &, | Boolean logical operators include the unary operator ! (logical complement) and the binary operators & (logical AND), | (logical inclusive OR), and ^ (logical exclusive OR, also called logical XOR). These operators can be applied to boolean or Boolean operands, returning a boolean value. The operators &, … Read more

Bitwise Compound Assignment Operators: &=, ^=, |= – Basic Elements, Primitive Data Types, and Operators

Bitwise Compound Assignment Operators: &=, ^=, |= Bitwise compound assignment operators for the bitwise operators are defined in Table 2.33. Type conversions for these operators, when applied to integral operands, are the same as for other compound assignment operators: An implicit narrowing conversion is performed on assignment when the destination data type is either byte, … Read more

Boolean Logical Compound Assignment Operators: &=, ^=, |= – Basic Elements, Primitive Data Types, and Operators

Boolean Logical Compound Assignment Operators: &=, ^=, |= Compound assignment operators for the boolean logical operators are defined in Table 2.27. The left-hand operand must be a boolean variable, and the right-hand operand must be a boolean expression. An identity conversion is applied implicitly on assignment. These operators can also be applied to integral operands … Read more

The Conditional Operator ?: – Basic Elements, Primitive Data Types, and Operators

2.18 The Conditional Operator ?: The ternary conditional operator ?: allows conditional expressions to be defined. The conditional expression has the following syntax: condition ?expression1 :expression2 It is called ternary because it has three operands. If the boolean expression condition is true, then expression1 is evaluated; otherwise, expression2 is evaluated. Both expression1 and expression2 must evaluate to … Read more

Class Declarations – Declarations

3.1 Class Declarations A class declaration introduces a new reference type and has the following syntax: Click here to view code image class_modifiers classclass_name extends_clause implements_clause // Class header{ // Class bodyfield_declarationsmethod_declarationsconstructor_declarationsmember_type_declarations} In the class header, the name of the class is preceded by the keyword class. In addition, the class header can specify the following information: … Read more

Method Declarations – Declarations

3.2 Method Declarations A method declaration has the following syntax: Click here to view code image method_modifiers return_type method_name             (formal_parameter_list)throws_clause // Method header{ // Method bodylocal_variable_declarationsstatements} In addition to the name of the method, the method header can specify the following information:  Access modifiers: public, protected, private (ยง6.5, p. 347)  Non-access method modifiers: static (p. 115), … Read more

Short-Circuit Evaluation – Basic Elements, Primitive Data Types, and Operators

Short-Circuit Evaluation In the evaluation of boolean expressions involving conditional AND and OR, the left-hand operand is evaluated before the right-hand operand, and the evaluation is short-circuited (i.e., if the result of the boolean expression can be determined from the left-hand operand, the right-hand operand is not evaluated). In other words, the right-hand operand is … Read more

Statements – Declarations

3.3 Statements Statements in Java can be grouped into various categories. Variable declarations, optionally specified with an initialization expression, are called declaration statements (p. 102). Other basic forms of statements are control flow statements (Chapter 4, p. 151) and expression statements. An expression statement is an expression terminated by a semicolon (;). Any value returned … Read more