Sunday 28 July 2013

Java interview questions

What is the difference between HashMap and Hashtable class.

HashtableHashMap
Hashtable class is synchronize.HastMap is not synchronize.
Because of Thread-safe, Hashtable is slower than HashMapHashMap works faster.
Neither key nor values can be nullBoth key and values can be null
Order of table remain constant over time.does not guarantee that order of map remain constant over time.

Q2. How to remove duplicate element from a ArrayList.

At first this question will look quite difficult but the answer is very simple. By converting the ArrayList intoHashSet. When you convert a ArrayList to HashSet all duplicates elements will be removed but insertion order of the element will be lost.

Q3. How to create a unmodifiable/read-only list in Java?

Collections.unModifiableList() method is used to create unmodifiable/read-only list in Java. Pass the listas a argument to this method.

ArrayList al=new ArrayList();
al.add("a");
al.add("b");
al.add("c");
al = Collections.unModifiableList(al);

Q4. What is the difference between ArrayList and Vector class.

VectorArrayList
Vector class is synchronize.ArrayList is not synchronize.
Because of Thread-safe, Vector is slower than ArrayListArrayList works faster.
Enumeration is used to iterate through the element of Vector.Iterator is used to iterate through the element of ArrayList.


Q5. Why String is immutable in Java?

In Java, strings are object. There are many different ways to create a String object. One of them is using string literals.
why string is immutable
Each time a string literal is created, JVM checks the string constant pool first. If string already exist in the pool, a reference to the pool instance is returned. Sometime it is possible that one string literals is referenced by many reference variable. So if any of them change the string, other will also get affected. This is the prominent reason why string object is immutable.

Q6. Difference between StringBuffer and StringBuilder?

Both StringBuffer and StringBuilder classes are almost same except for two major differences.

StringBufferStringBuilder
StringBuffer is synchronize.StringBuoder is not synchronize.
Because of synchronisation, StringBuffer operation is slower than StringBuilder.StringBuilder operates faster.


Q7. Difference between equals() method and == operator?

Main difference between '==' and equals() in Java is that '==' is a operator used to check whether two different reference refers to same instance and equals() is a method used to check equality of an object. Another important difference is '==' operators is used more with primitive data type while equals() method is used for object.
   See example of '==' operator and equals() method for more detail.

Q8. What are the different ways to create a thread in java?

There are two different way to create a thread in java.
1. Extending Thread class.
2. By implementing Runnable interface.



Q9. What are the difference between sleep() and wait() method.

wait() method in java should be called from synchronized block while there is no such requirement forsleep() method. Another difference is sleep() method is a static method, while wait() is an instance specific method called on thread object. In case of sleep(), sleeping thread immediately goes toRunnable state after waking up while in case of wait(), waiting thread first acquires the lock and then goes into Runnable state. notify() and notifyAll of Object class are used to awake a waiting Thread while sleeping thread can not be awaken by calling notify() method. wait() method is defined in Object class while sleep() is defined in Thread class.

Q10. What is serialization in java?

Serialization is a process of converting object into a sequences of byte which can be written to disk or database or sent over network to any other running JVM. The reverse process of creating object from sequences of byte is called Deserialization.
See more detail on

Q11. What is covariant return type?

After Java 5, it is possible to override a method by changing its return type. If subclass override any method by changing the return type of superclass method, then the return type of overriden method must be subtype of return type declare in original method in the superclass. This is the only way in which method can be overriden by changing its return type.

Q12. How to find if JVM is 32 or 64 bit from Java program.

By using System.getProperty() method, you can find JVM size from java program. Although the size of JVM hardly matters because we know that java is platform independent i.e write once and run everywhere but in some situation it is required to know the size of JVM like if you are using native library. Example of how to get size of JVM.
System.out.println(System.getProperty("os.arch"));
System.out.println(System.getProperty("sun.arch.data.model"));

Q13. How to change file permission in Java?

setReadable()setWritable()setExecutable() method is used to change or set file permission in java.
See 

Q14. How you can force the garbage collection?

Garbage collection automatic process and can't be forced. You could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. Garbage collection is one of the most important feature of Java, Garbage collection is also called automatic memory management as JVMautomatically removes the unused variables/objects (value is null) from the memory. User program can't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.

Java
Java Tutorial
Core Java
Java interview questions 

Friday 26 July 2013

interview questions

Q: What is the difference between an Interface and an Abstract class?
A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. 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.

Abstract class can not be final.
Abstract class Can not instantiated.
.


