Java Interview Questions & Answers

Question: What is Java?


Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!

Question: Mention some features of Java?


Some of the features which play important role in the popularity of java are as follows:

a) Simple: Java is easy to learn. Eventhough Java is based on C++ , it was developed by eliminating poor programming practices of C++.

b) Object-Oriented: Java is a object oriented programming language. Everything in Java is an Object.

c) Portable: Java run time environment uses a bytecode verification process to make sure that code loaded over the network doesn’t violate Java security constraints.

d) Platform independent: Java is platform independent. Java is a write once, run anywhere language. Without any modifications, we can use a program in different platforms.

e) Secured: Java is well known for its security. It delivers virus free systems.

High Performance: Java enables high performance with the use of JIT (Just-In-Time) compilers

f) Multithreaded: Java Multithreaded features allows us to write programs that can perform many tasks simulatenously. Multithreading concept of Java shares a common memory area. It doesn’t occupy memory for each thread.

Question: What is the difference between Declaration and Definition in Java?


Declaration: If you just declare a class or method/function or variable without mentioning anything about what that class or method/function or variable looks like is called as declaration in Java.

Definition: If you define how a class or method/function or variable is implemented then it is called definition in Java.

When we create an interface or abstract class, we simply declare a method/function but not define it.

Question: What is an Object in Java?


An object is an instance of a class. Objects have state (variables) and behavior (methods).

Example: A dog is an object of Animal class. The dog has its states such as color, name, breed known as variables, and behaviors such as barking, eating, wagging her tail.


Question: What is a Class in Java?


A class can be defined as a collection of objects. It is the blueprint or template that describes the state and behavior of an object.


Question: What is Constructor in Java?


Constructor in Ja