Top Java Interview Questions with Answers..






Hello Visitors! I have posted this post to help with Some Java questions which can or will be asked in the Interview for Automation testing.


Q. What is JAVA?
A: - Java is a high-level programming language and is platform-independent.
Java is a collection of objects. It was developed by Sun Microsystems. There are a lot of applications, websites, and Games that are developed using Java.

Q. What do you mean by platform independence of Java?
A: - Platform independence means that you can run the same Java Program in any Operating System. For example, you can write a java program in Windows and run it in Mac OS.

Q. Is Java a value-based or reference-based?
A: - Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.

Q. JVM is a dependent or independent platform?
A: - JVM is platform dependent because it takes java byte code and generates byte code for the current operating system. So Java software is platform dependent but Java language is platform-independent because the different operating system has different JVMs.

Q. Why Java is not pure Object Oriented language?
A: - Java is not said to be pure object-oriented because it supports primitive types such as int, byte, short, long, etc. I believe it brings simplicity to the language while writing our code. Obviously, java could have wrapper objects for the primitive types but just for the representation, they would not have provided any benefit.
As we know, for all the primitive types we have wrapper classes such as Integer, Long, etc that provide some additional methods.

Q. What is Object class?
A: - The Object class is the parent class of all the classes in java by default. In other words, it is the topmost class of java. The Object class is beneficial if you want to refer to any object whose type you don't know. Notice that the parent class reference variable can refer to the child class object, known as upcasting.

Q. What is the parent or base class of all the classes in Java?
A: - Object class is the super base class of all Java classes. Every other Java classes descend from Object.

Q. Which class is the superclass of all classes?
A: - java.lang.Object is the root class for all the java classes and we don’t need to extend it.

Q. What is a Class?
A: - Class is a blueprint. It is the structure where we can define variables and methods to utilize by objects.