Unit summary
- Java has constants, variables and eight primitive data types with fixed sizes; final declares symbolic constants.
- Widening conversion is automatic, narrowing needs a cast, and expressions promote operands to the larger type.
- Java provides arithmetic, relational, logical, assignment, increment, conditional and bitwise operators.
- Precedence and associativity decide the order of evaluation; brackets override them.
- if, if-else, else-if ladders and switch make decisions.
- while, do-while, for and for-each loops repeat code, and break, continue and labelled loops control them.
Glossary
| Term | Meaning |
|---|---|
| Associativity | Order for operators of equal precedence. |
| Bitwise operator | An operator that works on bits. |
| Constant | A fixed value that does not change. |
| Entry-controlled loop | A loop that tests before each pass. |
| Exit-controlled loop | A loop that tests after each pass. |
| Fall-through | Running into the next case without break. |
| Labelled loop | A loop with a name used by break or continue. |
| Narrowing | Explicit conversion to a smaller type. |
| Operator | A symbol that performs an operation. |
| Precedence | Which operator is applied first. |
| Primitive type | One of the eight basic types of Java. |
| Reference type | A type that refers to an object. |
| Short-circuit | Skipping the second operand of && or ||. |
| switch | A statement selecting a case by value. |
| Symbolic constant | A named constant declared with final. |
| Ternary operator | The conditional operator ?:. |
| Type casting | Explicit conversion with (type). |
| Variable | A named memory location whose value can change. |
| Widening | Automatic conversion to a larger type. |
Question bank
Short Answer Questions (2 marks each)
- List the primitive data types of Java with their sizes.
- What is a symbolic constant?
- Distinguish widening and narrowing conversion.
- What is the value of (int) 5.9?
- Distinguish ++x and x++.
- What is the conditional operator?
- Define operator precedence.
- What is fall-through in switch?
- Distinguish while and do-while.
- What is a labelled loop?
Medium Answer Questions (5 marks each)
- Explain the data types of Java.
- Explain type casting and type conversion in expressions.
- Explain the logical and bitwise operators with examples.
- Explain precedence and associativity with an example.
- Explain the switch statement with an example.
- Explain break, continue and labelled loops.
Long Answer Questions (15 marks each)
- Explain constants, variables, data types, declaration, symbolic constants and type casting in Java.
- Explain the operators of Java with examples.
- Explain arithmetic expressions, their evaluation, type conversion, precedence and associativity.
- Explain decision making, branching and looping statements in Java, with jumps and labelled loops.
Sources
- Official BCA syllabus Object Oriented Programming using Java, course code 25BCA402SEC01, Unit II
