Advanced Java Interview Questions- Part 3

Advanced Java Interview Questions- Part 3Want to land a top tech job? Go through our 120+ Advanced Frequently asked Java Interview Questions for Jobseekers. Java is a key language for web apps, mobile development, and enterprise systems, with a large number of developers using it worldwide.

By equipping yourself with Java skills, you can earn a three-figure salary. As Java is now integrated with Cloud and AI, its demand is soaring. Skills like Spring boot, Spring Boot, microservices, Java 8 streams, concurrency, JPA, and Kubernetes are what employers seek for building robust systems.

Our interview questions bank will help you learn to tackle tough interview questions with ease. With over 120 questions, you can cover all important topics to impress hiring managers.

Answer:

A Java component’s preferred size is the minimum component size that allows the component to display normally.

Answer:

The setLayout() method is useful for specifying a container’s layout. For instance, setLayout(new FlowLayout()); will be set the layout as FlowLayout.

Answer:

The Collection API in Java is a set of classes & interfaces that support operation on the collections of objects. Those classes & interfaces are more powerful, flexible, & regular than the vectors, arrays, and hash tables, if replaced effectively.

Answer:

An Iterator interface is used as an alternative for enumerations in Java Collection. However, an Iterator differs from the enumerations in two ways:

  • It allows the caller to remove the given elements from a specified collection during the element’s Iteration.
  • Method names have been enhanced.

Answer:

Following are the differences between yielding & sleeping:

Yielding Sleeping
Yield causes the thread to rejoin the queue in the CPU. Sleep suspends thread from running for a specified time.
When a task is invoked in the yielding method, it returns to the ready state. When a task is invoked in the sleeping method, it returns to the waiting state.
Yielding facilitates the running thread into out of runnable state with the same priority. Sleeping is useful to delay the execution for a while.

Answer:

No, Java garbage collection does not guarantee that a program will not run out of memory. The central objective of garbage collection is to identify & discard those objects that are no longer required by the Java program so that their resources can be reused & reclaimed. An object needs to garbage collected when it is unreachable to the Java program. If there is insufficient memory required for a new object, then the garbage collector attempts to reclaim its memory by releasing the memory used by the objects with no references. However, if there’s still insufficient memory, the program will throw an ‘out of memory’ exception.

Answer:

A package statement is confined to appear as the first line in a source code file (excluding blank comments & lines).

Answer:

No, it is impossible to invoke the finalize() method of an object while it is reachable. However, the finalize() method may get invoked by other objects.

Answer:

  • Preemptive scheduling: Under this, the highest priority task gets executed until it enters the dead states or a higher priority task comes into existence.
  • Time slicing: Under this, a task gets executed for a predefined slice of time, then reenters the pool of ready tasks. Thereby, the scheduler decides which task should be executed next, based on priority and various other factors.

Answer:

Clipping refers to the process of confining paint operations to a limited shape or area. When displaying a large portion of a picture, certain parts of the image are inside, while the others are partially visible. The elements or lines that are partly visible need to be omitted, so we use clipping to decide the visible-invisible portion. Thereon, the visible part is selected & the invisible part is discarded.

Answer:

A native method is a method whose implementation is written in other languages such as C++ & C. The ‘native’ keyword is used before a method indicates that it is implemented in another language.

Answer:

Yes, the “for statement” can loop indefinitely.

Answer:

The order of precedence in Java determines the order of evaluating the operators in expressions. The order of associativity determines the evaluation of operators with the same precedence.

Answer:

A task’s priority in Java is an integer value that determines the relative order, wherein it needs to executed with respect to other tasks. The scheduler first schedules higher priority tasks & later schedules lower priority tasks.

Answer:

The java.awt.AWTEvent class is the top class in the AWT event hierarchy.

Answer:

The initial state of a thread is the “Ready” state after it has been started & created; that stage signifies the thread is ready for task execution; thereon, it can be running.

Answer:

The central purpose of finalization is to allow an unreachable object to perform a cleanup processing before the object’s garbage collection.

Answer:

Both the “&” and “&&” operators are used to evaluate the conditional statements. The & operator is a bitwise operator, while && is a logical operator. The fundamental difference between the & and the && operator is that the former evaluates both sides of the expression. On the other hand, the latter evaluates only the left side of the expression to acquire final results.

Basis of Comparison & &&
Operator & is a Bitwise Operator. && is a Logical Operator
Evaluation & operator evaluates both right & the left side of an expression. && only evaluates the left side of an expression.
Operates on & operates on “Boolean datatype” & “bits”. && only operates on “Boolean datatype.”
Use && operator is used to check the logical condition and mask off certain bits like parity bits. && operator is only used to check logical conditions.

Answer:

Gregorian Calendar class provides an implementation of the abstract Calendar class. It renders us multiple methods to access & manipulate the current minute, second, hour, day of the week, week of the year, etc.

Answer:

validate() method causes a container to be laid out & redisplayed in Java.