1. What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.
2. What is the purpose of garbage collection in Java, and when is it used?
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
3. Describe synchronization in respect to multithreading.
Without synchonization, 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.
4. What is an abstract class?
Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.
5. What is the difference between an Interface and an Abstract class?
An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
6. Explain different way of using thread?
7. What is an Iterator?
Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.
8. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature. This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
What you get by default ie, without any access modifier (ie, public private or protected). It means that it is visible to all within a particular package.
9. What is static in java?
A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.
10. What is final class?
11. What if the main() method is declared as private?
12. What if the static modifier is removed from the signature of the main() method?
13. What if I write static public void instead of public static void?
14. What if I do not provide the String array as the argument to the method?
15. What is the first argument of the String array in main() method?
16. If I do not provide any arguments on the command line, then the String array of main() method will be empty or null?
17. How can one prove that the array is not null but empty using one line of code?
18. What environment variables do I need to set on my machine in order to be able to run Java programs?
19. Can an application have multiple classes having main() method?
Hence there is not conflict amongst the multiple classes having main() method.
20. Can I have multiple main() methods in the same class?
No comments:
Post a Comment
Note: only a member of this blog may post a comment.