Docstoc

java interview

Document Sample
java interview Powered By Docstoc
					                             Java Interview Prepration

                         Java Interview Questions

1) What is an object?
   An object is an entity, which consist of attributes, behaviors and qualities that
describe the object.

2) What is a class?
   A class represents a collection of attributes and behaviors of object. It is the class
from which individual objects created.
For example:-
  Bicycle is a class that contain the following attributes
  Speed
  Gear

3) What is OOAD?
   OOAD stands for Object Oriented analysis and design. It is a methodology use to
analyze, design and develop applications. It visualizes the class and the objects.

4) What are the advantages of OOAD?
   * Reusability
   * Maintainability
   * Increase the performance of the system.

5) What is Data Abstraction?
   It is a process of listing the essential features, without implementation details. Data
abstraction is nothing but the extraction of the information which is required and ignoring
the other information.

6) What is Data Encapsulation?
   Data encapsulation or data hiding is a function that keeps the implementation details
hidden to the user. The user of the application is allowed to perform only limited task
with the class members that are hidden.

7) What is the difference between data abstraction and information hiding?
   Abstraction mainly focus on the outside view of the object whereas encapsulation
prevents the user from seeing the inside view where the properties and behavior of the
abstraction is implemented.

8) Why is java not 100% pure OOPS language?
   Java doesn‟t support 100% pure OOPS concept, since it support primitive datatype
like int, long, byte etc, these are not objects.

9) Qualities for a program to be 100% OOPS language?
   Encapsulation/Data Hiding



                                              1
                            Java Interview Prepration

   1. Polymorphism
   2. All predifined types are objects
   3. Inheritance
   4. Operations performed through messages to objects
   5. Abstraction
   6. datatypes are to be objects.

10) What is early binding?
   Early binding or static type or static binding is assigning the value of the variable
during design phase. Early binding instruct the compiler to allocate space and perform
other task before the application starts executing.

11) What are the disadvantages of threads?
  o The main disadvantage of using thread is that it is operating system dependent. It
require to follow CPU cycle that various from system to system.
  o Deadlock occurs

12) Why is java case sensitive?
  Java is platform independent language. It is widely used for developing code which
contains different variables and hence java is case sensitive.

13) What is singleton class?
   A class which can create a single object at a time is called class. The object is
accessible by the java virtual machine. It creates a single instance for the class

14) Objects are passed by value or by reference?
   In java objects are passed by value. Since, the object reference value is passed both
the original and the copied parameter will refer to the same object.

15) What is serialization?
   It is a method which saves the object state by converting to byte stream.

16) What is externalizable interface?
   Externalizable interface controls the serialization mechanism. It consist of two
methods readexternal and writeexternal. It helps to customize the serialization process.

17) What are the different types of inner classes?
  * Member classes.
  * Anonymous classes.
  * Nested top-level classes.
  * Local classes.

18) What are wrapper classes?
   Wrapper class represents a base class for the data source. It allows the primitive
datatype to be accessed as objects.




                                            2
                            Java Interview Prepration

19) What are the different ways to handle exception?
   * By placing the desired code in the try block and allow the catch block to catch the
exception.
   * Desired exception can be placed in throw clause.

20) Is it necessary that each try block must be followed by a catch block?
    It is not essential that try block should be followed by catch block.

21) What is the difference between instanceof() and isInstance()?
    instanceof() is used to see whether the object can be typecast without making use
of the exception.
    isInstance() is to check whether the specified object is compatible with the class
that represent the object.

22) How can you achieve multiple inheritance in java?
    Multiple inheritance in java implemented in similar to the C++ with one difference the
inherited interface should be abstract.

23) What is the difference between == and equals methods?
   „==‟ is used to check whether two numbers are equal
   „Equals‟ is used to check whether two strings are equal.

24) What are java beans?
   Java bean is a platform independent and portable. It helps to develop code that is
possible to run in any environment

25) What is RMI?
    RMI stands for remote method invocation; it enables the developer to create
application based on java, in which the java objects are invoked by java virtual machine.
1) What is JVM?
   JVM enables to convert the source code into the code which can be executed in the
system. This makes the java independent of the platform

2) Name four container classes?
   * Dialog
   * FileDialog
   * Panel
   * Frame