2.    Q: What is the purpose of garbage collection in Java, and when is it used?
A: 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.


3.    Q: Describe synchronization in respect to multithreading.
A: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. 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.    Q: Explain different way of using thread?
A: The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.


5.    Q: What are pass by reference and passby value?
A: 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.

6.    Q: What is HashMap and Map?
A: Map is Interface and Hashmap is class that implements that.


7.    Q: Difference between HashMap and HashTable?
A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.


8.    Q: Difference between Vector and ArrayList?
A: Vector is synchronized whereas arraylist is not.


9.    Q: Difference between Swing and Awt?
A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.


10. Q: What is the difference between a constructor and a method?
A: 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.


11. Q: What is an Iterator?
A: Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. 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.


12. Q: 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.
A: public : Public class is visible in other packages, field is visible everywhere (class must be public too)
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.
default :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.


13. Q: What is an abstract class?
A: Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. 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.

14. Q: What is static in java?
A: 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, 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.

15. Q: What is final?
A: A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).


16. Q: What if the main method is declared as private?
A: The program compiles properly but at runtime it will give "Main method not public." message.


17. Q: What if the static modifier is removed from the signature of the main method?
A: Program compiles. But at runtime throws an error "NoSuchMethodError".


18. Q: What if I write static public void instead of public static void?
A: Program compiles and runs properly.


19. Q: What if I do not provide the String array as the argument to the method?
A: Program compiles but throws a runtime error "NoSuchMethodError".


20. Q: What is the first argument of the String array in main method?
A: 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.


21. Q: If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
A: It is empty. But not null.


22. Q: How can one prove that the array is not null but empty using one line of code?
A: 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 NullPointerException on attempting to print args.length.


23. Q: What environment variables do I need to set on my machine in order to be able to run Java programs?
A: CLASSPATH and PATH are the two variables.


24. Q: Can an application have multiple classes having main method?
A: Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.


25. Q: Can I have multiple main methods in the same class?
A: No the program fails to compile. The compiler says that the main method is already defined in the class.


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


27. Q: Can I import same package/class twice? Will the JVM load the package twice at runtime?
A: One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.


28. Q: What are Checked and UnChecked Exception?
A: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method•
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method• Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

29. Q: What is Overriding?
A: When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.
When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

Java interview questions


1)What is the Java Collections API? 
Java Collections Framework provides a set of interfaces and classes that support operations on a collections of objects.
2) What is the Set interface?
The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
3) What is the List interface?
The List interface provides support for ordered collections of objects.
4) What is the difference between set and list?
Set stores elements in an unordered way but does not contain duplicate elements, where as List stores elements in an ordered way but may contain duplicate elements.
5) What is map interface in a java?
Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. This Map permits null value
6) What is the difference between Map and Hashmap?
Map is Interface and Hashmap is class that implements that
7) What is the difference between a HashMap and a Hashtable in Java?
  • Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
  • Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
  • One of HashMap’s subclasses is LinkedHashMap, so in the event that you’d want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for aLinkedHashMap. This wouldn’t be as easy if you were using Hashtable.
8) What is a vector in Java?
Vector implements a dynamic array. It is similar to ArrayList, but with two differences:  Vector is synchronized,Vector is not part of latest Collection API Vector is introdus in JDK 1.0 and  that’s why it called  legacy Class.

9) What is ArrayList In java?
ArrayList is a part of the Collection Framework. We can store any type of objects, and we can deal with only objects. It is growable.That is Introdus JDK 1.2 new Collection API.

10) Difference between Vector and ArrayList?
Vector & ArrayList both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. ArrayList and Vector class both implement the List interface.
1) Synchronization - ArrayList is not thread-safe whereas Vector is thread-safe. In Vector class each method like add(), get(int i) is surrounded with a synchronized block and thus making Vector class thread-safe.
2) Data growth - Internally, both the ArrayList and Vector hold onto their contents using an Array. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
11)How Can I Synchronized ArrayList Object ?(That Is More Commen Collection Quection that is allays ask by interviewer)?
Ans- Yes we can Synchronized Array list Object  with the help of Collections Class
Collections.synchronizedList(ArrayList Object);

11) What is an Iterator interface?
The Iterator is an interface, used to traverse through the elements of a Collection. It is not advisable to modify the collection itself while traversing an Iterator.

12) what is Enumeration in java?
An enumeration is an object that generates elements one at a time, used for passing through a collection, usually of unknown size. The traversing of elements can only be done once per creation.


13) What is difference between Iterator and Enumeration?

