What do Java’s int, double, and boolean types store?
int stores whole-number values, double stores decimal or floating-point values, and boolean stores either true or false.
Study Java Primitive Types and Expressions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What do Java’s int, double, and boolean types store?
int stores whole-number values, double stores decimal or floating-point values, and boolean stores either true or false.
What is a Java literal?
A literal is a fixed value written directly in source code, such as 12, 4.99, or false.
What is Java’s arithmetic operator precedence?
Parentheses are evaluated first, then *, /, and %, followed by + and -. Operators with equal precedence are evaluated left to right.
When does + perform String concatenation?
If either operand is a String, + performs concatenation. Evaluation remains left to right, so "Total: " + 2 + 3 produces "Total: 23".
What is the result of 7 / 3 in Java?
With two int operands, division uses integer arithmetic and discards the fractional part toward zero. Thus, 7 / 3 evaluates to 2.
How can you preserve the fraction in numeric division?
At least one operand must be a double before division occurs. For example, 7.0 / 3 produces approximately 2.3333333333333335.
What does the % operator return?
The % operator returns the remainder after division. For example, 17 % 5 evaluates to 2.
What happens when int division uses a zero divisor?
An int division or remainder operation with a zero divisor throws an ArithmeticException at run time.
What happens when an int operation exceeds its range?
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.
How does casting double to int handle the fractional part?
Casting a double to int discards its decimal portion toward zero; (int) -7.9 evaluates to -7, not -8.
Why does cast placement matter in division?
Casting before division changes the operation: (double) x / y performs floating-point division, while (double) (x / y) casts an already-truncated integer result.
How does Math.round differ from an int cast?
Math.round(6.7) returns 7 as a long, whereas (int) 6.7 returns 6 by truncating toward zero.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how IP addressing, local delivery, routing, forwarding, translation, and DNS work together to connect independent networks and locate services.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.