Links

Java QA: 10 Interview Questions for Java - Beginners Level

thanassis | Java Questions And Answers | Saturday, January 20th, 2007

This is a interview test for a Java programmer at a beginner’s level. There are 10 questions but with 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 questions.

1. Question : Syntax - Datatypes

Associate Java’s 8 Datatypes to their respective memory representations

1. char A. signed 8-bit
2. int   B. signed 16-bit
3. double   C. floating point 64-bit
4. float   D. signed 64-bit
5. short   E. unsigned 16-bit
6. boolean   F. signed 32-bit
7. long   G. floating point 32-bit
8. byte   H. 1 bit

2. Question: Syntax - CastingWhich of the following expressions contain illegal casts that will not get compiled?

1. byte b = (byte)6.25f ;
2. boolean bool = (boolean) 1 ;
3. int i = (int) true ;
4. char ch1 = (char) ((int)2.5f );
5. char ch2 = (short) 0×320 ;

3. Question: Syntax - Methods

What is going to be the output of the following fragment of code at the printing statement?
….
int x = 5;
int[] arr = { 3 };
m(x, arr):
System.out.println(“x=” + x * arr[0]);
….
public void m(int value, int[] arr) {
value+=5;
arr[0]+=10;
}

1. x = 5
2. x = 15
3. x = 65
4. x = 30
5. x = 130

4. Question: Language Features - Exception Handling

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

1. Exceptions are only thrown at the runtime of a program
2. Both Error and Exception are subclasses of a class named Throwable. 3. Errors can be caught much the same way as exceptions
4. Exceptions subclassing RuntimeException do not need explicit exception handling to pass the compilation stage
5. With proper exception handling, some compiler errors can be avoided

5. Question: Language Features - Packages

Consider the diagram below where package A has two subpackages, B and C. Which of the following statements are true and which are false?

1. import A.*; Imports all the classes in package A and in package B and C
2. import A.A*; Imports all the classes in package A that start with the letter A
3. import A; Imports all the classes of package A
4. import B.B; Imports class B from package B
5. import *; Imports all the packages described by the CLASSPATH

6. Question: Language Features - Applets

Which of the following statements concerning Applet’s security on the client are true and which are false?

Typically an Applet is restricted by the SecurityManager in:
1. Using resources such as local printers and filestores
2. Opening any socket
3. Asking the OS for more memory to run itself
4. Opening more than a predefined number of Frames
5. Finding out about the client’s username and the VM’s version
7. Question: Language Features - Static vs Instance Methods

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

1. Static methods are inherited the same way instance methods do.
2. Static methods can call instance methods as long as they have a reference to the object that the instance method belongs to.
3. It is possible to have static methods described as private.
4. It is possible to have static methods described as protected.
5. If a static method is described as final then it will be in-lined by the compiler

8. Question: APIs - java.lang

Which of the following statements concerning the java.lang package are true and which are false?

Package java.lang
1. is implicitly available to all java sources
2. has several sub-packages
3. contains useful classes such as the Vector and the HashTable
4. contains classes designed for sub-classing such as the class String
5. contains all the classes that make the parsing of java sources by the compiler possible and all those used for the basic needs of all the api’s.

9. Question: APIs - java.util

Which of the following statements concerning the java.util api are true and which are false?

1. A StringTokenizer can tokenize a String or a Stream depending on its constructor
2. A StringTokenizer uses a delimiter that can be any character or String
3. A StringTokenizer can recognize and parse numerical values, putting them into a field named nval
4. A Stack can store both datatypes and objects
5. The util package contains the Date and Time classes

10. Question: APIs - java.io

Which of the following statements concerning the java.io api are true and which are false?

1. The family of Readers/Writers has been built to replace Streams and to provide better efficiency
2. A File object in java represents either a file or a directory
3. In Unix, java’s File objects can change file permissions
4. A BufferedReader can be constructed by passing any Reader or Stream
5. Both objects and primitive datatypes can be directly serialized.



1. Answer to Question 1:

Answer : 1->E, 2->F, 3->C, 4->G, 5->B, 6->H, 7->D, 8->A
Grading : 1 point per success
Difficulty : 2/10 B

2. Answer to Question 2:

Answer : 2 and 3 contain illegal to the compiler castings
Grading : 2 points per success
Difficulty : 3/10 B

3. Answer to Question 3:

Answer : The 3rd answer is the correct (x=65)
Grading : 12 points for correct answer
Difficulty : 3/10 B

4. Answer to Question 4:

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

5. Answer to Question 5:

Answer : 1 = false, 2 = false, 3 = false, 4 = true, 5 = false;
Grading : 10 points if all answers are correct
Difficulty : 1/10 B

6. Answer to Question 6:

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

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

8. Answer to Question 8:

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

9. Answer to Question 9:

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

10. Answer to Question 10:

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

2 Comments

Leave a comment

RSS feed for comments on this post. TrackBack URI