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)

  1. List the primitive data types of Java with their sizes.
  2. What is a symbolic constant?
  3. Distinguish widening and narrowing conversion.
  4. What is the value of (int) 5.9?
  5. Distinguish ++x and x++.
  6. What is the conditional operator?
  7. Define operator precedence.
  8. What is fall-through in switch?
  9. Distinguish while and do-while.
  10. What is a labelled loop?

Medium Answer Questions (5 marks each)

  1. Explain the data types of Java.
  2. Explain type casting and type conversion in expressions.
  3. Explain the logical and bitwise operators with examples.
  4. Explain precedence and associativity with an example.
  5. Explain the switch statement with an example.
  6. Explain break, continue and labelled loops.

Long Answer Questions (15 marks each)

  1. Explain constants, variables, data types, declaration, symbolic constants and type casting in Java.
  2. Explain the operators of Java with examples.
  3. Explain arithmetic expressions, their evaluation, type conversion, precedence and associativity.
  4. 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