Popular Posts

Tuesday, March 6, 2012

Java frequent interview questions

=====================================================================
Java interview questions : 
5) What is hashcode and equals contract?
6) What is the difference between == and equals method?
8) What is the difference between String and StringBuffer classes?
9) What is the way to store the integer value in a string object to an integer variable?
10) What are sorted collections in Java?
12) What is JDBC API?
14) What is final, finally and finalize?
15)********** What is weakhashmap?
16) ************What is the purpose of reflection API?
18) What is bucketing in Java?
19)*************** How does Java manages the threads?
23) **************What are the different ways of creating a thread?
24) ************** What is inter thread communication?
25) ************** What are instance and class level locks? What is synchronization?
29) What are the coding standards for naming variables, constants, methods and classes?
30) What is a literal and what is special about String literals?
31) **************What is flyweight design pattern?
32) **************How will you create a Singleton class? Is it thread safe?
35) What is the purpose of instanceof operator?
37) What is the difference between private, protected, default and public access specifiers?
38) What are this and super keywords?
39) What are transient and volatile keywords?
41) ***************Are all the classes specified in import statement actually imported?
42) Can an inheritance relationship exist between two interfaces?
46) What is the meaning of various keywords specified in creating the main method?
47) What is  the purpose of ^ operator?
48) What is the difference between pass by value and pass by reference?
49) ***************What are the various types of inner classes?
50)*************** What are the various memory areas in JVM and what kind of information is stored in each of them?

