What values can a Java boolean store?
A boolean stores exactly one of two values: true or false. Java conditions must have type boolean or Boolean; integers such as 1 and 0 cannot serve as conditions automatically.
Study Java Boolean Logic and Selection with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What values can a Java boolean store?
A boolean stores exactly one of two values: true or false. Java conditions must have type boolean or Boolean; integers such as 1 and 0 cannot serve as conditions automatically.
How do = and == differ in Java?
= assigns a value to a variable, while == tests whether two values are equal. For example, score = 90 changes score; score == 90 produces a boolean result.
How should Java String contents be compared?
For primitive numeric values, == compares the actual values. For String objects, == compares references; use equals to compare character contents, such as first.equals(second).
What do !, &&, and || mean?
! reverses a boolean, && is true only when both operands are true, and || is true when at least one operand is true.
What is Java’s logical operator precedence?
Without parentheses, Java evaluates logical operators in this order: ! first, then &&, then ||. Parentheses make compound conditions clearer and can change the grouping.
How does short-circuit evaluation work?
With &&, a false first operand prevents evaluation of the second. With ||, a true first operand prevents evaluation of the second. This can avoid errors such as division by zero.
What does a one-way if statement do?
An if statement executes its body only when its boolean condition is true. If the condition is false, the body is skipped and execution continues afterward.
When should you use if-else?
An if-else statement chooses exactly one of two bodies: the if body when the condition is true, or the else body when it is false.
How does an if-else-if chain choose a branch?
An if-else-if chain checks conditions from top to bottom and executes only the first branch whose condition is true. Therefore, condition order matters.
What is a nested conditional?
A nested conditional is a conditional inside another conditional. The inner condition is evaluated only if execution reaches it, such as after the outer condition is true.
Which if does an else match?
An else attaches to the nearest unmatched if at the same structural level. Braces make the intended association explicit and prevent ambiguity.
What are De Morgan’s laws?
De Morgan’s laws are !(a && b) equivalent to !a || !b, and !(a || b) equivalent to !a && !b. Negation switches AND and OR while negating each condition.
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.