3) What is JAR file?
  JAR stands for java archive, it is used to compress a class of file.

4) What is typecasting?
  Typecasting converts entity of one type to entity of another type. It is very important



                                             3
                             Java Interview Prepration

while developing applications.
 Casting is of two types:-
  1. downcasting
  2. Upcasting

5) What is serialization and deserialization?
   It is process of representing the state of an object in byte stream. Process of restoring
the object is done be deserialization.

6) What is vector class?
   Vector class provides the capability to implement array of objects.

7) What is JVM and its use?
    The most important feature of Java is platform independent, this is supported by
JVM. It converts the machine code into bytes. It is the heart of the java language and a
structure programming language.

8) What are the difference between java and C++?
   Java adopts byte code whereas C++ doesn‟t.
   C++ supports destructor whereas java doesn‟t support.
   Multiple inheritance possible in C++ but not in java.

9) Difference between swing and AWT?
   AWT is works faster then swing since AWT is heavy weight components.AWT consist
of thin layer of code, swing is larger and of higher functionality.

10) If a variable is declared as private, where may the variable be accessed?
   When the variable is declared private, it can be accessed only inside the class in
which it is defined.

11) What is final?
   A final class cannot be sub classed neither extended. The variables cannot change
the value.

12) What is static in java?
   Static methods are implicitly final, their methods are not attached to an object rather it
is attached to a class.

13) Is null a keyword?
    NULL is not a keyword.



                                             4
                             Java Interview Prepration


14) What is garbage collection?
   When an object is no longer used, java implicitly recalls the memory of the object.
Since java doesn‟t support destructor it makes use of garbage collector in the place of
destructor.

15) What is the resourceBundle class?
   It is used to store the local specific resources inorder to tailor the appearance.

16) What is tagged interface?
   Tagged interface is similar to the serializable interface, it instruct the complier to
perform some activity.

17) What is overriding?
   When any class use the same name, type and arguments as that of the methods in
the super class then the class can override the super class method.

18) What is referent?
   Referent variable are constant variable it cannot be modified to refer to any other
object then the one with it was initialized.

19) What is the method to implement thread?
   Thread can be implemented by run() method

20) What is the difference between primitive scheduling and time slicing?
   In case of primitive scheduling the task with highest priority is performed until it
enters the dead state. In case of time slicing it performs the task for sometime and then
enter the ready state.

21) What are different types of access modifiers?
   public: accessible from anywhere.
   private: can be accessed only inside the class.
   protected: accessed by classes and subclasses of the same package.
   default modifier : accessed by classes contain the same package

22) What is the difference between subclass and superclass?
   Subclass doesn‟t inherit anything from other classes whereas superclass inherit from
other class.

23) What is a package?



                                              5
                             Java Interview Prepration

   Package is a collection interface and class which provides a very high level of
protection and space management.

24) What is the difference between Integer and int?-
   Integer defined in java. lang package which is a class, whereas int is a primitive data
type defined in the Java language itself.

25) What is synchronization?
   It is mechanism that allows only one thread to process the thread at a time. This is
mainly to prevent deadlock.




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);
  Output:-
  15.

6. What will be the default values of all the elements of an array defined as an instance



                                              6
                             Java Interview Prepration

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:-
 Local
 Instance
 Static

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
Hashmap
LinkedHashmap
Treemap

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:-
Values
Keyset
Entryset

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.



                                               7
                             Java Interview Prepration


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:-
  Final
  Abstract
  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




                                               8
                            Java Interview Prepration

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.
    Advantage:-
   Make it localized, and can be translated into different languages.
   Modification can be done easily.




1. Explain different way of using thread?
   Thread can be implemented by using thread class or by runnable interface. Using
runnable interface is more advantageous because it can be used in multiple
inheritances.

2. Difference between HashMap and HashTable?
     HashMap is similar to HashTable, the only difference is that they are
unsynchronized and they permit NULL. HashMap doesn‟t guarantee that the map order
will be maintained.

3. What is the difference between a constructor and a method?
   A constructor is member function and it is used to create object of the class. It
assigns the same name as that in the class, and has no return type. Whereas method is
a ordinary member function, which has own name and return type. They are invoked
using dot operator.




                                             9
                            Java Interview Prepration

4. What is the disadvantage of threads?
    The major disadvantage is that
         It is operating system dependent.
         Execution of thread reduces speed
         High possibility of Dead Lock.

5. What is garbage collection? Can it be forced?
          Garbage collection is mainly to identify and discard objects which is no longer
used. It is required by the program for alloction of resources and reclaiming them. Java
virtual machine tries to recycle the unused object, but there is no guarantee that the
object is garbage collected.

6. What is Log4j in java?
     Log4j is a property file wich can be used to assign application mode in “DEBUG”,
“ERROR” etc.

7.What are the primitive types in Java?
   Java support eight types of primitive data types and they are as follows:-
    Short
    Int
    Byte
    Float
    Char
    long
    Boolean

8. How all can free memory?
  If a programmer really wants to explicitly request a garbage collection at some point,
System.gc() or Runtime.gc() can be invoked, which will fire off a garbage collection at
that time

9. What are the differences between JIT and Hotspot
JIT is a compiler whereas Hotspot is a collection of techniques, also called as
optimization.
Java hotspot is a core component of the Java platform. It implements JVM specification
and uses shared library.

10. What is the difference between concat and append?
    Concat is used to add a string at the end of another string.But append() is used with
String Buffer to append character sequence or string.When we concatinate a string with



                                           10
                             Java Interview Prepration

another string a new string object is created.But in case of StrinBuffer APPEND() that is
not the case.

11. What is EJB?
     EJB stands for Enterprise Java Bean. It is a server side resident resource
manageable, secure, reusable component.

12. What is package? Define with example?
        Grouping of related types is said to be package. The type can be a class or
enumeration or interface and annotation. They are provided with access protection. It is
a group of inter-related classes

13. What is the difference between length and length()?
     Length() is a method that is used to determine the length of the string in the class,
Whereas length is just used for array to find the length of the array.

14. What is synchronization and why it is important?
     Synchronization occurs when the programmer want to run two thread at a time
which shares some property. Synchronization is the process that control access to
multiple threads to share resources.

15. How to make a class serializable?
            Class can be serialized by using the interface or the io.externalizable or
io.serializable. When one class is inheritance to the other, the class is said to be
serializable.

16. Do I need to import java.lang package any time? Why ?
      No. It is by default loaded internally by the JVM.

17. What are the different types of inner classes?
     The different type of inner classes are as follows:-
     Local classes
     Anonymous classes
     Nested top- level classes
     Member classes

18. What is a member class?
    It is one of inner class which is just like the other methods and variables and they
are restricted to access. The major difference between member and nested top level
class is that it can access specific instance of the corresponding class.



                                            11
                            Java Interview Prepration



19. What is the difference between error and exception?
     An error that occurs during runtime is not recoverable whereas in most of the
cases an exception can be recovered if it occurs during run time.

20. What are the different ways to handle exceptions?
  The two methods to handle exception are as follows:-
   Wrapping the desired code in the try block that is followed by catch block
   List out the desired exception in throw and the caller of the method handle
   the exception

21. If I write System.exit (0); at the end of the try block, will the finally block still
execute?
     When you type System.exit(0) in the end it indicates the compiler to stop compiling
and execute of the program, thus the finally block will not be executed.

22. How are observer and observable used?
      Objects that subclass the Observable class maintain a list of observers. When an
Observable object is updated it invokes the update() method of each of its observers to
notify the observers that it has changed state. The Observer interface is implemented
by objects that observe Observable objects.

23. How does Java handle integer overflows and underflows?
        Java handles integer overflow and underflows using low order bytes that fit in
the size of the type that is allowed by the operation.

24. What is locale class?
       The class is mainly used to tailor the output of the program with respect to the
specification

25. Can applets communicate with each other?
              An applet may communicate with other applets that are running in the
same virtual machine. When the applet are from same class it can communicate using
static variable, when the applet are of different class it can communicate through
reference.




                                            12

				
DOCUMENT INFO
Shared By:
Tags: JAVA, .net, Spring
Stats:
views:12
posted:9/8/2012
language:English
pages:12
Description: These documents are relater to .net,sql and specially for JAVA.