Both Iterator and Enumeration are used to traverse Collection objects, in a sequential fashion.  Enumeration can be applied to Vector and HashTable. Iterator can be used with most of the Collection objects.
The main difference between the two is that Iterator is fail-safe. i.e,  If you are using an iterator to go through a collection you can be sure of no concurrent modifications in the underlying collection which may happen in multi-threaded environments.

14) What is the Properties class?
The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

15) What is difference between HashMap and HashSet?
HashSet : HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used where you want to maintain a unique list.
HashMap : It allows null for both key and value. It is unsynchronized. So come up with better performance
16 )  What is the Difference between the Iterator  and ListIterator?
Iterator : Iterator   Can Only get Data From forward Direction .
ListIterator: An iterator for lists that allows one to traverse the list in either direction.modify the list during iteration, and obtain the iterator’s current position in the list. A ListIterator has no current element. its cursor position always lies between the element that would be returned by a call to previous() and the element that would be returned by a call to next(). In a list of length n, there are n+1 valid index values, from 0 to n, inclusive.

17)  How to Make a Map or List as Thread-Safe or Synchronized Collection?
Collections.synchronizedMap(new HashMap());

Collections.synchronizedList(List<T> list)

18) What method should the key class of Hashmap override?

The methods to override are equals() and hashCode().
19) How to convert a string array to arraylist? 

new ArrayList(Arrays.asList(myArray));

Java

Thursday 25 July 2013

Java Questions


1) What are checked and unchecked exceptions?
Ans: It is important to understand the meaning of checked which is checked by compiler. The compiler flashes an error when a method can throw a checked exception. The kind of exceptions falling under this category are the ones for which the developer has no control like file permissions and network outage.
Java
Unchecked exceptions are the exceptions which arise primarily because of some fault on the developer's side. This includes not initializing reference variables properly, accessing non existing index in an array etc. The developer is not notified about these kind of exceptions.

Checked exceptions are usually considered as disguise as one is forced to use catch or throws irrespective of the intention.


Core Java

2) What is serialVersionUID?
Ans: serialVersionUID refers to the version given to a particular class with respect to serialization operation. 
Java Tutorial
serialVersionUID acts like meta data for serialization and de-serialization operations. The id if not added by developer is generated by JDK. The significance of serialVersionUID is that one can create various versions of class and hence allow/dis-allow the serialization/de-serialization of objects of this class.

3) How does Garbage Collection works?
Ans: Garbage collection is mechanism by which JVM automatically cleans up the memory occupied by objects. These are the objects which are no longer required by the application and there is no live reference pointing to these objects.

A Java program can’t force garbage collector to run but one can suggest the garbage collector to run by using the statement System.gc()


Core Java Tutorial 

Wednesday 24 July 2013

Java interview questions

1. What is difference between Java and C++?
Ans :
(i) Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist in Java.
(ii) Java does not support operator overloading.
(iii) Java does not perform any automatic type conversions that result in a loss of precision
(IV) All the code in a Java interview program is encapsulated within one or more classes. Therefore, Java does not have global variables or global functions.
(v) Java does not support multiple inheritance.
Java does not support destructors, but rather, add the finalize () function.
(vi) Java does not have the delete operator.
(vii) The <> are not overloaded for I/O operations
2. Can you explain me OOPs Concepts ???
Ans : OOPs stands for Object Oriented Programming.
it has mainly four concepts ..
1. Polymorphism : It is ability to take more tahn one form (Poly : More and Morphism : forms). In java it is achieved by using Method Overloading(Compile time Polymorphism) and Method Overriding( Runtime Polymorphism)
2. Inheritance : It is the process by which one object acquires the properties of another object and also has some of its own.The main advantages of inheritance are reusability and accessibility of variables and methods of superclass by the sub classes.
3. Encapsulation: It is the process of wrapping the data and code into a single object. Like all class are a object. It is used for data hiding like variables declared as private can be accessed only by members of that particular class.It is mechanism that binds together code and data . It manipulates and keeps both safe from outside world.
4. Abstaction : it is representating the essential features without including background details. It is like providing the functionality without knowing who it happens.
eg : By cominations of Red Green and Blue we can form 256 no of colors.
In java if need to append a string with another, then we use append method of StringBuffer without bothering how it works.
3. what is difference between Abstraction and Encapsulation ??
Abstrction is used at the design side while Encapsulation is used at the implementation side.
Abstraction is used for hiding the unwanted information and giving revelant information.
Eg: Three set of customers are going to buy a bike First one wants information about the style. Second one wants about the milage. Third one wants the cost and brand of the bike.So the salesperson explains about the product which customer needs what. So he hiding some information and giving the revelant information.
Encapsulation combines one or more information into a component.
Eg: Capsule is mixed with one or more medicine and packed into the tube. so its related and acting in two moducles.
4. what is dynamic binding or late binding ??
In dynamic binding the code associated with a given procedure call runs at the run time(Not compile time).
5. What is difference between Class and Object??
Class is a blue print of an object while object is an instance of a class. Class is a virtual entity while object is an real implemetation
6. Can you explain how obkect is created in memory ??
Ans : Object is constructed either on a memory heap or on a stack.

