Home ยป Java Interview Questions
Technology

Java Interview Questions

Java Interview Questions
Java Interview Questions
Here are some interview questions asked related to Java. 1. Distinguish between StringBuffer and StringBuilder in Java programming. 2. Differentiate between JDK, JRE, and JVM.

Java Interview Questions

1. Distinguish between StringBuffer and StringBuilder in Java programming.

StringBuffer

  • The storage area is a heap and modified easily.
  • StringBuffer methods are synchronized.
  • StringBuffer is thread-safe.
  • The performance is very slow.

StringBuilder

  • Storage is a heap and can be modified.
  • StringBuilder is non-synchronized.
  • String Builder is fast as it is not thread-safe.
  • The performance is very fast.

2. Differentiate between JDK, JRE, and JVM.

  • JVM stands for Java Virtual Machine which provides the runtime environment for Java bytecodes to be executed.
  • JRE (Java Runtime Environment) includes the sets of files required by JVM during runtime.
  • JDK (Java Development Kit) consists of JRE along with the development tools required to write and execute a program.

3. Compare overloading with overriding.

Overloading refers to the case of having two methods of the same name but different properties; whereas, overriding occurs when there are two methods of the same name and properties, but one is in the child class and the other is in the parent class.

4. Can we execute any code, even before the main method? Explain.

Overloading refers to the case of having two methods of the same name but different properties; whereas, overriding occurs when there are two methods of the same name and properties, but one is in the child class and the other is in the parent class.

5. How can we restrict inheritance for a class?

  1. By using the final keyword
  2. If we make all methods final, then we cannot override that
  3. By using private constructors
  4. By using the Javadoc comment (“//”)
Java Interview Questions

6. What are the advantages of JSON over XML?

  1. JSON is lighter and faster than XML.
  2. It is easily understandable.
  3. It is easy to parse and convert to objects for information consumption.
  4. JSON supports multiple data types-string, number, array, or Boolean-but XML data are all strings.

7. Differentiate between this() and super() in Java.

This

  • Represents the present instance of a class
  • Calls the default constructor
  • Used to point to the current class instance

Super

  • Represents the current instance of the parent class
  • Calls the base class constructor
  • Used to point to the instance of the superclass

8. Which API is provided by Java for operations on a set of objects?

Java provides a Collection API that provides many useful methods, which can be applied to a set of objects. Some of the important classes provided by the Collection API include ArrayList, HashMap, TreeSet, and TreeMap.

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

Default size = 0.75

Default capacity = initial capacity * load factor

10. What’s the base class of all exception classes?

Java.lang.throwable: It is the superclass of all exception classes, and all exception classes are derived from this base class.

11. Why do we use a vector class?

A vector class provides the ability to execute a growable array of objects. A vector proves to be very useful if you don’t know the size of the array in advance or if you need one that can change the size over the lifetime of a program.

Conclusion

In this post, we have seen Java Interview Questions. If you find this useful?, share this with your friends and follow the PublishSquare blog.

Further reading

78 INTERVIEW QUESTIONS FOR WEB DEVELOPMENT


About the author

Javith

I am Javith, a Content Writer and Marketer based in India.

I'm extremely good at one thing. And that's helping SaaS companies and small to large-sized businesses rank for their target keywords. I am highly skilled in SEO, copywriting, content marketing, and social media marketing.