Phone screen questions : 
Given a domain model, describe the process you follow to create a service.
Expect to hear: UML (class & interaction diagram), Data Model, SQL/DDL, API definition & documentation, Interface, Unit tests, integration tests.
How do you test your services?
Expect: JUnit, TestNG, or similar. Unit & integration tests, test cases.
Describe how you have used the Spring Framework.
Expect: IOC, JDBC Templates, controllers, annotations.
Describe your experience with high-volume website development.
Describe how you have addressed scalability/performance issues with large datasets.
Describe the approach you use to analyze performance issues. (Service API down.) (Web tier)
Expect to hear: profiler, SQL explain plan, debugger
What's the latest version of Java you have used. What, if any, changes did you take advantage of?
What's the latest version of Spring you have used. What, if any, changes did you take advantage of?
Describe the build systems you have used.
Expect: Ant, Maven, other.
Have you used any continuous build systems?
Expect: Cruise control, Hudson, other.
Which sounds like the most fun(Optional):
Refactoring some code that has bothered you for a long time.
Designing a new service API
Creating an AJAX based form processing framework.
Creating an automated testing/performance framework.
Porting a legacy application to your favorite language
===================================================================== 
  • What are the 4 basics of OOP?
  • Define Data Abstraction. What is its importance?
  • Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the number of smaller cubes on the surface. Extend this to k-dimension.
  • What is the time and space complexities of merge sort and when is it preferred over quick sort?
  • Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
  • Explain polymorphism. Provide an example.
  • Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
  • You are given some denominations of coins in an array (int denom[])and infinite supply of all of them. Given an amount (int amount), find the minimum number of coins required to get the exact amount. What is the method called?
  • What is the difference between an object and a class
  • you are provided with a stream of numbers, design a data structure to store the numbers in the stream along with their no. of occurrences.ans:I told him to use a Trie and he asked me why not BST, and asked me to compare both..
  • Given two sorted arrays A1 and A2, of lengths L1 and L2 , L1 < L2 and the last L1 slots in A2 are vacant, get me all the numbers in A2, sorted in the most efficient manner without using extra space. This was a written test question in which I blabbered quick sort will do.......In fact the answer was merge sort. I misunderstood the question a bit and was thinking in some other direction. But after he clarified the question, I wrote the code immediately.
  • In an array of size n, there is one number missing and one number repeated twice. Find them.I was a fool not to notice the sum of numbers and sum of squares of numbers property immediately. But after getting a clue, I answered it.
  • What is the effect by keeping a constructor private? (in terms of inheritance),
  • Say you are using a map in your program, how would you count the number of times the program use put() and the get() function? How would you do that if its using multiple maps in the program? How would you do that if the map is sent as a parameter in a method? How would you do it if the multiple maps are passed into the methods (as parameters), and are use differently? (it went on forever….)
  • What do you know about Java generics
  • what is object reflection in Java
  • What is polymorphism.
  • Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.
  • Coding: I have an integer array where every number appears even number of times and only one appears odd times. Find the number.(I said hashtable and he asked me to write code with Hashtable)
  • What data structure would you use to look up phone numbers for customer names.(I said Hashtable. Asked why hashtable, why not a tree. I said HT has O(1). Asked is order always 1, when more than O(1) in HT.
  • Data Structures: How will you use a hashtable to find data in a tree. (Then he rephrased) suppose I have a hashtable, I want to store the data in a tree instead of a bucket. How will I do it. What complexity to find an element.
  • Bits & Bytes: Find if a binary representation of a number is palindrome. The function should work irrespective of number of bytes for an integer. Suppose if our machine is 4 bytes for an int, how will you use the program for 8 byte machine.
  • What is the flaw in the design of Java.lang.Stack class of Java
  • What is the use of volatile variable.Explain it in Singleton class also for lazy initialization.
  • How to implement your own HashMap in java
  • Why should you not make your Sinleton claas as Serializable and Clonable.
  • What is the limitation of singleton pattern
  • Why Java language designer has chosen to make all the variable inside an Interface as public ,static and final.
  • What are the various ways in singleton pattern can be made to fail and how to avoid them ?
  • The wrapper classes also offer utility methods for converting to and from the int values they represent. Thus if you have a string that could also represent a number, you can use a wrapper class to perform that calculation.
  • I have a class A which implements serializible and there are two sub classes B and C which extends A. I want clsss B not be serializible ? How can I achive it?                                                          Refer  :http://www.careercup.com/question?id=7508689
  • Why do we need thread class when we have Runnable interface ? http://www.careercup.com/question?id=7571666
  • Name all the memories which are available in JVM? I knew only heap and perm. Is there any other memory also? http://www.careercup.com/question?id=7547664
  • What intern method does in java?  http://www.roseindia.net/java/string-examples/string-intern.shtml http://www.careercup.com/question?id=7184154
  • what is daemon thread in java? daemon thread is a low priority thread that is terminated as soon the vm exits. It is generally used to do all the house keeping work like gc thread is a daemon thread.It can be set using thread.setDaemon(true); And then start the thread.  The main thread terminates it if it is finished.
  • What is Java Reflection API? Java reflection supports dynamic retrieval of information about classes and data structures by name, and allows for their manipulation within an executing Java program.
  • What is the difference between Serializable and Externalizable interfaces ?  http://www.careercup.com/question?id=3220676
  • Given a sorted array of n integers that has been rotated left or right by k places, give an algorithm that searches and finds an element in the array in log n time.   Example Input : 8 9 0 1 2 4 5 6 (sorted array rotated right by 2 places)http://www.careercup.com/question?id=2319661
  • What are features of optimum Java code : reusability/modularity,  data/functional abstraction,  complete code coverage,  fail-safe (crashes safely.. no one can totally avoid crashing).. most imp of all.. meet the user requirements.. add more if needed. Takes care of garbage collection.
  • Explain what is in a deployment descriptor file? give an example of a deployment descriptor ?           A deployment descriptor contains configuration data that the run-time environment uses for an application. A deployment descriptor can include information about the following:
               * The structure and content (enterprise beans or servlets, for example) of the application.

              * References to internal and external dependencies of the application. For example, an enterprise bean in an EJB module can require another enterprise bean that is not bundled in the same module.

            * References to resource factory objects, such as URLs, JDBC DataSources, JavaMail Sessions, JMS Connection Factories, JMS Destinations, and J2C Connection Factories.

        * Security roles that the container uses when implementing the required access control for the application.

        * Transactional information about how (and whether) the container is to manage transactions for the application.


  • How does the Collections API handle collisions? How does the API handling making the collection "some-what" collision safe?Explain- which collection does this affect and the best way to deal with it.Also explain, the most common scenario that causes this issue- hint* one is in threading(how can this be caused). Refer for discussion : http://www.careercup.com/question?id=417089
  • Can Java constructor has private or protected access type?                                                        Refer : http://www.careercup.com/question?id=296844
  • Write a Java program that prints the size of a non-primitive Java object.
  • What is the default visibility of an instance variable in java? What is package visibility?
  • What is the use of volatile variable?  http://www.careercup.com/question?id=2726
  • Why should you not make your Singleton class as Serializable and Clonable?http://www.careercup.com/question?id=2711
  • implement a counting semaphore in Java? http://www.careercup.com/question?id=133664
  • write java code for prime number generation?
  • What is the limitation of singleton pattern? http://www.careercup.com/question?id=2789
  • Why is access to static variables not allowed from non-static methods in java?http://www.careercup.com/question?id=2462
  • What is Garbage Collection in Java. How is it implemented? What kind of algorithms does the garbage collector use? How does it know that references can be collected? What are advantages and disadvantages of garbage collection? http://www.careercup.com/question?id=3111
  • How does Java achieve synchronization? Given an class with Synchronized method A and B, a normal method C, there are 2 threads, one instance, can these two threads call A at the same time? call A and B at the same time? A & C at the same time? http://www.careercup.com/question?id=57337
  • You are using a map in your program, how would you count the number of times the program use put() and the get() function? How would you do that if its using multiple maps in the program? How would you do that if the map is sent as a parameter in a method? How would you do it if the multiple maps are passed into the methods (as parameters), and are use differently? (it went on forever....)http://www.careercup.com/question?id=58095

No comments:

Post a Comment