• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Interview Questions Answers

Question - 11 : - What does a well-written OO program look like?

Answer - 11 : - A well-written OO program exhibits recurring structures that promote abstraction, flexibility, modularity and elegance.

Question - 12 : - What is multi-threading?

Answer - 12 : - Multi-threading means various threads that run in a system.

Question - 13 : - What is an Iterator interface?

Answer - 13 : - The Iterator interface is used to step through the elements of a Collection.

Question - 14 : - This class (IncrementImpl) will be used by various threads concurrently; can you see the inherent flaw(s)? How would you improve it?

Answer - 14 : - public class IncrementImpl { private static int counter = 0; public synchronized void increment() { counter++; } public int getCounter() { return counter; } } The counter is static variable which is shared by multiple instances of this class. The increment() method is synchronized, but the getCounter() should be synchronized too. Otherwise the Java run-time system will not guarantee the data integrity and the race conditions will occur. The famous producer/consumer example listed at Sun's thread tutorial site will tell more. one of solutions public class IncrementImpl { private static int counter = 0; public synchronized void increment() { counter++; } public synchronized int getCounter() { return counter; } }

Question - 15 : - What is the ResourceBundle class?

Answer - 15 : - The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Question - 16 : - What state does a thread enter when it terminates its processing?

Answer - 16 : - When a thread terminates its processing, it enters the dead state.

Question - 17 : - What are the Object and Class classes used for?

Answer - 17 : - The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.

Question - 18 : - Why would you use a synchronized block vs. synchronized method?

Answer - 18 : - Synchronized blocks place locks for shorter periods than synchronized methods.

Question - 19 : - When is the ArrayStoreException thrown?

Answer - 19 : - When copying elements between different arrays, if the source or destination arguments are not arrays or their types are not compatible, an ArrayStoreException will be thrown.

Question - 20 : - Which method of the Component class is used to set the position and size of a component?

Answer - 20 : - setBounds()

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners