50+ Java Interview Questions and Answers for Getting a Job

Thinking of joining any firm as a Java specialist? However, you must possess practical knowledge about the programming language but there are some questions that are generally asked in a Java Interview. You must go through them while preparing yourself for the interview round.

This will definitely help you to at least answer the questions that are generally preferred in the interview round. For your convenience, we have brought you a list of 50+ Java Interview Questions as well as their answers that will help you in getting a job:

Q1. What do you mean by Loops in Java?

Ans: Loops are used to repeatedly execute a certain statement or block of statements.

Basically, there are three types of Loops in Java: For Loops, While Loops and Do While Loops.

Q2. What do you understand by the term enumeration?

Ans:  Enumeration is an interface that you can use to access the original data structure from which the enumeration is obtained.

Q3. How do you prevent a class from being subclassed in Java?

Ans: In order to prevent a class from being subclassed you just need to make its constructor private.

Q4. What method will you use to override an Object to be used as Key in HashMap?

Ans: For an Object to be used as Key in HashMap you can use equals and hashcode.

Q5. How does Autoboxing of Integer work in Java?

Ans: The Autoboxing of Integer works using the valueOf() method in Java.

Q6. What do you mean by aggregation?

Ans: Aggregation is a type of weak relation you can create between two classes, where one contains references to another class contained within it.

Q7. What’s the exception in Java?

Ans: Exceptions are unusual conditions during the program. This may be caused due to an incorrect logic written by incorrect user input or a programmer.

Q8. What is the difference between this and super in Java?

Ans: “this” refers to the current instance whereas “super” refers to an instance of the superclass.

Q9. What is the difference between wait and sleep in Java?

Ans: The wait() method releases the lock or monitor, while sleep doesn’t.

Q10. Why is Java not 100% Object-oriented?

Ans:  Java makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects. That’s why Java is not 100% Object-oriented.

Q11. How can we find the actual size of an object on the heap?

Ans: In Java, there is no way to find out the actual size of an object on the heap.

Q12. What is the default size of the load factor in the hashing-based collection?

Default size = 0.75

Q13. Can we access the private method in Java?

Ans: Yes, in the same class but not outside the class.

Q14. Name two Java IDEs?

Ans: Eclipse and NetBeans.

Q15. Can you pass argument to a function by reference instead of pass by value?

Ans: No, we can pass argument to a function only by value and not by reference.

Q16. What is meant by Overloading?

Ans: Method overloading occurs for different classes or within the same class.

Q17. Can we override the private method in Java?

Ans: No, because it’s not visible in the subclass, a primary requirement for overriding a method in Java.

Q18. Explain the use of Pointers in Java class.

Ans: There are no pointers in Java. Hence, there is no use of Pointers in Java.

Q19. Explain the difference between Serializable and Externalizable in Java.

Ans: The only difference between the two is that Externalizable gives you more control as compared to the Serialization process.

Q20. What is JAVA?

Ans: Java is a high-level programming language that is platform-independent.

Q21. What do you mean by the term literal?

Ans: A literal is a constant value assigned to a particular variable

Q22. Define workspace.

Ans: Workspace manages the jar files, Artifacts & runtime libraries.

Q23. What is a package in Java?

Ans: A package is a set of relevant classes and interfaces.

Q24. Which class remains superclass for each class?

Ans: Object class remains superclass for each class.

Q25. What is spanning tree?

Ans: A spanning tree is that type of tree in which you can cover all nodes using minimum number of edges.

Q25. What is Inheritance?

Ans: Inheritance allows you to let a derived class acquire the methods from a base class.

Q26. What is Class?

Ans: Class is a templet or blueprint or collection of objects .its describe state and behaviors .state means-data, behavior means-method.

Q27. What is the use of encapsulation?

Ans: Encapsulation can be used for combining properties and methods in a single unit.

Q28. Define JSON.

Ans: JSON stands for JavaScript Object Code. JSON uses JavaScript syntax, and the design is only text.

Q29. What do you understand by method overloading?

Ans: Method overloading occurs when a Java program contains more than one method with the same name but with different properties.

Q30. What is the full form of JAXB?

Ans: JAXB stands for Java API for XML Binding.

Q31. List out the Classes available in Java collections

Ans: Various classes available in Java collections are Array List, Linked List, Lists and Vector.

Q32. What do you mean by JDK?

Ans: JDK is an acronym used for Java Development Kit and it is a software development environment which can be used to develop Java apps.

Q33. What is an array?

Ans: Array is the collection of homogenous data elements.

Q34. Which class inherits from super class?

Ans: Sub-class

Q35. Can you find the actual size of an object om the heap?

Ans: No, there is no way to find out the exact size of an object on the heap in Java.

Q36. Which class is the superclass of all the classes?

Ans: Object Class.

Q37. What is the full form of JVM?

Ans: Java Virtual Machine.

Q38. Is “exit” a keyword in Java?

Ans: No, there is no such keyword in Java.

Q39. Provide the exception handling keywords available in Java

Ans: There are three exception handling keywords available in Java which are try, catch and finally.

Q40. Can you create the object of an abstract class?

Ans: No, objects cannot be created for an abstract class.

Q41. Write one indefinite loop for Java.

Ans: for (;;) {}

Q42. What are the types of Access Modifier?

Ans: Default, Public, Private and Protected are the four types of Access Modifier.

Q43. Who created Java?

Ans: Java was created by James Coscough in Sun Microsystem in 1995.

Q44. Name two types of constructor in Java.

Ans: The Two types of constuctors in Java are:

  • 1. Default Constructor
  • 2. Parameterized Constructor

Q45. What do you understand about Web Container?

Ans: Web Container is a combination of both JSP and Servlet.

Q46. State two types of Typecasting.

Ans: The two types of Typecasting include Implicit and Explicit.

Q47. Can you start a dead book again? How?

Ans: No, a dead book cannot be started again.

Q48. What are the two searching techniques in Java?

Ans: The two searching techniques in Java are: Binary Searching and Linear Searching.

Q49. What do you mean by Object Cloning?

Ans: It can be used to create an exact copy of an object.

Q50. What is the full form of JAXP?

Ans: JAXP stands for Java API for XML Processing.

Q51. What is final in java?

Ans: A final is a keyword used for declaring any variable as final.

We hope that these questions will help you crack the Java Interview process and you would get your desired job. For more details on interview-related questions, you must stay connected with our website.


You Might Also Like