Assigning References – Basic Elements, Primitive Data Types, and Operators

Assigning References Copying reference values by assignment creates aliases. Below, the variable pizza1 is a reference to a pizza that is hot and spicy, and pizza2 is a reference to a pizza that is sweet and sour. Click here to view code image Pizza pizza1 = new Pizza(“Hot&Spicy”);Pizza pizza2 = new Pizza(“Sweet&Sour”);pizza2 = pizza1; Assigning … Read more

Instance Methods and the Object Reference this – Declarations

3.5 Instance Methods and the Object Reference this Instance methods belong to every object of the class and can be invoked only on objects. All members defined in the class, both static and non-static, are accessible in the context of an instance method. The reason is that all instance methods are passed an implicit reference … Read more

The Binary String Concatenation Operator + – Basic Elements, Primitive Data Types, and Operators

2.9 The Binary String Concatenation Operator + The binary operator + is overloaded in the sense that the operation performed is determined by the type of the operands. When one of the operands is a String object, a string concatenation is performed rather than numeric addition. String concatenation results in a newly created String object … Read more

Range of Numeric Values – Basic Elements, Primitive Data Types, and Operators

Range of Numeric Values As we have seen, all numeric types have a range of valid values (p. 41). This range is given by the constants named MAX_VALUE and MIN_VALUE, which are defined in each numeric wrapper type. The arithmetic operators are overloaded, meaning that the operation of an operator varies depending on the type … Read more

Arithmetic Operators: *, /, %, +, – – Basic Elements, Primitive Data Types, and Operators

2.8 Arithmetic Operators: *, /, %, +, – Arithmetic operators are used to construct mathematical expressions as in algebra. Their operands are of a numeric type (which includes the char type). Floating-point operations are now consistently strict; that is, they are executed in accordance with the IEEE-754 32-bit (float) and 64-bit (double) standard formats. This … Read more

Unary Arithmetic Operators: -, + – Basic Elements, Primitive Data Types, and Operators

Unary Arithmetic Operators: -, + The unary operators have the highest precedence of all the arithmetic operators. The unary operator – negates the numeric value of its operand. The following example illustrates the right associativity of the unary operators: Click here to view code image int value = – -10; // (-(-10)) is 10 Notice … Read more

Boolean Expressions – Basic Elements, Primitive Data Types, and Operators

2.11 Boolean Expressions As the name implies, a boolean expression has the boolean data type and can only evaluate to the value true or false. Boolean expressions, when used as conditionals in control statements, allow the program flow to be controlled during execution. Boolean expressions can be formed using relational operators (p. 74), equality operators … Read more

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

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

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