Free Online Flashcard Deck

Java Primitive Types and Expressions Free Online FlashCards

Study Java Primitive Types and Expressions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What do Java’s int, double, and boolean types store?

Back

int stores whole-number values, double stores decimal or floating-point values, and boolean stores either true or false.

02
Front

What is a Java literal?

Back

A literal is a fixed value written directly in source code, such as 12, 4.99, or false.

03
Front

What is Java’s arithmetic operator precedence?

Back

Parentheses are evaluated first, then *, /, and %, followed by + and -. Operators with equal precedence are evaluated left to right.

04
Front

When does + perform String concatenation?

Back

If either operand is a String, + performs concatenation. Evaluation remains left to right, so "Total: " + 2 + 3 produces "Total: 23".

05
Front

What is the result of 7 / 3 in Java?

Back

With two int operands, division uses integer arithmetic and discards the fractional part toward zero. Thus, 7 / 3 evaluates to 2.

06
Front

How can you preserve the fraction in numeric division?

Back

At least one operand must be a double before division occurs. For example, 7.0 / 3 produces approximately 2.3333333333333335.

07
Front

What does the % operator return?

Back

The % operator returns the remainder after division. For example, 17 % 5 evaluates to 2.

08
Front

What happens when int division uses a zero divisor?

Back

An int division or remainder operation with a zero divisor throws an ArithmeticException at run time.

09
Front

What happens when an int operation exceeds its range?

Back

An int overflow wraps around within the fixed int range instead of expanding. For example, 2,147,483,647 + 1 becomes -2,147,483,648.

10
Front

How does casting double to int handle the fractional part?

Back

Casting a double to int discards its decimal portion toward zero; (int) -7.9 evaluates to -7, not -8.

11
Front

Why does cast placement matter in division?

Back

Casting before division changes the operation: (double) x / y performs floating-point division, while (double) (x / y) casts an already-truncated integer result.

12
Front

How does Math.round differ from an int cast?

Back

Math.round(6.7) returns 7 as a long, whereas (int) 6.7 returns 6 by truncating toward zero.