Term
Control Statements
Q: What is the purpose of an if-else statement? |
|
Definition
Ans: It allows conditional execution of code blocks based on whether a condition is true or false.
[image] |
|
|
Term
Q: Why do we use .equals() instead of == for string comparison? |
|
Definition
Ans:
.equals() compares the actual content of two strings, while == checks if they reference the same memory location. |
|
|
Term
Control Statements
Switch Statement
Q: When should you use a switch statement instead of if-else? |
|
Definition
Ans: When you need to compare a variable against multiple fixed values efficiently.[image] |
|
|
Term
Control Statements
Q: What happens if you forget the break statement in a switch? |
|
Definition
Ans:
Without break, execution will continue into the next case (fall-through behavior).
|
|
|
Term
Logical Operators (&&, ||, !)
Q: What does && do? |
|
Definition
Ans:
It checks if both conditions are true
(logical AND). |
|
|
Term
Logical Operators (&&, ||, !)
Q: What does || do?
"Can you remember what its called?" |
|
Definition
Ans:
It checks if at least one condition is true (logical OR). |
|
|
Term
Logical Operators (&&, ||, !)
Q: What does ! do?
"Can you remember what it's called?" |
|
Definition
Ans:
The Logical NOT (! ) operator reverses (negates) the truth value of a condition.
- If a condition is true , ! makes it false .
- If a condition is false , ! makes it true .
EX : boolean isRaining = true; System.out.println(!isRaining);
isRaining is true , but !isRaining is false .
|
|
|
Term
Modulo Operator (%)
Q: What does x % y return? |
|
Definition
Ans:
The remainder when x is divided by y. |
|
|
Term
Modulo Operator (%)
Q:
How do you check if a number is even or odd using %? |
|
Definition
Ans:
num % 2 == 0 means even,
num % 2 != 0 means odd. |
|
|
Term
Methods (Functions) in Java
Q:
What is a method in Java? |
|
Definition
Ans:
A reusable block of code that performs a specific task. |
|
|
Term
Methods (Functions) in Java
Q: What’s the difference between a void method and a method with a return type? |
|
Definition
Ans:
void methods perform actions without returning a value, while methods with a return type send back a result. |
|
|
Term
Methods with Parameters
Q: Why do we use parameters ( )
in methods? |
|
Definition
Ans:
To pass different values to a method, making it reusable. |
|
|
Term
Methods (Functions) in Java
Q: What happens if a method is called without passing required parameters? |
|
Definition
Ans:
A compilation error occurs because Java expects the required arguments. |
|
|
Term
Writing a Method with a Return Value
Q: How do you write a method that returns a value? |
|
Definition
Ans:
You define the return type in your method (e.g., int, double, String), and use return to send back a result.
EX: public static int addNumbers(int a, int b) {
return a + b;
} |
|
|
Term
Practicing Java Daily
Q: What are some daily Java practice exercises? |
|
Definition
Ans:
Write a program to check if a number is even or odd.
Modify an if-else program to include additional conditions.
Create a method that converts Fahrenheit to Celsius.
Experiment with switch to categorize animals or car brands.
|
|
|