Free forever · Browser-based · No setup required Back to course
Students will gain the ability to manipulate data and perform various operations in Java. They will learn to use different types of operators and understand operator precedence.
By the end of this unit, students will be able to perform type casting and conversions, giving them the tools to handle different data types effectively in their programs.
Each lesson in this unit follows the same structure:
- Read the concept
- Study the example
- Write or modify Java code
- Compile the program
- Run the code
- Review the output
- Complete a hands-on lab
- Answer review questions
Arithmetic, relational, and logical operators
Arithmetic operators perform mathematical calculations: addition, subtraction, multiplication, division, and modulus. Relational operators compare two values and return a boolean result: equal to, not equal to, greater than, less than, greater than or equal to, and less than or equal to. Logical operators combine boolean expressions: AND returns true only when both conditions are true, OR returns true when at least one condition is true, and NOT reverses a boolean value.
Assignment and compound assignment operators
The assignment operator stores a value in a variable. Compound assignment operators combine an arithmetic operation with assignment in a single step, such as adding a value to a variable and storing the result in the same variable simultaneously. These shorthand operators are widely used in professional Java code.
Operator precedence and associativity
When an expression contains multiple operators, Java evaluates them in a defined order called operator precedence. Multiplication and division are evaluated before addition and subtraction. Parentheses can be used to override the default order. Associativity determines the direction of evaluation when operators have equal precedence, which is left to right for most operators in Java.
Type casting and conversions
Type casting converts a value from one data type to another. Widening conversion happens automatically when a smaller type is assigned to a larger type, such as assigning an int to a double. Narrowing conversion requires an explicit cast and may result in data loss, such as converting a double to an int. Students will practice both types and learn when each is appropriate.
This unit is included in all academic level tracks.
| Academic Level | Track |
|---|---|
| High School | Units 1–7 |
| College / University — Year 1 | Units 1–8 |
| College / University — Year 2 | Units 1–11 |
| College / University — Year 3 | Units 1–13 |
Start this unit Terms of Use · Privacy Policy
© Java Pro Academy. All rights reserved.