• +91 9971497814
  • info@interviewmaterial.com

Java Questions Answers

Subjects

Java Interview Questions Answers

Question - 1 : - How to check two arrays to see if contents have the same types and contain the same elements?

Answer - 1 : - One of options is to use the equals() method of Arrays class. Arrays.equals(a, b); If the array types are different, a compile-time error will happen.

Question - 2 : - What do you understand by Synchronization?

Answer - 2 : - Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption. E.g. Synchronizing a function: public synchronized void Method1 () { // Appropriate method-related code. } E.g. Synchronizing a block of code inside a function: public myFunction (){ synchronized (this) { // Synchronized code here. } }

Question - 3 : - Can you call one constructor from another if a class has multiple constructors?

Answer - 3 : - Yes. Use this() syntax.

Question - 4 : - What is the difference between the Font and FontMetrics classes?

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

Question - 5 : - What is the difference between interface and abstract class?

Answer - 5 : - interface contains methods that must be abstract; abstract class may contain concrete methods. interface contains variables that must be static and final; abstract class may contain non-final and final variables. members in an interface are public by default, abstract class may contain non-public members. interface is used to "implements"; whereas abstract class is used to "extends". interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance. interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces. interface is absolutely abstract; abstract class can be invoked if a main() exists. interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces. If given a choice, use interface instead of abstract class.

Question - 6 : - Which package has light weight components?

Answer - 6 : - javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.

Question - 7 : - How is it possible for two String objects with identical values not to be equal under the == operator? How are this() and super() used with constructors?

Answer - 7 : - The == operator compares two objects to determine if they are the same objects in memory. It is possible for two String objects to have the same value, but located in different areas of memory.

Question - 8 : - What is the difference between preemptive scheduling and time slicing?

Answer - 8 : - Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

Question - 9 : - What method is used to specify a container's layout?

Answer - 9 : - The setLayout() method is used to specify a container's layout.

Question - 10 : - How to create a thread in a program?

Answer - 10 : - You have two ways to do so. First, making your class "extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method to start the thread.


Selected

 

Java Contributors

krishan
Naresh

Share your email for latest updates

Name:
Email:

Our partners