October 28, 2013

Java Questions

Just a few interview questions which i faced in the interviews ... thought of sharing..

 1) What is JVM?
2) What is JDK?
3) What is JRE? Differences between JDK and JRE?
4) How java is platform independent?
5) When you say java FileName what happens? Every time it creates new JVM instance or how?
6) What are the benefits/features of java?
7) What are differences between C# and Java?
8) What are the major properties of java? i.e. Encapsulation, Inheritance, Abstraction and polymorphism. Explain those and give some examples of them.
9) What is difference between interface and abstract class? Examples of each and when to use what?
10) How string is immutable? What is immutable? Any other classes in java are immutable?
11) How you can create an immutable class? What happens internally?
12) What are the differences between final, finally and finalze?
13) What are differences between string buffer and string builder and when to use what?
14) Various questions on access modifiers like public, protected, private and default.
15) Various questions on static keyword, can static methods are called by instance variables. What is the use of static? When to use it?
16) What is singleton pattern and some more questions on it like if u extend this singleton class for another class how u call the methods. Instead of private constructor cant i have it as protected etc.,
17) Make sure you learn some more patterns like Factory, Facade, Observer etc.,
18) What is binary search?
19) What is thread? Thread life cycle? Yeild, wait, sleep etc., multi threading .. some logical questions.
20) Run vs runnable?
21) Concurrency package
22) Reflection package – what is it for and any sample implementations
23) What is garbage collector? How it happens? Any algorithms you know like mark and sweep algo ? what is nursery? Can u invoke gc() is it safe to use?
24) Memory related questions what is stack  mem , heap mem.. how the gc works on both and how objects move from one mem to other mem.
25) Cacheing.. what is cache? How can we implement our own cache? Have you used any cacheing? Some more ques like if i have heavy data with blob and clob related entries also how u perform cacheing.
26) If i have 100 threads and a synchronized block each thread is taking 30 sec but i want to improve my app performance so how u can solve it.
27) What is volatile means how it works
28) What is transient means how it works
29) What is marker interface? Examples of it and will you be able to create marker interface?
30) What is serialization? How it works? What is advantages of it? If i give transient what it does, what happens? If i implement serialization for base class and not for extended classes what happens and vice versa?
31) What is enumeration? Basic questions
32) What is system.out.println()? What is system? Out?
33) Generics? If u know other side <> or or etc questions
34) Any new features in java 5 what is it? Same quests for 6 and 7.
35) What is deadlock. Any deadlock prevention techniques
36) What is file stream, buffered readers
37) Collections? What is hashmap, hashtable, hashset, treeset, vector, linkedlist, arraylist, stack, queue etc.,
38) Some differences between them in 37 Q
39) Internal implementations of arraylist, linked list which is best for what i.e insertion , deletion, traversal etc
40) What is auto boxing, shadowing, deep copy, pass by value, pass by reference
41) Sorting, comparable, compare to method override. Person has emp name and all person obj in arraylist .. now sort arraylist by emp name
42) Without using any java packages and even util package implement stack, queue etc
43) What all packages you know and which packages are you comfortable in.
44) Equals and hashcode overriding. ... lot of questions on why we override and how we override. Do we have any contracts between both if so what.
45) Treeset is auto sorted right how it happens.
46) I want to write my own collection class with push pop so which one you implement or extend and how u write the methods...
47) What are differences between creational, structural and behavioural design patterns.
48) What is inner class? Some deep questions on inner classes? (Rare people ask)
49) What is multiple inheritance in java and any example for it?
50) More questions on overloading and overriding.
51) What is exception? And what is error?
52) Difference between exception and error? What is checked and unchecked exceptions?
53) Sample exceptions and errors and whats its purpose?
54) If out of memory error how u handle it?
55) How jvm creates a dump file for you?
56) Java –x parameters questions.
57) When u say java Mohan which is import x.mohan.Sub; and the same class available in two jars in class path then which one jvm considers.
58) What are wrapper classes?
59) MVC what is model, view and controller? Where we use it.
60) More questions on Compile time and run time. Like will i be able to catch outofmemory error if no why if yes how. If our answer is no then if i write the statement in catch an outofmemory error it thows complie time exception or runtime.
61) How can i create my own custom exceptions.
62) Difference between throws, throwable is it safe to use.
63) Code review related and some best practices related questions.
64) SQL Joins , trigger, index, clustered index, as a developer they give a scenario and ask on what u create indexes.
65) What are JSP implicit objects? I.e Request, response, pagecontext, application, session, out, config, page and exception.
66) What is priority queue, binary sort, binary tree, tree sort.
67) Given one binary tree...
      a. A has left B and right C
      b. B has left D and right E
      c. C has left F and right G
     d. How u write a program to make it mirror image.
