• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Interview Questions Answers

Question - 31 : - What are synchronized methods and synchronized statements?

Answer - 31 : - Synchronized methods are methods that are used to control access to a method or 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.

Question - 32 : - How can a GUI component handle its own events?

Answer - 32 : - A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Question - 33 : - What is the difference  between a Window and a Frame?

Answer - 33 : - 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 heavy weight.

Question - 34 : - What is the output from System.out.println("Hello"+null);?

Answer - 34 : - Hellonull

Question - 35 : - What are the drawbacks of inheritance?

Answer - 35 : - Since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation. In addition, the inheritance may make peers hardly understand your code if they don't know how your super-class acts and add learning curve to the process of development. Usually, when you want to use a functionality of a class, you may use subclass to inherit such function or use an instance of this class in your class. Which is better, depends on your specification.

Question - 36 : - What is the difference between shallow copy and deep copy?

Answer - 36 : - Shallow copy shares the same reference with the original object like cloning, whereas the deep copy get a duplicate instance of the original object. If the shallow copy has been changed, the original object will be reflected and vice versa.

Question - 37 : - Does the code in finally block get executed if there is an exception and a return statement in a catch block?

Answer - 37 : - If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(1) statement is executed earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block.

Question - 38 : - What is the Locale class?

Answer - 38 : - The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

Question - 39 : - Why Java does not support pointers?

Answer - 39 : - Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. This is why Java and C-sharp shine.

Question - 40 : - How does Java handle integer overflows and underflows?

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

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners