SARGA

. COM

Java Certified Programmers' Examination Samples


1) What is the correct ordering for import, class and package declarations in a single
java source file

Select most appropriate answer.

a) package, import, class
b) any order
c) package, class, import
d) import, package, class

2) Which of the following are valid java keywords

Select all valid answers.

a) NULL
b) switch
c) extends
d) Object
e) String

3) Which of the following lines will compile without warning or error.

Select all valid answers.

a) float f=0;
b) char c="0";
c) byte b=157;
d) boolean f=null;
e) int i=10;

4) Size of a byte can be

Select most appropriate answer.

a) -2^8 to 2^8
b) 0 - 255
c) -255 to 255
d) Depends on Java Virtual machine and Hardware
e) -128 to 127

5) What will be output if the program is executed as below

java Sample One Two Three

public class Sample{

public static void main(String argv[])
{
System.out.println(argv[2])
}
}

Select most appropriate answer.

a) One
b) Two
c) Three
d) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
e) None

6) What will be output if the program is executed as below

java -DOne -DTwo -DThree Sample

public class Sample{

public static void main(String argv[]) {
System.out.println(argv[2])
}
}

Select most appropriate answer.
///////////////////////////////////////////////////////////////////
Note: This may not be really needed for the Certification Examination.
///////////////////////////////////////////////////////////////////

a) One
b) Two
c) Three
d) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
e) None

5) Which of the following are legal identifiers

Select all valid answers.

a) _1_
b) int
c) byte1
d) $Value
e) goto
f) 3Value

6) Which of the following valid statements

Select all valid answers.

a) an array extends Object
b) an array extends Cloneable
c) an array implements Cloneable
d) an array extends primitive types like int, char, byte
e) None

7) Which of the following valid statements

Select all valid answers.

a) all classes extend Object by default
b) all classes implement Cloneable by default
c) In Java a class cannot extend more than one class.
d) In Java a class cannot extend a class and implement another interface at same time
e) In Java a class cannot implement a class.

8) What will be the output when you compile and execute the following program.

public class Base{

private int i;

static public void main(String[] a) {
System.out.println("Value is: " + i);
}

}

Select most appropriate answer(s).

a) Value is: 0
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None

9) Which of the following are valid java keywords

Select all valid answers.

a) FALSE
b) class
c) new
d) throw
e) Integer

10) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: private void test() {
4:
5: String aStr = "One";
6: String bStr = new String();
7: String cStr = new String("Three");
8: String dStr = aStr;
9: System.out.println(aStr + "," + bStr + "," + cStr + "," + dStr );
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error at line 5;
b) Runtime error. Variable dStr may not have been initialized.
c) Runtime error. java.lang.NullPointerException at line No 9
d) One,,Three,,
e) One,,Three,One

11) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: private void test() {
4:
5: String aStr = " One ";
6: String bStr = aStr;
7: aStr.toUpperCase();
8: aStr.trim();
9: System.out.println("[" + aStr + "," + bStr + "]");
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a)[ONE, One ]
b)[ One ,One]
c)[ONE,One]
d)[ONE,ONE]
e)[ One , One ]

11) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: private void test() {
4:
5: String aStr = "One";
6: String bStr = aStr;
7:
8: aStr = null;
9: System.out.println(bStr);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a)Runtime error. java.lang.NullPointerException at line No 9
b)null
c)A blank line
d)One

12) What will be the output when you compile and execute the following program.

public class Base{

private int i;

static public void main(String[] a) {
System.out.println("Value is: " + new Base().i);
}

}

Select most appropriate answer(s).

a) Value is: 0
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None

13) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: int array[];
4:
5: private void test() {
6: System.out.println("Value is: " + array[0]);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error. Variable array may not have been initialized.
b) Runtime error. Variable array[0] may not have been initialized.
c) Runtime error. java.lang.NullPointerException at line No 6

14) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: int array[] = new int[3];
4:
5: private void test() {
6: System.out.println("Value is: " + array[0]);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error. Variable array may not have been initialized.
b) Runtime error. Variable array[0] may not have been initialized.
c) Runtime error. java.lang.NullPointerException at line No 6
d) Value is: 0

15) What is the correct way of declarating main() so that the progarm can be
compiled and executed using this entry point.

Select all valid answers.

a) static public void main(String[] args)
b) static public void main(String a[])
c) public static void main(String[] a)
d) static void public main(String[] a)
e) public void main(String[] a)
f) static public void main(char arg[][])

16) How do you write 8 in octal format?

17) What is the value of 021 in decimal format?

18) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3:
4: private void test() {
5: Boolean f;
6: System.out.println("Value is: " + f);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error. Variable f may not have been initialized.
b) Runtime error. Variable f may not have been initialized.
c) Value is: null
d) Runtime error. java.lang.NullPointerException at line No 6
e) Value is: false
e) Value is: true

19) Size of a short can be

a) -2^16 to 2^16
b) 0 - 2^16
c) -2^8 to (2^8 -1)
d) Depends on Java Virtual machine and Hardware
e) -2^15 to (2^15 -1)

Select most appropriate answer.

20) How do you write 13 in octal format?

21) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3: Integer array[]= new Integer[3];
4:
5: private void test() {
6: System.out.println("Value is: " + array[0]);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error. Variable array may not have been initialized.
b) Runtime error. Variable array[0] may not have been initialized.
c) Value is: null
d) Runtime error. java.lang.NullPointerException at line No 6
e) Value is: 0
e) Value is:

22) Size of a char can be

a) -2^16 to 2^16
b) 0 - (2^16-1)
c) -2^8 to (2^8 -1)
d) Depends on Java Virtual machine and Hardware
e) -2^15 to (2^15 -1)

Select most appropriate answer.

23) How do you write 18 in Hexadecimal format?

24) How do you write 0x1C in decimal format?

25) Which of the following are valid java keywords

a) TRUE
b) delete
c) final
d) Integer
e) array

Select all valid answers.

26) What will be the output when you compile and execute the following program.

1:public class Base{
2:
3:
4: private void test() {
5: boolean f;
6: System.out.println("Value is: " + f);
7: }
8:
9: static public void main(String[] a) {
10: new Base().test();
11: }
12:
}

Select most appropriate answer.

a) Compile time error. Variable f may not have been initialized.
b) Runtime error. Variable f may not have been initialized.
c) Value is: null
d) Runtime error. java.lang.NullPointerException at line No 6
e) Value is: false
e) Value is: true

27) How do you write 19 in Hexadecimal format?

28) Size of an int (integer) can be

a) -2^32 to 2^32
b) 0 - 2^32
c) -2^16 to (2^16 -1)
d) Depends on Java Virtual machine and Hardware
e) -2^31 to (2^31 -1)

Select most appropriate answer.

29) What will be the output when you compile and execute the following program.

public class Base{

static private int i;

static public void main(String[] a) {
System.out.println("Value is: " + i);
}

}

Select most appropriate answer(s).

a) Value is: 0
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None

30) Size of a long can be

a) -2^64 to 2^64
b) 0 - 2^32
c) -2^32 to (2^32 -1)
d) Depends on Java Virtual machine and Hardware
e) -2^63 to (2^63 -1)

Select most appropriate answer.

31) What will be the output when you compile and execute the following program.

public class Base{

private int j;

private void test() {
int i;
System.out.println("Value is: " + i);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer(s).

a) Value is: 0
b) Runtime error. Variable i may not have been initialized.
c) Compile time error. Variable i may not have been initialized.
d) None
e) Error.Cannot access the private method test() from main()

32) Which of the following statements are true?

public class Base{

private void test() {

int i = 012;
int j = 10;
int k = 0x10;
int l = 0x0A;

}

static public void main(String[] a) {
new Base().test();
}

}

Select all valid answers.

a) i is equal to j
b) i is equal to k
c) i is equal to l
d) j is equal to l
e) k is equal to 16
f) None

33)


What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 | 3);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) true
b) false
c) 9
d) Compilation Error
e) 7

34) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 & 3);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) true
b) false
c) 9
d) Compilation Error
e) 2

35) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 && 3);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) true
b) false
c) 9
d) Compilation Error.Incompatible type for &&. Can't convert int to boolean.
e) 2

36)


What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 && 3);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) true
b) false
c) 9
d) Compilation Error.Incompatible type for ||. Can't convert int to boolean.
e) 2

37) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 >> 3);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) true
b) false
c) 0
d) Compilation Error.Incompatible type for >>. Can't convert int to boolean.
e) -1

38) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 >> 33);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 6
b) 1
c) 3
d) Compilation Error.Incompatible type for >>. Cannot be greater than 32
e) -1

39) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(!6);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 0
b) false
c) -6
d) Compilation Error.Incompatible type for !. Can't convert int to boolean.
e) !6

40) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(~6);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 0
b) false
c) -6
d) Compilation Error.Incompatible type for ~. Can't convert int to boolean.
e) ~6
f) -7

41) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(2^6);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 0
b) 2
c) 32
d) Compilation Error.Incompatible type for ^. Can't convert int to boolean.
e) 8
f) 4


42) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 + "(Result)");
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 6
b) 6(Result)
c) Runtime Error.Incompatible type for +. Can't convert an int to a string.
d) Compilation Error.Incompatible type for +. Can't add a string to an int.

43) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println(6 + 6 + "(Result)");
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) 66
b) 66(Result)
c) Runtime Error.Incompatible type for +. Can't convert an int to a string.
d) Compilation Error.Incompatible type for +. Can't add a string to an int.
e) 12(Result)

44) What will be the output when you compile and execute the following program.

public class Base{

private void test() {
System.out.println("Result:" + 6 + 6);
}

static public void main(String[] a) {
new Base().test();
}

}

Select most appropriate answer.

a) Result:6
b) Result:66
c) Runtime Error.Incompatible type for +. Can't convert an int to a string.
d) Compilation Error.Incompatible type for +. Can't add a string to an int.
e) Result:12


Answers:

1) A 2) BC 3)AE 4) E 5) C 6)D 7)ACD 8)AC 9)ACE 10)C

11)BCD 12)E 13)D 14)A 15)C 16)D 17)ABC 18) 010 19)17 20)A

21)E 22) 015 23)C 24)B 25) C 26)A 27)0x13 28) E 29)A 30)E

31)C 32)ACDE 33)E 34)D 35) D 36)C 37)C 38)D 39)F 40)F

41) B 42)E 43)E 44)B