Java Interview Questions & Answers

Showing 10 of 301 questions | Page 19

Technical interview questions and answers are essential for any Java Interview because Java is one of the most widely used programming languages in software development. Companies expect candidates to know OOP concepts, multithreading, exceptions, JDBC, collections, and real-time coding questions. Java interviews are commonly part of campus placements and software development roles in companies such as TCS, Infosys, Wipro, Cognizant, and Accenture. For freshers and job seekers, understanding Java concepts clearly makes it easier to clear technical rounds, online coding tests, and project discussions. This guide includes the most important and frequently asked Java interview questions with detailed explanations to help you prepare efficiently. These questions will help you gain confidence during software developer interviews and competitive placement tests.

Java professionals should deepen their expertise through J2EE development  concepts and data structures  fundamentals 

Showing 10 of 301 questions

181. Difference between Swing and AWT?

AWT are heavy-weight components. Swings are light-weight components. Hence swing works faster than AWT.

182. What is the difference between a constructor and a method?

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

183. What are Iterators?

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.

184. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.

public : Public class is visible in other packages, field is visible everywhere (class must be public too) private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature. This access is provided even to subclasses that r

185. What is an abstract class?

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.

186. What is static in java?

Static means one per class, not one for each object no matter how many instance of a class might exist.This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a super class can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't overr

187. What is final class?

A final class can't be extended. i.e. final class may not be subclasses. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

188. What if the main method is declared as private?

The program compiles properly but at runtime it will give "Main method not public." message.

189. What if the static modifier is removed from the signature of the main method?

Program compiles. But at runtime throws an error "NoSuchMethodError".

190. What if I write static public void instead of public static void?

Program compiles and runs properly.
Questions and Answers for Competitive Exams Various Entrance Test