Java Web Dynpro Interview Questions & Answers
1. What Is The Purpose Of Garbage Collection In Java, And When Is It Used?
Ans :
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
2. What If The Main Method Is Declared As Private?
Ans :
The program compiles properly but at runtime it will give “Main method not public.” message.
3. What If I Write Static Public Void Instead Of Public Static Void?
Ans :
Program compiles and runs properly.
4. What If I Do Not Provide The String Array As The Argument To The Method?
Ans :
Program compiles but throws a runtime error “NoSuchMethodError”.
5. What Is The First Argument Of The String Array In Main Method?
Ans :
The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name
6. How Can One Prove That The Array Is Not Null But Empty Using One Line Of Code?
Ans :
Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a Null Pointer Exception on attempting to print args.length.
7. Describe Synchronization In Respect To Multithreading?
Ans :
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.
8. What Are Pass By Reference And Pass By Value?
Ans :
Pass by Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.
9. What Is Hashmap And Map?
Ans :
Map is Interface and Hashmap is class that implements that.
10. Difference Between Vector And Arraylist?
Ans :
Vector is synchronized whereas arraylist is not.
11. Difference Between Swing And Awt?
Ans :
AWT are heavy-weight components. Swings are light-weight components. Hence swing works faster than AWT.
12. What Is Static In Java?
Ans :
Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, if the original method was not declared final. However, you can’t override a static method with a non-static method. In other words, you can’t change a static method into an instance method in a subclass.
13. What Is Final?
Ans :
A final class can’t be extended ie., final class may not be subclasses. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant)
14. What Is The Difference Between Declaring A Variable And Defining A Variable?
Ans :
In declaration, we just mention the type of the variable and it’s name. We do not initialize it. But defining means declaration + initialization. e.g String s; is just a declaration while String s = new String (“abcd”); Or String s = “abcd”; are both definitions.
15. Objects Are Passed By Value Or By Reference?
Ans :
Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object.
16. What Is Serialization?
Ans :
Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.
17. How Do I Serialize An Object To A File?
Ans :
The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the Object Output Stream which is connected to a file output stream. This will save the object to a file.
18. Which Methods Of Serializable Interface Should I Implement?
Ans :
The serializable interface is an empty interface; it does not contain any methods. So, we do not implement any methods.
19. What Is The Common Usage Of Serialization?
Ans :
Whenever an object is to be sent over the network, objects need to be serialized. Moreover, if the state of an object is to be saved, objects need to be serilazed.
20. What Is Externalizable Interface?
Ans :
Externalizable is an interface which contains two methods read External and write External. These methods give you a control over the serialization mechanism. Thus, if your class implements this interface, you can customize the serialization process by implementing these methods.
For more Click Here
For Course Content Click Here