0% found this document useful (0 votes)
100 views

Java Interview Questions - Answers

This document contains 20 Java interview questions and their answers covering topics such as: 1. The advantages of Java including being object-oriented, platform independent, and secure. 2. The differences between objects and classes, and how classes act as blueprints for objects. 3. The roles of the JVM, JRE, and JDK in running Java programs. 4. Core Java concepts like looping, inheritance, polymorphism, and the 'this' keyword.

Uploaded by

Apurba Panja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Java Interview Questions - Answers

This document contains 20 Java interview questions and their answers covering topics such as: 1. The advantages of Java including being object-oriented, platform independent, and secure. 2. The differences between objects and classes, and how classes act as blueprints for objects. 3. The roles of the JVM, JRE, and JDK in running Java programs. 4. Core Java concepts like looping, inheritance, polymorphism, and the 'this' keyword.

Uploaded by

Apurba Panja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Interview Questions & Answers

1. What do you think are the advantages of using Java?


i) Java is an object oriented language. This allows us to create modular
programs and reusable code. In other words we can break the code into
small pieces and reuse it whenever it is needed.

ii) Being an compiled language java is comparatively faster than other


interpreted languages.

iii) Java is platform independent. We can run the same code across different
platforms with only the JVM.

iv) Java supports multithreading, it has the potential for a program to perform
several tasks at the same time.

v) Java is robust and secured.

2. What do you understand about Objects and Class?


In object-oriented paradigm, object and class are core concepts. This
paradigm helps us to keep the codes organized. But what are objects and
classes? In programming terms class is a blueprint of an object. We
developers bind attributes and functionality in a single unit, give it a name
and call it a class. Now we instantiate the class to create multiple objects.
Objects treat like and real world objects like pen,drone, camera or even a cat
or dog.

3. What are JVM, JDK and JRE?


JVM stands for Java Virtual machine. It is an abstract machine that enables a
computer to run Java programs. Literally it takes the java bytecode and
converts it into native machine code.

JRE is a software package that contains Java class libraries and JVM in
order to successfully run a Java Application.

JDK is a software development kit required to develop applications in Java.


When we download JDK, JRE comes along with it. JDK also contains Java
compiler, JavaDoc and Java debugger helps to compile and debug a java
program.

JDK = JRE + Compiler + Debugger + JavaDoc


JRE = JVM + Java Class libraries

4. What is meant by looping?


In programming, looping is a feature that facilitates the execution of a set of
statements repeatedly until a given condition is true.
Java has three looping features for, while and do-while.

5. What is the difference between method overloading and method


overriding?
A Java class can have more than one method with the same name. This
feature is called method overloading. An overloaded method must have
different types of parameters or different numbers of parameters.
On the other hand, when we inherit a class, the subclass has all the methods
and variables of the parent class but we can write the inherited methods in
the sub class again so that it has a specific functionality. This is called
method overloading.

6. What is inheritance?
In object oriented programming inheritance is a powerful feature which allows
a class to inherit all the methods and attributes from another class. The class
that inherits from another is called child-class or subclass and which it
inherits from is called parent or super class. In java we use ‘extends’
keywords for inheritance.

7. Is it possible to restrict inheritance?


Yes, we can restrict inheritance by declaring a class as final. In that case use
the final keyword.

8. What do you mean by content negotiation?

9. What is WORA?
This is a term or an acronym which stands for Write once run anywhere. The
term refers to a program's ability to run across all platforms. This slogan was
created by Sun Microsystem to illustrate the cross-platform benefits of Java.

10. What is the function of ClassLoader?


The ClassLoader is responsible for loading Java classes during runtime
dynamically to the JVM. ClassLoader is a part of JRE. JVM does not need to
know where the underlying files are; the classloader does this job.

11. What are the static methods and static variables?


The static methods and static variables are associated with a class, they are
called with the class name and a dot operator. A static method cannot call a
non-static method and it cannot access or change an instance variable.

12. What do you understand about OOP?


OOP is a programming paradigm, it’s a way to think about our code to
structure our code inorder to make it easily manageable and extensible.
In OOP everything is an object which is an instance of class.
The four main pillars in Object oriented our programming are:
Encapsulation, Inheritance, Abstraction, and Polymorphism.

(….with example)

13. Is there a difference between Object Oriented and Object-Based


language?
In object oriented programming do not have in-built objects on the other hand
object based languages have in-built objects. For example Java or Python
don’t have any built-in objects. All we need to do is create objects when we
need to but language like JavaScript has objects (window object).

14. What is the function of a constructor?


The function of a constructor method is to initialize an object.

15. How do you use the ‘this’ keyword?


The ‘this’ keyword represents an instance of a class. It is used inside a class
to access methods and variables of the class.

16. What is aggregation?


When an object contains a reference of another object, it is termed as
aggregation. In Java aggregation represents a HAS-A relationship.

17. What is the purpose of composition?


Composition represents the HAS-A relationship between objects where one
object’s existence depends on another object. Let’s have an example, think
about a class object which has an engine, wheel, music player etc. but what’s
about a car without an engine or wheel? This is called composition.
The purpose here is to reuse codes. Java does not support multiple
inheritance, using composition we can achieve pretty much the same things.

18. What is annotation?


Annotation is a tag used to provide some additional information about a
class, interface and method. Annotations start with a “@” sign.

19. What is enumeration?


It is an interface we can use to access the original data structure from which
the enumeration is obtained.

20. What is the function of the Synchronized block?


Synchronized block is used to lock an object for any shared resources.
Scope of the synchronized block is smaller than the method.

You might also like