Java interview Question-Part3

Posted on:
tags: , , , ,
Java interview Question-Part3

1. How does a try statement determine which catch clause should be used to handle an exception?
   When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.                    

2. Is Empty .java file a valid source file?
   An empty java file is perfectly a valid java source file.

3. Is delete a keyword in Java?
    Delete is not a keyword in Java. Java does not make use of explicit destructors the way C++ does.

4. How many objects are created in the following piece of code?
   MyClass c1, c2, c3;
   c1 = new MyClass ();
   c3 = new MyClass ();
   c1 and c3 are the two objects created. The c2 is only declared and not initialized.

5. What will be the output of the following statement?
   System.out.println ("1" + 5);

6. What will be the default values of all the elements of an array defined as an instance variable?
   If the array is of primitive data type then the elements of the array is initialized to default value. If the array is of reference type then it is initialized to NULL.

7. What are the different scopes for java variables?
  The different scopes for java variables are as follows:-

8. What is the default value of the local variables?
   When the local variables are not initialized explicitly the java compiler will not compile. And it will not initialize any default value for these local variable.

9. Can main method be declared final?
   The main method can be declared final with the addition of public static.

10. Does Java provide any constructor to find out the size of an object?
    There is no sizeof operator in java. It is not possible to determine the size of the object directly in java.

11. What is the Map interface?
    Map is an object which helps to map the keys to values. It is not possible to have duplicate keys. It is essential that each key should map to a one value.
Three Map implementations are

12. What is collection Views?
     Collection view is a metho that is used  to view map as a collection. This can be done in three ways:-

13. What is multimaps?
     Multimap is also like map which map key to multiple values. But there is no separate interface for multimap in Java since it is used quiet often. It’s much more simple to use map whose values to list instance as a multimap.

14. What is the SimpleTimeZone class?
     It is a subclass of Time zone which represent time zone that could be used with Gregorian calendar. It doesn’t handle any changes.
public class SimpleTimeZone
extends TimeZone

15. Is &&= a valid Java operator?
    no &= is a valid operator not &&=

16. Is "abc" a primitive value?
    Abc is a string object it is not primitive value.

17. What modifiers can be used with a local inner class?
    Some of the modifiers that can be used in the local inner class are as follows:-
    Static modifier

18. Can an unreachable object become reachable again?
    An unreachable object becomes reachable if the objects finalize() method is invoked, the object performs operation that causes the object to accessible.

19. What happens when you add a double value to a String?
    When double value is added to the string it becomes a string object.

20. What is Layout Managers?
    It is an object that implements LayoutManager  interface and also determines the position and size of the components within a container.
    Some of the task associated with layout manager are as follows:-
    Adding space between components
    Adding components to container
    Setting up layout manager

21. What is a compilation unit?
     A compilation unit is composed of two parts: an interface and an implementation. The interface contains a sequence of specifications, just as the inside of a sig … end signature expression. The implementation contains a sequence of definitions, just as the inside of a struct … end module expression

22. Which package is always imported by default?
     “Java.lang” is the package that imported by default.

23. What is numeric promotion?
     Numeric promotion is a conversion of numeric type of smaller to a larger numeric type,so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

24. Which arithmetic operations can result in the throwing of an ArithmeticException?
     Integer / and % can result in the throwing of an ArithmeticException.

25. What is the ResourceBundle class?

     It contains locale specific objects. If a program requires locale specific resources then the program can load resource bundle that is appropriate for the current user.
     Make it localized, and can be translated into different languages.
     Modification can be done easily.

Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 

No comments:

Post a Comment

< >