Technical Interview

Java Interview Questions



Several jobs require candidates to have a profound knowledge of Java. These Java Interview Questions have been designed specially to get you acquainted with the nature of questions that you may encounter during your interview for the subject of Java.

1. What is Java?

Java is a high level, robust, object-oriented, class-based, concurrent, secured and general-purpose programming language. It is used to create window-based applications, mobile applications, web applications and enterprise applications. Applications developed in Java are also called WORA (Write Once Run Anywhere). This implies that a complied Java application is expected to run on any other Java-enabled system without any adjustment. As of now, Java is one of the most popular programming languages in use particularly for client-server web applications.


2. What are the features of Java Programming language?

Some important features of Java programming language are given below:

  • Simple Language - It is easy to learn and its syntax is quite simple and easy to understand. The syntax Java is very much similar to C++. The complicated concepts of C++ are either removed or redesigned in a simple way in Java.
  • Object-Oriented Programming Language - It is an object-oriented programming language. Everything in Java is an object which has some data and behavior.
  • Portable Language - Java Byte code can be carried to any platform. It requires no implementation dependent features.
  • High Performance Language - Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler.
  • Platform Independent Language - Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language. On compilation Java program is compiled into byte code. This byte code is platform independent and can be run on any machine, plus this byte code format also provide security. Any machine with Java Run time Environment can run Java Programs.
  • Robust Language - Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time error checking and run time checking. But the main areas which Java improved were memory management and mishandled exceptions by introducing automatic garbage collector and exception handling.
  • Secure Language - When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system. Java program always runs in Java run time environment with almost null interaction with system OS, hence it is more secure.
  • Multi-Threading Language - Java multi-threading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multi-threading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.
  • Architectural Neutral Language - Compiler generates byte codes, which have nothing to do with a particular computer architecture, hence a Java program is easy to interpret on any machine.

3. What are the various access specifiers in Java?

Access specifiers defines the access type of the attributes and methods of the class. In Java, there are four types of access specifier.

  • public: Attributes and methods of the class are accessible from everywhere.
  • protected: Attributes and methods of the class are accessible within the package or all subclasses.
  • private: Attributes and methods of the class are accessible within the class only.
  • default (when no access specifier is specified): Attributes and methods of the class are accessible only within the package (package private).

4. What is a constructor?

A constructor is a special method of a class which automatically executed when a new object of the class is created. It allows the class to initialize object attributes and allocate memory.

The constructor function is declared just like a regular method except the class name and method name should be same without any return type.

When a constructor is not specified in a class, compiler generates a default constructor and inserts it into the code. However, it does not initialize object attributes.

//Creating class constructor
className(parameters) {
  statements;
}

5. What is constructor overloading?

With constructor overloading feature in Java, two or more constructors can be created in the same class with different definitions like different number and types of parameters. The compiler automatically calls the constructor which matches the argument passed while creating the object.


5