Links

Java QA: 10 Interview Questions for Java – Intermediate Level

thanassis | Java Questions And Answers | Friday, February 2nd, 2007

This is an interview test for Java programmers at internediate level. There are 10 questions and more than a single answer to most of the questions. The correct answers are given at the end of the article together with the points awarded for each correct option and the difficulty of the question on a 1-10 scale. The best score you can get is 100 by answering correctly to all the questions.

1. Question : Syntax – Algorithms

What would be the behaviour of the next fragment of code if called with x(4,””) :

public static void x(int rC, String c) {
String temp = c;
if (rC ==0) {
System.out.println(temp);
return;
}
else  {
rC--;
for (int i=0; i<26;i++) {
temp = c +(char)(65+i);
x(rC, temp);
}
}
}

1. A counter counting from A to Z will be print for 4 times
2. The 264 combinations of strings containing letters A to Z will be print
3. The compiler will throw an error for calling x() from x() itself
4. The program will hang in a never ending loop
5. The program will print for 264 times the alphabet in capital letters.

2. Question : Syntax - Object Casting

Which statements concerning object casting are true and which are false?:

An object can be cast to :
1. Any type from which the object's class is a direct or indirect extension or implementation.
2. Any datatype providing that there is a wrapper for it.
3. An Interface only if the class of the object directly implements that Interface.
4. Any other type as long as for that type there is package visibility
5. Any type that is a sutype of an object. This is called downcasting. Downcasting in java is safe because it is checked by the compiler.

3. Question : Language Features - Interface with Environment

Concerning Java's Interface with the environment. Which of the following statements are true and which are false?

1. Java can execute external processes but it can't communicate with them
2. Java can communicate with spawn processes but it can't control them
3. Properties in Java are stored in an object that inherits from a Hashtable
4. Environmental Variables can be passed through command line arguments in a java program
5. Applets have methods to read all datatypes as parameters given in a HTML page

4. Question : Language Features - String's Operator Overloading

What is the output of the following extract of code when we call run()?

void run() {
int x=0;
byte[] b= { 14 } ;
Employee e = new Employee();
String s = "My String";
m(x,b,e,s);
System.out.print("x:"+x+" b[0]:"+b[0]+" Name:"+e.getName()+" Str:"+s);
}
public  static void m(int x, byte[] b, Employee e, String s) {
x=5;
b[0]=5;
e.setName("Ron");
s = s + "has been added";
}

1. x:5 b[0]:14 Name:Ron Str:My String has been added
2. x:0 b[0]:5 Name:Ron Str:My String
3. x:0 b[0]:14 Name:Ron Str: My String has been added
4. x:0 b[0]:5 Name:Ron Str: My String has been added
5. x:5 b[0]:5 Name:Ron Str: My String

5. Question : Language Features - Threading

Concerning Java's multi-threading abilities. Which of the following statements are true and which are false?

1. When a method is synchronized there is no possibility of a Deadlock.
2. The thread that starts the application has always the minimum priority
3. A thread has its own stack area to store all local variables of the executing method
4. True concurrent execution is not possible using java
5. Notify() will wake up the thread that is waiting the longest.

6. Question : Object Orientation Principles - Polymorphism

Which of the following statements is true?

A polymorphic call is:
1. A call on a method that is defined many times with the same name within the same class but has different number/types of arguments. The selection of the method that actually gets' invoked is based on matching its arguments
2. A call where the selection of the method to run on an object is based on the type of the object at creation time. This selection is based on the name only and arguments are irrelevant.
3. A call that gets delegated to a method of another object
4. A call of the constructor of the parent class. It can be called only as the first expression of a constructor to implement polymorphic chaining.
5. Any call that is indirect.

7. Question : APIs - awt

What is an Adapter in AWT?

1. A GUI component that looks like a Slider but does not have a Border
2. A "helper" class that adapts data from GUI controls to models
3. A "dummy" implementation of a Listener interface used for convenience.
4. An object that translates coordinates between coordinate systems
5. A native implementation of a GUI component

8. Question : APIs - awt

Can you get a Graphics object within the constructor of any AWT Component's subclass?

1. Yes, you can just call getGraphics() that gets inherited from Component
2. Yes, you can just use fGraphics that is a protected field of Component
3. There is no way to get it. The graphics context object is given only to the paint(graphics g) method which is called asynchronously.
4. No, it hasn't been created yet by the peer.
5. Depends on the Component

9. Question : APIs - net

Which of the following statements concerning Sockets are true and which are false?

1. Sockets communicate though TCP/IP
2. A ServerSocket blocks when it waits to accept a call
3. Sockets communicate through Streams
4. A ServerSocket automatically spawns a new thread to handle the incoming client call and then it continues to listen for new client calls.
5. Serializable objects can be transferred between Sockets using ObjectInputStream and ObjectOutputStream

10. Question : APIs - RMI

How is "marshalling" done in RMI?

Through
1. A java tool called rmic
2. HTTP tunneling
3. Serialization
4. The use of JNI
5. The use of JNDI



1. Answer to Question 1:

Answer : 2 = true
Grading : 10 points for the 2nd answer
Difficulty : 7/10 I.

2. Answer to Question 2:

Answer : 1=true , 2 = false, 3= false, 4=false, 5=false;
Grading : 2 points for every correct answer
Difficulty : 5/10 I.

3. Answer to Question 3:

Answer : 1 = false, 2 = true, 3 = true, 4 = true, 5 = false
Grading : 2 points for every correct answer
Difficulty : 5/10 I.

4. Answer to Question 4:

Answer : 2 = true
Grading : 10 points for the correct answer
Difficulty : 7/10 I.

5. Answer to Question 5:

Answer : 1 = false, 2 = false, 3 = true, 4 = false, 5=false
Grading : 2 points for every correct answer
Difficulty : 8/10 I.

6. Answer to Question 6:

Answer : 2 = true
Grading : 10 points for the correct answer
Difficulty : 2/10 I.

7. Answer to Question 7:Answer : 3 = true
Grading : 10 points for the correct answer
Difficulty : 1/10 I.

8. Answer to Question 8:Answer : 4 = true
Grading : 10 points for the correct answer
Difficulty : 7/10 I.

9. Answer to Question 9:

Answer : 1 = true, 2 = true, 3 = true, 4 = false, 5 = true
Grading : 2 points for every correct answer
Difficulty : 7/10 I.

10. Answer to Question 10:

Answer : 3 = true
Grading : 10 points for the correct answer
Difficulty : 7/10 I.

2 Comments

Leave a comment

RSS feed for comments on this post. TrackBack URI