300+ [LATEST] Java Developer Interview Questions and Answers

Q1. What Is Collections Api In Java Programming?

The Collections API is a set of classes and interfaces that support operations on collections of objects.

Q2. Described The Purpose Of The Wait(), Notify(), And Notifyall() Methods In Java Programming?

The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other in Java Programming.

Q3. What Must Class Do To Implement An Interface In Java Programming?

It must provide all of the methods in the interface and identify the interface in its implements clause.

Q4. Can You Please Explain The Difference Between Font And Fontmetrics Classes In Java Programming?

The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.

Q5. Does The Garbage Collection Guarantee That A Program Will Not Run Out Of Memory?

No, it doesn’t. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

Q6. What Is Iterator Interface In Java Programming?

The Iterator interface is used to step through the elements of a Collection.

Q7. Can You Please Explain The Difference Between Boolean & Operator And The && Operator In Java Programming?

If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

Operator & has no chance to skip both sides evaluation and && operator does. 

Q8. Described Gregorian Calendar Class In Java Programming?

The GregorianCalendar provides support for traditional Western calendars in Java Programming.

Q9. Name Primitive Java Types?

The primitive types are byte, char, short, int, long, float, double, and boolean.

Q10. Which State Does A Thread Enter When It Terminates Its Processing In Java Programming?

When a thread terminates its processing, it enters the dead state.

Q11. Can You Please Explain The Difference Between Yielding And Sleeping In Java Programming?

When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Q12. What Is Simpletimezone Class In Java Programming?

The SimpleTimeZone class provides support for a Gregorian calendar in Java Programming.

Q13. Which Modifiers May Be Used With An Inner Class That Is A Member Of An Outer Class In Java Programming?

A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

Q14. Described Trient Variable?

A trient variable is a variable that may not be serialized.

Q15. Is The Size Of A Keyword In Java Programming?

The sizeof operator is not a keyword in Java Programming.

Q16. Define Map Interface In Java Programming?

The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.

Q17. Does Java Handle Integer Overflows And Underflows?

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

Q18. How Many Bits Are Used To Represent The Unicode, Ascii, Utf-16, And Utf-8 Characters In Java Programming?

Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Q19. Described The Purpose Of System Class In Java Programming?

The purpose of the System class is to provide access to system resources in Java Programming.

Q20. Which Three Ways In Which A Thread Can Enter The Waiting State In Java Programming?

A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object’s lock, or by invoking an object’s wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Q21. Described Synchronized Methods And Synchronized Statements In Java Programming?

Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method’s object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Q22. Which Containers Is Use A Border Layout As Their Default Layout?

The window, Frame and Dialog classes use a border layout as their default layout in Java Programming.

Q23. What Is Vector Class In Java Programming?

The Vector class in Java Programming provides the capability to implement a growable array of objects.

Q24. Which Classes Of Exceptions May Be Caught By A Catch Clause In Java Programming?

A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

Q25. Can You Please Explain The Difference Between Static And A Non-static Inner Class In Java Programming?

A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

Q26. Described Object’s Lock And Which Object’s Have Locks In Java Programming?

An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

Q27. Define Llist Interface In Java Programming?

The List interface provides support for ordered collections of objects.

Q28. Can Anonymous Class Be Declared As Implementing An Interface And Extending A Class In Java Programming?

An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Q29. Define Preferred Size Of A Component In Java Programming?

The preferred size of a component is the minimum component size that will allow the component to display normally.

Q30. What Is The Purpose Of Finally Clause Of A Try-catch-finally Statement In Java Programming?

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Q31. Described Wrapped Classes In Java Programming?

Wrapped classes are classes that allow primitive types to be accessed as objects.

Q32. Which Component Subclasses That Support Painting In Java Programming?

The Canvas, Frame, Panel, and Applet classes support painting.

Q33. Described Properties Class In Java Programming?

The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

Q34. Described Heavy Weight Components Mean In Java Programming?

Heavy weight components like Abstract Window Toolkit (AWT), depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface.

For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavyweight.

Q35. How Observer And Observable Used In Java Programming?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.

Q36. Which Containers Use Flowlayout As Their Default Layout In Java Programming?

The Panel and Applet classes use the FlowLayout as their default layout.

Q37. What Happens When A Thread Cannot Acquire Lock On An Object In Java Programming?

If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object’s lock, it enters the waiting state until the lock becomes available.

Q38. If The A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed In Java Programming?

A class that is declared without any access modifiers is said to have package or friendly access. This me that the class can only be accessed by other classes and interfaces that are defined within the same package.

Q39. Which Class Is Superclass For Every Class In Java Programming?

Object class is the superclass for every class in Java Programming.

Q40. Suppose If A Method Is Declared As Protected, Where May The Method Be Accessed In Java Programming?

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Q41. When An Object Reference Be Cast To An Interface Reference In Java Programming?

An object reference be cast to an interface reference when the object implements the referenced interface.

Q42. How To Write A Loop Indefinitely In Java Programming?

for(;;)-for loop; while(true)-always true, etc.

Q43. Can A Lock Be Acquired On Class In Java Programming?

Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.

Q44. What Is The Purpose Of Runtime Class In Java Programming?

The purpose of the Runtime class is to provide access to the Java runtime system in Java Programming.

Q45. Which Container Method Is Used To Cause Container To Be Laid Out And Redisplayed In Java Programming?

validate();  : Container method is used to cause a container to be laid out and redisplayed in Java Programming.

Q46. Which Invokes A Thread’s Run() Method In Java Programming?

After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread’s run() method when the thread is initially executed.

Q47. What Advantage Do Java’s Layout Managers Provide Over The Traditional Windowing Systems?

Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java’s layout managers aren’t tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

Q48. Can You Please Explain The Difference Between Window And A Frame In Java Programming?

The Frame class extends Window to define a main application window that can have a menu bar.

Q49. What Is Purpose Of Finalization In Java Programming?

The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

Q50. Described The Elements Of A Gridbaglayout Organized In Java Programming?

The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.