You can find core Java interview questions as well as advanced Java interview questions answers here. All these Java interview questions and answers have been gathered meticulously from reliable sources. Whether you are a fresher or an experienced Java developer, these questions and answers will surely help you brush up your Java skills and prepare you well for the interview.
The interview for a position of fresher and experienced developers is different. The complexity of the question also differs a great deal. In this collection of Java programming interview questions, you will find some of the most frequently asked Java interview questions with answers. You can go through them and enhance your confidence to take on any interview for Java developer.
Java is one of the most sough-after technology in the IT industry. Most of the multinational IT firms require JAVA professionals with command over core and advance Java and the Java Frameworks like Spring, Hibernate and others. As there is a fierce competition in the IT sector, the candidates who wish to make it big in the software industry and particularly in the JAVA domain must be prepared to face Java interview.
Collection of the best Java job interview Questions and Answers
Top Core Java interview questions
Question: How many type of memory areas does JVM allocate?
Answer: It is one of the most frequently asked Java interview questions from freshers.
The types of memory allocated are:
Heap
Stack
Class area
Native method stack
Program counter register
Question: Can this() and super() both be used in a constructor?
Answer: No, because both super() and this() are required to be the first statement in a constructor.
Question: What is a covariant return type?
Answer: It is a among the top java interview questions for experienced asked frequently. It is a feature of Java5 using which we can override a method by changing its return type. It is possible only if the subclass overrides a method with a non-primitive return type. The return type is changed to subclass type.
Example code
class Car{ Car get(){return this;} } class sedan extends Car{ Sedan get(){return this;} void message(){System.out.println("covariant return type");} public static void main(String args[]){ new Sedan ().get().message(); } }
Question: Why is String class immutable?
Answer: The String class is immutable, to prevent any change to the String object. As the String is immutable the threads can share them without compromising on the safety.
Question: How do you invoke a superclass version of a method which is overridden?
Answer: For invoking a superclass method that is overridden in a subclass, you can either call the method using the the superclass instance, or subclass superfix. From the perspective of the subclass, there is an explicit reference to the superclass’ implementation of the method.
// From subclass super.overriddenMethod();
Question: What do you understand by a marker interface?
Answer: Marker interface is an interface with no fields or methods. In other words, we can call it an empty interface. Some examples of marker interface are java.io.Serializable interface and Cloneable. These interfaces do not contain any methods, but classes need to implement them to be serialized and de-serialized.
Question: What is an Iterator interface ?
Answer:
- The Iterator interface is used to cycle through a collection and let you display the elements.
- You can go through each element of the collection and process them.
- Iterator interface is a generic way to step through the elements irrespective of their organization in the collection.
- Boolean hasNext(), Object next() and void remove() are the methods associated with iterator.
Question: What is the Set interface ?
Answer:
- The Set interface provides methods for accessing the elements of a finite mathematical set
- Sets do not allow duplicate elements
- Contains no methods other than those inherited from Collection
- It adds the restriction that duplicate elements are prohibited
- Two Set objects are equal if they contain the same elements
Question: What are the main Implementations of the Set interface?
Answer: The main implementations of the List interface are as follows:
- HashSet
- TreeSet
- LinkedHashSet
- EnumSet
Most asked Java architect interview questions
Q. What are the types of Class loaders used by JVM ?
Answer:
1. Extensions – They load the jar files from JDK extensions directory.
2. Bootstrap – It loads JDK internal classes and java.* packages.
3. System – It loads the classes contained in system classpath.
Q. What is meant by metaspace ?
Answer:Â The Permanent Generation (PermGen) space which was used previously has been totally removed in Java 8. It has been replaced by a new space called Metaspace. The advantage of PermGen removal and incorporation of metaspace is the dynamic spacing.
Q. What is meant by database deadlock and what are the ways to avoid it?
Answer:Â When more than one external resources make an attempt to access the database, it gets locked and enters into cyclic wait. As the database becomes unresponsive and undecisive, it is called Database deadlock.
Database deadlock is avoidable using these methods:
- A queue can be made where the request will be first verified and then ordered to the database.
- Reducing the use of cursors as they make the database tables unresponsive.
- Transaction should be kept small.
Q. How to add a jar to a project with the help of Maven ?
Answer: If the jar is present in the Maven local repository, it can be added as a dependency in the pom file. Its Artifact Id, Group ID and version will be used in the process. Alternatively, we can SystemPath can be provided as additional attribute, if the jar is not located in the local repository.
We can also first install it in the local repository and then add it as a dependency.
Java multithreading interview questions with answers
Question: If you have threads T1, T2, T3, how will make T2 run after T1 and T3 run after T2 ?
Answer: This is a basic multithreading question and is asked to know whether the candidate has idea about the join method. The answer to this question is that it can be done by using join() method.
Java Interview Questions & Answers Video
Java Interview Questions and Answers : A guide for experienced
Top 10 JAVA Interview Questions
These questions and answers are equally useful for the freshers as well as experienced. Whether you are looking for core Java interview questions and answer or advanced Java interview questions and answers, you have come at the right place. The interview questions on core Java has been prepared by the experts and will definitely be helpful in giving insight on Java. If you are an experienced Java developer and looking for java interview questions and answers for 2 year experience, you can find them in plenty.
The position of a Java developer is a very lucrative one in terms of quality of work, salary and opportunity to go overseas on-site location. You need to well prepared for the interview whether you are a fresher on an experienced Java developer. If you are looking to switch company and searching top core java interview questions for senior developers, you are the right spot. Just go through all these Java interview questions with answer and enhance your chance to be selected for the interview.
We have compiled these java developer job interview questions with great care and every effort has been put in to ensure the utmost accuracy of the answers. You will find java interview questions and answers for experienced professionals as well as java interview questions and answers for freshers. Make the most of this collection and let us know if we can add more valuable questions.
Comments
0 comments