Interview Questions - Java Basics
Why should I learn to solve Java Basics technical interview questions?
Learn and practise solving Java Basics technical interview questions and answers to enhance your skills for clearing technical interviews, HR interviews, campus interviews, and placement tests.
Where can I get technical Java Basics technical interview questions and answers with explanations?
IndiaBIX provides you with lots of fully solved Java Basics technical interview questions and answers with a short answer description. You can download Java Basics technical interview questions and answers as PDF files or e-books.
How do I answer Java Basics technical interview questions from various companies?
You can answer all kinds of Java Basics technical interview questions by practising the given exercises (short answer type). You can also find the frequently asked Java Basics technical interview questions with answers from various companies, such as TCS, Wipro, Infosys, CTS, IBM, etc.
The important difference between constructors and methods are:
Constructors create and initialize objects that don't exist yet, while methods perform operations on objects that already exist.
Constructors can't be called directly; they are called implicitly when the new keyword creates an object. Methods can be called directly on an object that has already been created with new keyword.
Constructors must be named with the same name as the class name. They can't return anything, even void (the object itself is the implicit return). Methods must be declared to return something, although it can be void.
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources.
Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.
Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain static data.
Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.