68) Servlet life cycle
69) Will i be able to overwrite init method of servlet
70) How can i destroy a servlet
71) What is jsp life cycle
72) <@page , import , cache  related questions.
73) Web.xml questions like init params, context params , session, servlet filters etc.,
74) Select Null from Employee e;
75) What is Cartesian join.
76) Aptitude questions like
              a. 20 sheets -> 1 sheet -> 55 lines -> 1 line -> 65 chars. If i write 1 sheet -> 65 lines and 1 line 75 chars then how many sheets req?
77) 25 buckets of water to fill a tank ...
78) Green blue white balls et.c...
79) Super and this questions
80) Suppose class A has static int i =10; then Output of  A1.i, A2.i then change it to int i =20; then outputs and if i change value of i then outputs etc.,
81) Then Extends questions like A A1 = new A(); B B1=(B) A1; A A2 – new A(); B B2 = (B)A2();
82) Class A  public int i=10; class B public final A A1 = new A(); .... Main { B B1=new B(); B1.A1.i = 15; will it give any exception}
83) DOM Vs SAX Parser.
84) XML – simple type complex type
85) WSDL Structure what is soap envelope?
86) Marshalling and unmarshaling  .. Webservice bottom up and top down approach.
87) SOAP, Document literial, RPC bindings
88) String s = “Hello”; String s1 = “Hello”;            == .equals gives what output what happens internally.                  String s = new String(“Hello”);   == .equals ??
89) Cloning / deep cloning ??
90) In a web application how can i count how many requests are coming to a respective servlet.
91) Servlet Vs Portlet life cycle.
92) Portlet AJAX Implementation.
93) Servlets will have default no arg constructor or not.. if so can we initialize it with new operator.
94) Array[100] obj -> normal serialization is not used..  then how u can serialize this array.
95) If you serialize one object and then u modify that obj.. in that case if you deserialize that object it will give proper result or it will throw an exception.
96) Write a program to create a tree as shown below
             a. Root 21 has left 6 and right 15 as its sum is equal to root.
          b. 6 has left 2 and right 4 .. sum is 6
             c. 15 has left 7 and right 8 .. sum is 15.
97) SQL count will give count of null values also or not.
98) Delete vs truncate commands in SQL
99) Will you be able to catch Runtime exception in try catch and will you be able to throw runtime exception?
100) Can we give final to a singleton class.
101) Linkedhashmap?? Stringbuilder vs stringbuffer vs vector.
102) JDBC drivers type 1,2,3,4.
103) JSP tags etc..
104) Can you implement a remote contract where u have 5 buttons each button performs on and off of the item .. so how u store the state and alter the state from on to off .. vice versa. And more over one Undo button.
105) What is anonymous class?
106) Can we write an interface with in a class?

            Useful Websites:
a. http://javapapers.com
b. http://www.brpreiss.com/books/opus5/index.html
c. http://www.tutorialspoint.com/java/java_serialization.htm
d. http://javarevisited.blogspot.in/2011/09/javalangoutofmemoryerror-permgen-space.html
e. http://www.brpreiss.com/books/opus5/html/page36.html

1 comment: