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.
The combination of interpreter and compilation in Java is for?
- Security & robustness
- Faster execution
- Native code
- Platform independent byte code
Answer to Question 1
What is the correct ordering for the import, class and package declarations when
found in a single file?
- package, import, class
- class, import, package
- import, package, class
- package, class, import
Answer to Question 2
Machine independent byte code is interpreted by
- Java interpreter
- Java compiler
- Java Virtual Machine
- Browser
Answer to Question 3
Which of the following is platform dependent?
- Java virtual machine
- Java runtime compiler
- Java compiler
- All
Answer to Question 4
What does the compareTo() method in the String class of Java do?
- Compares whether two strings are same and returns a boolean value.
- Compares the total number of characters in two given Strings and based on that
returns a boolean value.
- Compares the given strings according to their Unicode values of the caharacters
and returns an integer value.
- Compares whether the two strings are same but differ only in their cases i.e the
first one is lower case and the second one is in uppercase or viceversa.
Answer to Question 5
The four parts to the Java virtual machine are
- Stack, Queue, Registers and Method area
- Stack, Queue, Registers and garbage-collection heap
- Stack, Queue, Method area and garbage-collection heap
- Stack, Registers, garbage-collection heap and Method area
Answer to Question 6
What is the return type of the following declaration?
int value = 10;
String.valueOf(value);
- 64k
- 32k
- 16k
- No limit
Answer to Question 7
What is the output of the program?
public class test {
public static void main(String arg[])
{
switch(0) {
case 0: System.out.print("0");
default:System.out.print("9");
case 1:System.out.print("1");
}
}
}
- No output
- 0 9
- 0 9 1
- Error: Default should be the last statement
Answer to Question 8
StringTokenizer is a class of which package?
- java.util
- java.io
- java.lang
- java.text
Answer to Question 9
What is the output of the program?
public class test {
public static void main(String arg[]) {
int p = 0, q =1;
if( p=1) {
p = q++ + 99;
q = p++ + 99;
}
System.out.println
(p);
System.out.println
(q);
}
}
- 0 1
- 101 199
- 101 201
- Error at compilation time
Answer to Question 10
Whenever you allocate memory with the new operator, where is the memory allocated?
- Stack
- Heap
- RAM
- Registers
Answer to Question 11
What of the following statement regarding an Event adapter class ?
- Event Adapter class are the classes which provide body/implementation to the methods
of the interfaces
which it implements and need to be extended compulsorily.
- Event Adapter class are the classes which provide empty implementation to the
methods of the interfaces
which it implements and need to be extended compulsorily.
- Event Adapter class are the classes which provide empty implementation to the
methods of the interfaces which it
implements and need not to be extended compulsorily.
- Event Adapter class are the classes which provide body/implementation to the methods
of the interfaces
which it implements and need not to be extended compulsorily.
Answer to Question 12
What is the return type of the read() method of InputStream class in java.io package?
- int
- String
- StringBuffer
- byte
Answer to Question 13
public class myprog{
public static void main(String argv[])
{
System.out.println(argv[2])
;
}
}
What will be the output if we execute the program with the command given in the
next line:
java myprog Good Morning
- myprog
- Good
- Morning
- Exception is given : java.lang.ArrayIndexOutOfBounds
Answer to Question 14
What is the output of the program?
public class divtest {
public void divide(int a, int b) {
try {
int c = a / b;
}
catch (Exception
e) {
System.out.print("Exception ");
}
finally {
System.out.println("Finally");
}
}
public static void main( String args[
]) {
int result
= 0;
divtest
dv = new divtest();
dv.divide(4,
0);
}
}
- Prints out: Exception Finally
- Prints out: Finally
- Prints out: Exception
- No output
Answer to Question 15
The "System.in" object used for the standard input operations is instantiated
from which class?
- System class
- InputStream class
- DataInputStream class.
- Object class
Answer to Question 16
Java interpreter option, which checks to see if the source code is newer than its
class file.
- sourcecheck
- checksource
- -checktime
- -checksrc
Answer to Question 17
import java.util.*;
public class mathTest {
public static void main( String args[
]){
// The required
statement needs to come here.
}
}
Which of the following will output -4.0?
- System.out.println(Math.floor(-4.7));
- System.out.println(Math.round(-4.7));
- System.out.println(Math.ceil(-4.7));
- System.out.println(Math.Min(-4.7));
Answer to Question 18
How are parameters and Objects passed in Java?
- Both are passed by value.
- Both are passed by reference.
- Parameters are passed by value but Objects by reference.
- Parameters are passed by reference but Objects are passed by value.
Answer to Question 19
Which of the operators have the highest precedence in Java Operators?
- Parentheses i.e [ ], ()
- Multiplicative operators i.e *, / , %
- Additive operators i.e +, -
- Assignment Operator i.e =
Answer to Question 20
Answers
Answer 1 - D
Back to question 1
Answer 2 - A
Back to question 2
Answer 3 - C
Back to question 3
Answer 4 - B
Back to question 4
Answer 5 - C
Back to question 5
Answer 6 - D
Back to question 6
Answer 7 - D
Back to question 7
Answer 8 - C
Back to question 8
Answer 9 - A
Back to question 9
Answer 10 - D
Back to question 10
Answer 11 - B
Back to question 11
Answer 12 - C
Back to question 12
Answer 13 - A
Back to question 13
Answer 14 - D
Back to question 14
Answer 15 - A
Back to question 15
Answer 16 - B
Back to question 16
Answer 17 - B
Back to question 17
Answer 18 - C
Back to question 18
Answer 19 - C
Back to question 19
Answer 20 - A
Back to question 20