Govt. Exams
Entrance Exams
Characters are treated as their ASCII values in arithmetic operations. 'A' (65) + 'B' (66) = 131.
The correct syntax is 'datatype[] arrayName = {elements};' or 'datatype[] arrayName = new datatype[size];'
The length() method returns the number of characters in the string "Java", which is 4 characters.
Java variable names are case-sensitive. 'age' and 'Age' are different variables. Names cannot start with digits, cannot contain spaces, and special characters are not allowed.
The ternary operator (?:) evaluates the condition (5 > 3, which is true) and returns the first value 'A'.
Parentheses () and array access [] have the highest precedence in Java. Multiplication, division, and modulo come next, followed by addition and subtraction.
When both operands are integers, the division result is an integer. 10 / 3 = 3 (integer division, not floating-point).
Once a final variable is assigned, it cannot be reassigned. The line 'y = 30;' will cause a compilation error.
The 'char' data type in Java is 2 bytes (16 bits) because it uses Unicode character encoding.
String is a non-primitive (reference) data type in Java. Primitive types include int, boolean, double, float, char, long, short, byte.