JAVA Interview Questions and Answers




JAVA Interview Questions and Answers Online Training

Enroll Today

Top JAVA Interview Questions and Answers - 2021 [UPDATED]

Are you looking for JAVA Interview Questions and Answers? Than you are at the Right Place. Browse through Popular and Most Asked Interview Questions for JAVA.  There is a Huge Demand for JAVA Professionals in the Market. These Questions are suitable for both Freshers and Experienced Professionals and are based on Trending Topics and as per Current Industry Requirements.

Master These Topics and Increase your Chances in cracking JAVA Interviews like a pro and Secure your Dream Job Today.

JAVA Interview Questions and Answers

  • 28 Questions

Java is a platform-independent, object-oriented, portable, multi-thread, high-level programming language. The collection of objects is considering as Java. We use Java for developing lots of websites, games and mobile applications. For high performance, Java uses Just in time compiler.

Serialization converts an object to a stream of bytes for safety purposes. We can save it as a file, store in DB or send it by the network. We can also recreate the state of an item when needed.

JVM helps the computer to run the Java program or other languages. It acts as a run-time engine. Java code is compiled into bytecode to run on any computer.

It is an instant and special method having the same name as the class. A constructor can be overloaded and a section of code to load newly created objects. If a constructor is created with a parameter then another constructor can be created without a parameter.

A name for a memory location is variable. And it is called a basic unit of storage in a program. You can change the stored value during the program execution. Local variables Instant variables Static variables

Classloader is a Java runtime environment to load Java classes into Java virtual machine. It loads class files from the network, file system, and other sources. In java, there is 3 built-in classloader. Extension System/application Bootstrap

A wrapper class wraps or contains primitive data types. The Java primitives change into the reference types. It contains a field when we create an object. Primitive data types are stored in this field. Thus a primitive value is also be wrapped.

The collection of classes, sub-packages, and interfaces are bundled together is called packages. We can modularize the code and optimize its reuse. The code can also be imported by other classes and reused. It helps to remove name clashes. Provide access protection to manage the code. The classes and interfaces are easily maintained because of proper structure. It contains hidden classes to use within the packages.

IT is a program to help in changing the Java bytecode into instructions. It improves the performance of Java applications at the run time and known as the integral parts of the Java Runtime Environment.

The special keywords in Java are access modifiers. Constructor, variable, scope of a class, data member or method is restricted. Default, private, protected and the public are four types of access modifiers.

It implicit memory management and destroy the unused objects to relieve the memory. It automatically removes the unreferenced objects to make the memory efficient. There are 4 types of garbage collectors. Serial garbage G1 garbage CMS garbage Parallel garbage

A thread, A scheduler executes independently. All programs having one thread is called the main thread. JVM creates the main thread when the program starts its execution. The main ( ) of the program is invoked by the main thread. Thread is created – By implementing the Runnable interface and extending the thread.

Finally block always executes a set of statements. It is with a try block of any exception occurs or not. It does not execute the program by calling System.exit( ) or by a fatal error.

Synchronization, it keeps all concurrent threads in execution. Memory consistency errors are avoided by synchronization. Execution of multiple threads accesses the same objects and fields. The thread holds the monitor when the method is considered as synchronized.

Final cannot be overridden, inherited or change. For restrict the class, variable and method. Finally, is used for putting important code and executed the exception is handled or not. Finalize is for cleaning up processing before the object is collected in the garbage.

In method overloading signature must be different. The same class method shares the same name. Every single method should be the indifferent number of parameters or different orders or types of parameters. For “adding” or “extending” and known as a compile-time polymorphism.

Method Overriding is run-time polymorphism having the same signature. Inheritance is required in Method Overriding. It is used to change existing behavior. The subclass has the same method od same number, name, parameters, return type.

In Java, the static method belongs to the class and access only static data. It calls only other static methods and directly accessed by the class name. To define variables, static is used.

The programming paradigm based on data and methods is called object-oriented programming. Paradigm incorporates the advantages of reusability and modularity. Objects are instances of classes to interact with one another. It designs programs and applications.

A real-time entity of some behavior and state is called an object. It is an instance of a class with instance variables. The new keyword is for creating the object of the class.

JavaScript, VBScript is an object-based language and has in-built objects. All the concepts of OOPs such as polymorphism and inheritance are not followed by object-based languages.

Default constructor – It is used to perform the task on object creation and to initialize the instance variable with default values. The constructor does not accept any value. If no constructor is defined in the class, then a default constructor is invoked implicitly by the compiler. Parameterized constructor – This constructor accepts the arguments. It initializes the instance variables with the given values.

We can print the values by using the constructor, to allow the values of one object to other and the design of clone. In Java, there is no copy constructor.

The Java method is invoked explicitly and is to disclose the nature of an item, it has an entry. Its name is not the same as the class name. It is not given by the finder.

The static variable belongs to the class and makes the memory-efficient of the program. It refers to the common property of all objects. At the moment when class is loading, it gets the memory in the department field.

Aggregation is described as a has-a relationship and has an entity reference. And having a relationship between two classes. The weak relationship is represented by aggregation.

The Super keyword is a hint variable is to mention at once parent class item with the concept of inheritance, the keyword comes into the picture. It appeals soon the parent class technique and constructor. Refers directly parent class instance variable. It is used to initialize the base class variables.

In Java method overriding is when a subclass has the specific implementation or the same method as in the parent class. Rules It should have the same name and signature as in the parent class. IS-A relationship should be in between two classes. Uses For runtime polymorphism To give the specific implementation already provided by its superclass.