Full Transcript

Q1 Explain identifier, keywords and literals in Java. Give examples of each. - They can contain letters (both uppercase and lowercase), digits, underscores (\_), and dollar signs (\$). - They must begin with a letter, underscore, or dollar sign. - They cannot be a reserved keyword. -...

Q1 Explain identifier, keywords and literals in Java. Give examples of each. - They can contain letters (both uppercase and lowercase), digits, underscores (\_), and dollar signs (\$). - They must begin with a letter, underscore, or dollar sign. - They cannot be a reserved keyword. - Java is case-sensitive, so myVariable and myvariable are different identifiers. - Example - Q2 Explain primitive data types in Java. Explain automatic type conversion and explicit type conversion with an example. - Q3 Explain relational, logical operators in Java. How does operator precedence affect the evaluation of expressions in Java? 1. **==**: Equal to - Checks if two values are equal. - Example: a == b 2. **!=**: Not equal to - Checks if two values are not equal. - Example: a != b 3. **\>**: Greater than - Checks if the left value is greater than the right value. - Example: a \> b 4. **\=**: Greater than or equal to - Checks if the left value is greater than or equal to the right value. - Example: a \>= b 6. **\ 7. **&&**: Logical AND - Returns true if both operands are true. - Example: a && b 8. **\|\|**: Logical OR - Returns true if at least one of the operands is true. - Example: a \|\| b 9. **!**: Logical NOT - Reverses the logical state of its operand. If the condition is true, it becomes false, and vice versa. - Example: !a 10. **Parentheses** () 11. **Unary operators** (e.g., ++, \--, !) 12. **Relational operators** (\ 22. **Usage**: Used for selecting one of many code blocks to be executed. 23. **Conditions**: Evaluates a single expression against multiple cases. 24. **Data Types**: Works with int, char, String, and enum types. 25. **Efficiency**: Generally more efficient for multiple discrete values.

Use Quizgecko on...
Browser
Browser