Memory heap
generally the objects are created using the new keyword. Some heap memory is allocated to this newly created object. This memory remains allocated throughout the life cycle of the object. When the object is no more referred, the memory allocated to the object is eligible to be back on the heap.
Stack 
During method calls, objects are created for method arguments and method variables. These objects are created on stack.
7. What is mean by System.out.pritnln(“hello World”);
System : it is a claas.
out : It is an instance variable of java.lang.System class refers to console.
println() : It is a method of java.io.PrintWriter.
8. What is wrapper classes ?
primitive data types can be converted into objects by using wrapper classes. These ara part of java.lang package.
9. Does Java passes methos arguments by value or by reference ??
Java passes all arguments by value , not by references.

Monday 22 July 2013

Java interview questions

  1. What is the most important feature of Java? 
    Java is a platform independent language.
  2. What do you mean by platform independence? 
    Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

  3. Are JVM's platform independent?
    JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.

  4. What is a JVM?
    JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

  5. What is the difference between a JDK and a JVM?
    JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

  6. What is a pointer and does Java support pointers? 
    Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

  7. What is the base class of all classes?
    java.lang.Object

  8. Does Java support multiple inheritance?
    Java doesn't support multiple inheritance.

  9. Is Java a pure object oriented language? 
    Java uses primitive data types and hence is not a pure object oriented language.

  10. Are arrays primitive data types? 
    In Java, Arrays are objects.

  11. What is difference between Path and Classpath? 
    Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.

  12. What are local variables? 
    Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

  13. What are instance variables? 
    Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

  14. How to define a constant variable in Java? 
    The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.
    static final int PI = 2.14; is an example for constant.

  15. Should a main method be compulsorily declared in all java classes?
    No not required. main method should be defined only if the source class is a java application.

  16. What is the return type of the main method?
    Main method doesn't return anything hence declared void.

  17. Why is the main method declared static?
    main method is called by the JVM even before the instantiation of the class hence it is declared as static.

  18. What is the arguement of main method?
    main method accepts an array of String object as arguement.

  19. Can a main method be overloaded? 
    Yes. You can have any number of main methods with different method signature and implementation in the class.

  20. Can a main method be declared final? 
    Yes. Any inheriting class will not be able to have it's own default main method.

  21. Does the order of public and static declaration matter in main method?
    No it doesn't matter but void should always come before main().

  22. Can a source file contain more than one Class declaration?
    Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

  23. What is a package?
    Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

  24. Which package is imported by default?
    java.lang package is imported by default even without a package declaration.

  25. Can a class declared as private be accessed outside it's package?
    Not possible.

  26. Can a class be declared as protected?
    A class can't be declared as protected. only methods can be declared as protected.

  27. What is the access scope of a protected method?
    A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

  28. What is the purpose of declaring a variable as final? 
    A final variable's value can't be changed. final variables should be initialized before using them.

  29. What is the impact of declaring a method as final? 
    A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

  30. I don't want my class to be inherited by any other class. What should i do? 
    You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

  31. Can you give few examples of final classes defined in Java API? 
    java.lang.String,java.lang.Math are final classes.

  32. How is final different from finally and finalize? 
    final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.
    finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.
    finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

  33. Can a class be declared as static?
    No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

  34. When will you define a method as static?
    When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

  35. What are the restriction imposed on a static method or a static block of code?
    A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

  36. I want to print "Hello" even before main is executed. How will you acheive that?
    Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.

  37. What is the importance of static variable?
    static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

  38. Can we declare a static variable inside a method? 
    Static varaibles are class level variables and they can't be declared inside a method. If declared, the class will not compile.

  39. What is an Abstract Class and what is it's purpose? 
    A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction. 
Some important links

Java 
Core Java
Java interview questions
Java tutorial
Core Java
Core java tutorial
CoreJava
Learn Java
Java Programming Language
Java interview questions