This is a mock Exam based on the Objectives for the Sun Java Programmers Exam. It
is created by Genesis InSoft Limited (admin@genesisinsoft.com)
and may be freely distributed so long as it is unmodified. Please email us if you
have any corrections or comments.
Which of the following converts an array of bytes to an instance of class Class?
- toClass( )
- createClass()
- byteToClass()
- defineClass()
Answer to Question 1
What is the general form of declaration for a method in Java?
- accessspecifier modifier returnvalue name of method (parameters)
throws ExceptionList
- modifier accessspecifier returnvalue name of method (parameters)
throws ExceptionList
- accessspecifier returnvalue modifier name of method (parameters)
throws ExceptionList
- modifier returnvalue accessspecifier name of method (parameters)
throws ExceptionList
Answer to Question 2
What is the default Container layout combination for a Panel?
- FlowLayout
- CardLayout
- BorderLayout
- GridLayout
Answer to Question 3
________ a thread group is automatically destroyed when its last thread is stopped
or its last
thread group is destroyed.
- Daemon
- Auto
- Default
- none
Answer to Question 4
Which is the followig method returns the current number of active threads in this
thread group
- currentCount()
- threadCount()
- activeCount()
- getActiveCount()
Answer to Question 5
What is the output of the following code?
int i = 16;
int j = 17;
System.out.println("i >> 1 = " +
(i >> 1));
System.out.println("j >> 1 = " +
(j >> 1));
- Prints "i >> 1 = 8"
"j >> 1 = 8"
- Prints "i >> 1 = 7"
"j >> 1 = 7"
- Prints "i >> 1 = 8"
"j >> 1 = 9"
- Prints "i >> 1 = 7"
"j >> 1 = 8"
Answer to Question 6
Which of the operators have the lowest precedence in Java Operators?
- Parentheses i.e [ ], ()
- Conditional i.e ?:
- Unary operators i.e +, -, ++, --
- Assignment Operator i.e =
Answer to Question 7
1. public class Q11{
2. static String str1 = "main method
with String[] args";
3. static String str2 = "main method
with int[] args";
4. public static void main(String[] args){
5. System.out.println(str1);
6. }
7. public static void main(int[] args){
8. System.out.println(str2);
9. }
10. }
What will happen if you compile/run the following code?
- Duplicate method main(), compilation error at line 6.
- Duplicate method main(), compilation error at line 11.
- Prints "main method with main String[] args".
- Prints "main method with main int[] args".
Answer to Question 8
class Th22{
public static void main(String args[
]){
int i = -333;
int j = ~i;
System.out.println(j);
}
}
The output of the above program is
- Compilation error . ~ operator applicable to boolean values only.
- Prints 333.
- Prints 332
- Prints 334
Answer to Question 9
What is the output of the following code?
1. class StringTest {
2. public static void main(String args[
]){
3. String str
= "Welcome";
4. str.concat("
to Java!");
5. System.out.println(str);
6. }
7. }
- Strings are immutable, compilation error at line 3.
- Strings are immutable, runtime exception at line 3.
- Prints "Welcome".
- Prints "Welcome to Java!".
Answer to Question 10
Java archives (JAR files) can be used to improve the download speed of your applets.
What types of files can be stored in JAR archives?
- XML files
- BMP files
- Class files
- All of the above
Answer to Question 11
What does the stop() internally do to stop a thread ?
- it calls the destroy() method of the Thread class.
- it calls the yield() method of the Thread class.
- it throws an instance of the ThreadDeath class.
- None of the above.
Answer to Question 12
What is the only method available in the Runnable inteface ?
- start().
- stop().
- run().
- sleep().
Answer to Question 13
What will happen if you compile/run the folowing lines of code?
Vector a = new Vector();
a.addElement(10);
System.out.println(a.elementAt(0));
- Prints 10.
- Prints 11.
- Compilation error.
- Prints some garbage.
Answer to Question 14
What will happen if you invoke the following method?
public void check() {
System.out.println(Math.min(-0.0,+0.0));
System.out.println(Math.max(-0.0,+0.0));
System.out.println(Math.min(-0.0,+0.0)
== Math.max(0.0,+0.0));
}
- prints -0.0, +0.0 and false.
- prints -0.0, +0.0 and true.
- prints 0.0, 0.0 and false.
- prints 0.0, 0.0 and true.
Answer to Question 15
public class Test {
//Some code comes here
}
Which of the following can be used to define a constructor for this class?
- public void Test() {...}
- public Test() {...}
- public static Test() {...}
- public static void Test() {...}
Answer to Question 16
What tags are mandatory when creating HTML to display an applet?
- name, height, width.
- code, name.
- codebase, height, width.
- code, height, width
Answer to Question 17
Characters in java are based on which encoding scheme ?
- Unicode encoding scheme.
- ASCII / ANSI.
- UTF 8.
- None of the above.
Answer to Question 18
public class MyFor{
public static void main(String argv[]){
int i; int j;
outer:for (i=1;i
<3;i++){
inner:for(j=1; j<3; j++) {
if (j==2)
continue outer;
System.out.println("Value for i=" + i + " Value for j=" +j);
}
}
}
}
What is the output of the above program?
- Value for i=1 value for j=1.
- Value for i=2 value for j=3.
- Value for i=2 value for j=2.
- Value for i=3 value for j=1
Answer to Question 19
Which of the following technologies depend on the "Serialization" mechanism?
- JiniTM technology.
- JavaSpacesTM technology.
- RMI.
- All of the above
Answer to Question 20
Answers
Answer 1 - D
Back to question 1
Answer 2 - A
Back to question 2
Answer 3 - A
Back to question 3
Answer 4 - A
Back to question 4
Answer 5 - C
Back to question 5
Answer 6 - A
Back to question 6
Answer 7 - D
Back to question 7
Answer 8 - C
Back to question 8
Answer 9 - C
Back to question 9
Answer 10 - C
Back to question 10
Answer 11 - D
Back to question 11
Answer 12 - C
Back to question 12
Answer 13 - C
Back to question 13
Answer 14 - C
Back to question 14
Answer 15 - B
Back to question 15
Answer 16 - B
Back to question 16
Answer 17 - D
Back to question 17
Answer 18 - A
Back to question 18
Answer 19 - A,B
Back to question 19
Answer 20 - D
Back to question 20