Govt. Exams
Entrance Exams
All three declarations are syntactically valid in Java and represent the same 2D array structure. The position of brackets doesn't matter for 2D array declaration - they all create a 3x4 integer array.
String s = "Java";
s = s.concat(" Programming");
System.out.println(s.length());
"Java" has 4 characters. After concatenation with " Programming" (12 characters including space), the total length is 4 + 13 = 17 characters.
int[] arr = new int[5];
System.out.println(arr[5]);
An array of size 5 has valid indices from 0 to 4. Accessing arr[5] throws ArrayIndexOutOfBoundsException at runtime because index 5 is out of bounds.
Java's garbage collector automatically identifies and reclaims memory of objects that are no longer referenced. While System.gc() can be suggested, it's not guaranteed to execute immediately.
The 'final' keyword when applied to a class prevents it from being extended or inherited. This is a fundamental OOP concept in Java used to restrict inheritance.
This uses the ternary operator (conditional operator). The condition 5 > 3 is true, so it returns the value after the '?', which is "Yes".
'thread' is not a Java keyword. 'synchronized', 'volatile', and 'transient' are all valid Java keywords used for special purposes.
'break' statement exits the innermost loop or switch statement. It doesn't skip the current iteration (that's 'continue') and doesn't terminate the entire program.
When dividing two integers, Java performs integer division and returns an integer result. 10 / 3 = 3 (remainder is discarded). To get decimal result, at least one operand should be a float or double.
In Java, the 'long' data type is always 64 bits, regardless of the platform. This is one of Java's strengths - its size specifications are platform-independent.