Friday 20 December 2013

Java most asked interview questions

1. what is transient variable?

By default all the variables in the object get converted to a persistant state, in some case you may want to avoid passing some variables, so you can declare that variable as transient variable.
Transient variables are non-serializable.

2. what will happen if we don't initialize the local variables?
COmpilation error will come.

3. Instance variables are initialized to what values?

integer- 0
float 0.0.
boolean - false
string - null.
char -  nothing.

4. how to set locale for Canada?
Locale canada = new Locale("fr","CA");

5. if a exception thrown by a try statement but no catch what is the output?
Compilation error.

6. which variable is synchronizes?
a.static
b.public
c. private

Ans:static.

7. which is the default access specifier for class?

Package

8. JVM declare how many times of memory?

stack and the heap memory.

9. what is the deamon process and whether we can ceate the deamon process?
Deamon process is the thread which is the service provider for user threads.
which will terminate after all user threads terminated.

Yes, we can create the deamon process using
setDeamon() method.

and can check isDeamon().

we need to create the deamon thread before calling the start() method.

10. what is singleton class?
we can not initialize more than one instance.

11. why implementing the runnable interface preferable over extend the thread?
thread class
a. If we extend the thread class all the threads create their own objects and associated with them.
b. if we extend thread in future we can not extend any other thread.

runnable interface.

a. we can implemetn any number of interface.
b all threads created will share same object spce.

11. which algorithem used in java garbage collection?
mark and sweep algorithem.

12. stack is faster or heap?

stack.

13. what is run time polymorpison.?
binding happens during run time, this is because of method overriding.

14. how many public classes can be present in one java file?

one class.

16. how many main mehods can be present in single java file?

more than one.

17. difference between ennumaration and Iterator?

Ennumaration.
It is read only.
it does not have remove method.

Iterator.
It can modify the collection using remove method.
it does remove methd.

18. difference between hashmap and hashtable?
hashmap.
Allows null keys and null values.
hash map is not synchronized.

hashtable
It does not allow null keys and null values.
hash table is synchronized.

19. Advantages and disadvantages of static bllock?

 Advantages.
a. used while loading the device driver.
b. for initialize the variables which requires computation.
c. security related and leaking issues.

disadvantages.

a. static initialization block should not exceed 64k.
b. cn not through checked exceptions.
c. should not try to access super since there is no such thing for static block.
 d. can not return anything from static block.

20.why interface is better than abstract class?
 java will not support class multiple inheritance  so interface is usefull.

21. what is early binding?

the data and the method which will operate on the data are separately  defined in oops, and they bind data members during compilation time.

22. difference between multi threading and multi processing?
multi threading.
a. shares same address space.
b. thread is light weight.
c. cost of communicartion is low.
d. context switching cost is very less.


multi process.
a. each process have seperate address space.
b. heavy weight component.
c. coat of intercommunication is high.
d. context switching cost is very high.

23. why jvm is platform dependenant.
JVM is developed usig the platform dependent languages like c,c++ so it is platform depedent.

24. difference between classpath and path environmen variables?
classpath referes to the user clasess whre located.
c:/programs/
path refers to the executable where located.
c:/java/jdk/bin



 





No comments:

Post a Comment