JAVA CERTIFICATION QUESTIONS

1. Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer.



   a.public static int main(char args[])
   b.public static void main(String args[])
   c.public static void MAIN(String args[])
   d.public static void main(String args)
   e.public static void main(char args[])









2. What all gets printed when the following code is compiled and run? Select the three correct answers.






public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) { for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}



    a. i=0 j=0
        i=0 j=1
        i=0 j=2
  
    b. i=1 j=0
        i=1 j=1
        i=1 j=2



    c. i=2 j=0
        i=2 j=1
        i=2 j=2






3. What gets printed when the following code is compiled and run with the following command -
java test 2
Select the one correct answer.
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();



if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}






      a. test
      b. test -1
      c. 0
      d. 1
      e. 2






4.In Java technology what expression can be used to represent number of elements in an array named arr?



5.How would the number 5 be represented in hex using up-to four characters.



6.Which of the following is a Java keyword. Select the four correct answers.



    a.extern
    b.synchronized
    c.volatile
    d.friend
    e.friendly
    f.transient
    g.this
    h.then



7. Is the following statement true or false. The constructor of a class must not have a return type.
   a.true
   b.false






8.What is the number of bytes used by Java primitive long. Select the one correct answer.
The number of bytes is compiler dependent.
a.2
b.4
c.8
d.64






9.Which of the following is correct? Select the two correct answers.
A .The native keyword indicates that the method is implemented in another language like C/C+ +.
B.. The only statements that can appear before an import statement in a Java file are comments.
C. The method definitions inside interfaces are public and abstract. They cannot be private or protected.
      1. A class constructor may have public or protected keyword before them, nothing else.




10.What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.
A.25
B.37
C.6
D.31
E.17
F.9
G.24






11.Which of the following are true. Select the one correct answers.
A.&& operator is used for short-circuited logical AND.
B.~ operator is the bit-wise XOR operator.
C.| operator is used to perform bitwise OR and also short-circuited logical OR.
      1. The unsigned right shift operator in Java is >>.




12.Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.






13.Which of the following is true. Select the two correct answers.
A class that is abstract may not be instantiated.
The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.
A static variable indicates there is only one copy of that variable.
A method defined as private indicates that it is accessible to all other classes in the same package.






14.What all gets printed when the following program is compiled and run. Select the two correct answers.






Public class test {
public static void main(String args[]) {
int i, j=1;
i = (j>1)?2:1;
switch(i) {
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}
0
1
2
3



15.What all gets printed when the following program is compiled and run. Select the one correct answer.






public class test {
public static void main(String args[]) {
int i=0, j=2;
do {
i=++i;
j--;
} while(j>0);
System.out.println(i);
}
}



0
1
2
The program does not compile because of statement "i=++i;"



16.What all gets printed when the following gets compiled and run. Select the three correct answers.
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}






0
1
2
3
4
17.What all gets printed when the following gets compiled and run. Select the two correct answers.




public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}






0
1
2
3
4
18.What all gets printed when the following gets compiled and run. Select the two correct answers.






public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}






1
2
3
4
19.What all gets printed when the following gets compiled and run. Select the two correct answers.






public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");



if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}

1
2
3
4
20.Which of the following are legal array declarations. Select the three correct answers.
int i[5][];
int i[][];
int []i[];
int i[5][5];
int[][] a;