1. What is the primary use of operators in Java?
Answer:
Explanation:
Operators in Java are used to perform various operations on variables and values, such as arithmetic, assignment, comparison, and logical operations​“【oaicite:12】“​.
2. Which operator is used in Java for addition?
Answer:
Explanation:
The '+' operator is used for addition in Java, allowing the addition of two values, a variable and a value, or two variables​“【oaicite:11】“​.
3. What does the '++' operator do in Java?
Answer:
Explanation:
The '++' operator is an arithmetic operator in Java that increments the value of a variable by one​“【oaicite:10】“​.
4. What is the function of the assignment operator '=' in Java?
Answer:
Explanation:
The assignment operator '=' is used to assign a value to a variable in Java​“【oaicite:9】“​.
5. What does the '!=' operator do in Java?
Answer:
Explanation:
The '!=' operator is a comparison operator that checks if two values are not equal​“【oaicite:8】“​.
6. What is the result of using the '&&' logical operator in Java?
Answer:
Explanation:
The '&&' operator is a logical AND operator, returning true if both the operands are true​“【oaicite:7】“​.
7. Which operator returns the remainder of a division in Java?
Answer:
Explanation:
The '%' operator, known as the modulus operator, is used in Java to return the remainder of a division​“【oaicite:6】“​.
8. How does the '+=' assignment operator function in Java?
Answer:
Explanation:
The '+=' operator adds a value to a variable and then assigns the result to that variable​“【oaicite:5】“​.
9. What is the purpose of the '<' operator in Java?
Answer:
Explanation:
The '<' operator is a comparison operator used to check if a value is less than another value​“【oaicite:4】“​.
10. Which operator is used to reverse the result of a boolean expression in Java?
Answer:
Explanation:
The '!' operator is a logical NOT operator, used to reverse the result of a boolean expression​“【oaicite:3】“​.
11. What is the function of the '>>=' operator in Java?
Answer:
Explanation:
The '>>=' operator is an assignment operator that performs right bitwise shift on the variable and then assigns the result​“【oaicite:2】“​.
12. What does the '==' operator check in Java?
Answer:
Explanation:
The '==' operator is a comparison operator used to check if two values are equal​“【oaicite:1】“​.
13. Which operator is used for concatenating two strings in Java?
Answer:
Explanation:
In Java, the + operator is overloaded for string concatenation.
14. What will be the result of the expression 3 + 6 * 2?
Answer:
Explanation:
According to operator precedence, multiplication is evaluated before addition. Thus, 6 * 2 equals 12, and then 3 is added, resulting in 15.
15. Which operator checks if two references point to the same object in memory?
Answer:
Explanation:
In Java, == checks if two references point to the same memory location. The equals method is used to check for value equality, and there is no === operator in Java.
16. Which of the following is a postfix increment operator?
Answer:
Explanation:
x++ is the postfix increment operator. It increments the value of x after its current value is used.
17. Which of the following operators is ternary?
Answer:
Explanation:
The ternary operator is represented by ? : and is the only operator in Java that takes three operands.
18. How can you check if a number x is even using operators?
Answer:
Explanation:
If a number is divisible by 2 with no remainder (x % 2), then it's an even number.
19. Which of the following is a modulus operator in Java?
Answer:
Explanation:
The % operator returns the remainder of a division operation.
20. What is the output of the following program?
public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
int result = x % y;
System.out.println(result);
}
}
Answer:
Explanation:
The % operator is used for finding the remainder of the division operation. In this case, 5 divided by 2 leaves a remainder of 1.