JAVA Interview Questions


What is java?

Java is a high level, general purpose, platform independent; object oriented programming language developed by sun microsystem in 1995. Its fast and secure methods used for developing various desktop and mobile applications by using an execution engine and a compiler. There are number of websites cannot work unless they use java. Java is also used for scientific computing applications, creating enterprise soft wares and big data analytics. Java code is secure as it is unable to read by a human because it is converted into bytecode after compilation.

What are some core features of java?

Here are some core features of java.

    Object oriented

    In java everything is an object having some distinct data and behavior. Java posseses basic terminologies of OOP on the basis of which it is called object oriented programming language.

    • Object
    • Class
    • Inheritance
    • Polymorphism
    • Abstraction
    • Encapsulation

    Secure

    Java provides run time, library and explicit security which secure data from being hacked. Security features such as static type checking and run time checking helps to avoid virus attack.

    Multi Threaded

    It enables multitasking at the same time by executing two or more threads and also known as thread based multitasking. They save memory by allocating same memory area.

    Portable

    Java code is executable on all platforms. When javac compiler is used; the bytecode is saved with file extension.class.

    High performance

    Java uses a good compiler named as ‘’just in time’’ which enables its high performance. It makes the code run smoothly and much better than other traditional programming languages.

What is inheritance in java?

Attributes and methods inherited from one class to another is known as inheritance. The class which inherits the properties is called the sub-class and from which properties are inherited is called parent class or the super class. Inheritance syntax in java is;
Class derived_class extends base_class
{
//methods
//fields
}
In java there are two types of inheritance.

There’s a concept of reusability in inheritance by which same code of the previous can be used in the next derived class so basically fields and methods of the existing class is reused inderived class.

Differentiate between method overriding and overloading?

Method overriding Method overloading
It provides specific implementation of the method It is used to increase the readability of the program.
In method overriding methods and functions must have the same name and same signatures. In method overloading methods have the same name and different signatures.
It is an example of run time polymorphism. It is an example of compile time polymorphism.
Inheritance is always required in method overriding. Inheritance may or may not be required in method overloading.
It occurs in two classes. It is performed only within a class.
Static methods cannot be overridden. Static methods can be overloaded.
It gives better performance. It doesn’t give better performance comparing to method overriding.
It should have same argument list. It should have different argument list.

Method overriding and overloading is different from each other on the basis of various features. Here’s a list of differentiating features that make both of them distinctive.

What is an array? Array i

Array is a basically homogenous data structure or group of a fixed number of items. Another important aspect of an array is that multiple values of the same kind can be stored in an array, whereas we cannot store different values in a single array. The best illustration of this is that an array of int type can only store integer values.