In today’s era, the knowledge of Java has become very essential for the interviews and competitive examinations since a major part of the questions are asked from the programming section specially from Java coding questions. So here are some java interview questions for the students appearing in the job interviews which are mostly asked in the interviews.
Basic Java Interview Questions
Some basic level Java interview questions along with their answers which may be useful for your job interviews are as follows :
1. What is the most important feature of Java ?
Ans. The most important feature of Java is that it is a platform independent language which means that the code can be written in any platform and can be executed in any other supported platform.
2. What do you understand by JVM ?
Ans. JVM or Java Virtual Machine is an interpreter that converts Java byte code into machine level language.
3. Does Java support multiple inheritance ?
Ans. No, Java doesn’t support multiple inheritance.
4. What are local variables ?
Ans. Local variables are those variables whose scope lies only within the method where it is initialized. They cannot be used globally, that is, outside the method where it is initialized.
5. What is the difference between the keywords final and finally ?
Ans. When the keyword final is used before any variable, then the value of that variable becomes final, that is, fixed and does not change throughout the program. On the other hand, when in exception handling, after the try block when the program needs to be executed, finally is used.
6. What is an interface ?
Ans. An interface is a type of class where all the functions or methods are declared which are to be used in the program.
7. What is an inner class ?
Ans. If the methods of a class can be accessed only by the instance of the class, then such a class is known as an inner class.
8. What is the Collections API ?
Ans. The Collections API is a set of classes and interfaces that support operation on the collections of objects.
9. What is the difference between class and class path ?
Ans. Both the class and class path are the operating system level environment variables. While path is used to define where the system can find the executable files, on the other hand class path is used to specify the location of class files.
10. What are pointers ? Are pointers supported by Java ?
Ans. Pointers store the memory addresses. Improper handling of pointers leads to memory leaks, thus Java does not support pointers.
Frequently Asked Java Questions along with Answers :
The Frequently Asked Questions on Java coding for job interviews are as follows :
1. What is Java ?
Ans. Java is a high level Object Oriented Programming Language which works with the help of objects. It is a platform independent language and can run on a variety of platforms such as Windows, Mac, various versions of UNIX etc.
2. Which all platforms are supported by Java Programming Language ?
Ans. Java is a platform independent language and supports a large number of platforms such as Windows, Ubuntu, Mac OS, various versions of UNIX / LINUX , Sun Solaris etc.
3. What are objects ?
Ans. Objects are identifiable entities that have same characteristics and behavior. Its behavior is shown with the help of methods which operate on object’s internal state.
4. When is a byte data type used ?
Ans. Byte data type is used to save space in large arrays specially in place of integers since bytes are four times smaller than integers.
5. What is an exception ?
Ans. An exception is a problem that arises during the execution of a program.
6. When is a throws keyword used ?
Ans. If a method does not handle a checked exception, the method must declare it using a throws keyword. The throws keyword appears at the bottom of the method’s signature.
7. What is a multi threaded program ?
Ans. A multi threaded program contains two or more parts of a program that can run concurrently. Each part of the program is called a thread and each thread defines a separate path of execution.
8. What do you mean by platform independence ?
Ans. Platform independence implies that the code can be written and compiled in one platform and can be executed in another platform.
9. What is the usage of this() with constructors ?
Ans. this() is used with variables or methods and is used to call constructor of the same class.
10. What is a Null Point exception ?
Ans. A Null Point exception is thrown either for calling instance method of a null object or for accessing or modifying the field of a null object.
Advance Java Interview Questions with Answers
Some probable java coding questions for the advanced level which may be asked in your job interviews are as follows :
1. What is synchronization and why is it important ?
Ans. With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in process or using the object’s value. This often leads to significant errors.
2. What is the difference between a vector and an array list ?
Ans. The basic difference between a vector and an array list is that vector is synchronized while an array list is not synchronized.
3. What do you mean by Hashmap ?
Ans. The Hashmap class is equivalent to Hashtable except for the fact that it is unsynchronized and permits null values.
4. What is a transient variable ?
Ans. A transient variable is that type of variable that cannot be serialized.
5. What is ORM ?
Ans. ORM or Object Relational Mapping is a tool for transaction management that needs to be integrated with Spring, Struts etc.
6. What method is used to specify a container’s layout ?
Ans. The method setLayout() is used to specify a container’s layout.
7. What is the name of the state where a thread enters when it terminates its processing ?
Ans. The state is called the dead state where the thread enters when it terminates its processing.
8. What is the difference between an argument and a parameter ?
Ans. While defining the method, the variables passed in the method are called parameters and while using the methods, the values passed to the variables are called arguments.
9. What do you mean by garbage collection ?
Ans. When an object is no longer referred to by any variable, java automatically reclaims memory used by it. This is known as garbage collection.
10. Is null a keyword ?
Ans. No, null is not a keyword.
Java Questions with answers for Freshers
Here are some interview questions on java coding along with their answers for the freshers appearing for job interviews :
1. What is an abstract class ?
Ans. An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.
2. What is the utility of an interface ?
Ans. Interfaces are useful for declaring methods that one or more classes implement.
3. What is the difference between a super class and a sub class ?
Ans. A super class is that class which is inherited by other classes while a sub class is that class which inherits from the super class.
4. What is inheritance ?
Ans. The process of inheriting all the features of one class.
5. What do you mean by an anonymous class ?
Ans. An anonymous class is that class which is defined inside a method without a name and which cannot have explicit constructors.