• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Interview Questions Answers

Question - 1 : - What is the difference between Swing and AWT components?

Answer - 1 : - AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components 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.

Question - 2 : - What is the difference between throw and throws keywords?

Answer - 2 : - The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that designates that exceptions may come out of the method, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw. If a class is declared without any access modifiers, where may the class be accessed? A class that is declared without any access modifiers is said to have package or friendly access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Question - 3 : - What is weak reference in Java ?

Answer - 3 : - A weak reference is one that does not prevent the referenced object from being garbage collected. You might use them to manage a HashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.

Question - 4 : - What is an IO filter?

Answer - 4 : - An IO filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

Question - 5 : - How many methods in the Externalizable interface?

Answer - 5 : - There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal().

Question - 6 : - Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

Answer - 6 : - Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.

Question - 7 : - What is the purpose of the wait(), notify(), and notifyAll() methods?

Answer - 7 : - The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.

Question - 8 : - Can we use System.arraycopy() method to copy the same array?

Answer - 8 : - Yes, you can. The source and destination arrays can be the same if you want to copy a subset of the array to another area within that array.

Question - 9 : - How to add menushortcut to menu item?

Answer - 9 : - If you have a button instance called aboutButton, you may add menu short cut by calling aboutButton.setMnemonic('A'), so the user may be able to use Alt+A to click the button.

Question - 10 : - What are the different types of inner classes?

Answer - 10 : - There are four different types of inner classes in Java. They are: a)Static member classes , a static member class has access to all static methods of the parent, or top-level, class b) Member classes, the member class is instance specific and has access to any and all methods and members, even the parent's this reference c) Local classes, are declared within a block of code and are visible only within that block, just as any other method variable. d) Anonymous classes, is a local class that has no name

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners