Sei sulla pagina 1di 8

http://jeremymanson.blogspot.com/2008/05/double-checked-locking.html Question : Does Java provide any construct to find out the size of an object?

Question: Give a simplest way to find out the time a method takes for execution without using any profiling tool? Question: What are wrapper classes? Question: Why do we need wrapper classes? Question: What are checked exceptions? Question: What are runtime exceptions? Question: What is the difference between error and an exception?? Question: How to create custom exceptions? Question: If I want an object of my class to be thrown as an exception object, what should I do? Question: If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object? Question: How does an exception permeate through the code? Question: What are the different ways to handle exceptions? Question: What is the basic difference between the 2 approaches to exception handling...1> try catch block and 2> specifying the candidate exceptions in the throws clause? When should you use which approach? Question: Is it necessary that each try block must be followed by a catch block? Question: If I write return at the end of the try block, will the finally block still execute? Question: If I write System.exit (0); at the end of the try block, will the finally block still execute? 1. How would one analyze and find solutions to HIGH CPU usage by a web application? The CPU usage shoots close to 100% within 3 days of application server restart, and once the CPU reaches close to 100%, the web application hangs? What could be the probable causes? What would be line of approach to resolve this issue.? Basically the candidate who answers this question, should try to reason out the issues which can shoot the CPU usage to 100%. The Interviewer should bascially look the approach and discuss to find a solution. I have asked this question very frequently and the answers give a very

good feedback on the technology grasp of the candidate unlike theorotical questions which have one line answers. 2. How should a web application authenticate user id / passwords combinations? a) should the password be sent in clear text to the server for authentication ? b) should the password be hashed ? c) if hashed, how wud one authenicate the password at server? d) or any other mechanism? 3. Any approach to migrate passwords from an existing web application to migrated web application. ? Java Architect Interview Questions 1. What do you understand by UML. How to interpret UML diagrams? 2. State the effect of encapsulation, inheritance, and use of interfaces on architectural characteristics? 3. Differentiate between 2 tier, 3 tier and n-tier architectures. 4. How do the following characteristics scalability,performance, high availabilty behave based on the above architecture selected. 5. In what all ways (methods/concepts) can we achieve integration with legacy/n-n-legacy applications using JAVA technologies. 6. List the required classes/interfaces that must be provided for an EJB technology. 7. Distinguish stateful and stateless Session beans. 8. Distinguish Session and Entity beans. 9. Recognize appropriate uses for Entity, Stateful Session, and Stateless Session beans. 10. State the transactional behavior in a given scenario for an enterprise bean method with a specified transactional deployment descriptor. 11.Given a requirement specification detailing security and flexibility needs, identify architectures that would fulfill those requirements. 12. Identify costs and benefits of using an intermediate data-access object between an entity bean and the data resource. 13. State the benefits of bean pooling in an EJB container. 14. State the benefits of Passivation in an EJB container. 15. State the benefit of monitoring of resources in an EJB container. 16. Explain how the EJB container does lifecycle management and has the capability to increase scalability. 17. Given a scenario description, distinguish appropriate from inappropriate protocols to implement that scenario. 18. Identify a protocol, given a list of some of its features, where the protocol is one of the following: HTTP, HTTPS, IIOP, JRMP.

19. Select from a list, common firewall features that might interfere with the normal operation of a given protocol. 20. State the benefits of using design patterns. 21. State the name of a design pattern given the UML diagram and/or a brief description of the pattern's functionality. 22. Select from a list benefits of a specified design pattern. 23. Identify the design pattern associated with a specified J2EE feature. 24. Identify scenarios that are appropriate to implementation using messaging, EJB, or both. 25. List benefits of synchronous and asynchronous messaging. 26. Select scenarios from a list that are appropriate to implementation using synchronous and asynchronous messaging. 27. State three aspects of any application that might need to be varied or customized in different deployment locales. 28. Match the following features of the Java 2 platform with descriptions of their functionality, purpose or typical uses: Properties, Locale, ResourceBundle, Unicode, java.text package, 29. InputStreamReader and OutputStreamWriter. 30. Select from a list security restrictions that Java 2 environments normally impose on applets running in a browser. 31. Given an architectural system specification, identify appropriate locations for implementation of specified security features, and select suitable technologies for implementation of those features. J2EE Interview Questions 1. What do you understand by the term J2EE? J2EE is a specification. provides middleware services. EJB JDBC JNDI JMS JavaMail JTA Servlets JSPs Connectors JAAS EJB : is Server Side component architecture for developing distributed applications. Developers need to concentrate only on business logic. The middleware services are provided by appserver. (transaction management,persistence, threading,concurreny ) Session Beans : Model processes Entity Beans : Model data Message Driven beans : Similar to session beans. Invoked only by sending messages. 2. Diff between RMI and EJB EJB uses RMI technology. We have to declare the middleware services needed by the EJB in a descriptor. The Appserver will generate stubs for the same.

RMI : one has to write the middleware services. (txn mgmt, persitence.) EJB cannot be invoked directly by remote clients because there are not network enabled. Location transparency. 3. How many tiers does an J2EE application have? Explain multi-tier applications? 4. What is a web component? A web componenet is a software entity which runs on a web server, handles requests and generates dynamic web content. 5. What is a web container? Runtime environment for servlets and jsp Manages lifecycle of instances Supports HTTP 6. Should web container always be a part of web server? No. 7.What are servlets? 8. What are JSPs? 9.What are web services? 10.Explain SOA? 11. Explain EJB containers? 12.What is the purpose of init() in servlet class? 13. Can servlets have constructors? Can they be used for initializing servlets instead of init() Yes. But we shouldnt. Reason being init has access to servlet config and servlet context object , constructors wont. 14.Name JSP scripting elements? declarations, scriptlets, expressions. 15.What is SingleThreadModel ? 16. How to implement a thread-safe JSP page? What directive should be added? %@ page isThreadSafe="false" % 17 .How can we include static files within a JSP page? Answer: using the JSP include directive.

18.Distinguish between servletconfig and servlet context? 19.What is the difference in between doPost and doGet methods ? 20.Why does EJB needs two interface( Home and Remote Interface) ? 21.Explain deployment descriptors? 22.Why cant we invoke methods on ejbs directly ? 23.Explain clustering and fault tolerance 24.How would you go about analyzing performance of the application Application performance testing When performance testing a Web application, several requirements must be determined either through interpretation of data from an existing application that performs similar work. Those requirements are: User base What is the expected number of users that will access this application? This is generally expressed in hits per month, day, hour, or minute depending on volumes. Total concurrent users During a peak interval, what is the maximum possible number of users accessing the application at the same time. Peak request rate How many pages will need to be served per second?

1. You need to insert huge amount of objects and randomly delete them one by one. Which Collection data structure is best pet? 2. What goes wrong if the HashMap key has same hashCode value? 3. If hashCode() method is overridden but equals() is not, for the class A, then what may go wrong if you use this class as a key in HashMap? 4. How will you remove duplicate element from a List? 5. How will you synchronize a Collection class dynamically? 1. Write a Java program to create three threads namely A, B, C and make them run one after another. (C has to run after B completes, B has to run after A completes). 2. What happens when a thread calls notify() but no thread(s) is waiting? 3. How will you declare a timer variable that will be accessed by multiple threads very frequently? 4. How will you synchronize static variables? 5. What happens when threads are waiting, but never being notified?

1. Many ways to do it. I prefer join(). When a thrad A calls b.join(), then A runs only after thread b completes. So, for this problem, C has to call b.join() and B has to call a.join() 2. Actually, nothing the notify() call simply returns. 3. Declare the variable as volatile. Every thread caches a copy of instance variable, work with local copy, and then sync it with master copy. But, threads do not cache a copy of volatile instance variable. 4. Obtain class level lock.

1. Give the use and an example of the scenario where you would use serialVersionUID in a your Java class? 2. Design a Employee class with name, empId, age and address fields. o Any two Employee objects are compared based on their age. o The empId is the unique id for Employee class. The Employee class can be used in Collections and HashMap. 3. Explain what goes in a HashMap or Hashtable, when you store the objects with same hashcode values. Explain your answer in very depth. 4. In JVM Memory, where the private, public, protected, static, String literal and object references are stored? 5. How will you store your exception stack trace in a file? (you should not redirect the console output) 6. What is the use of Weak, Soft, Phantom references in Garbage Collection of java? Give scenarios. 7. How will you keep an object alive for ever in the JVM memory? (trick: use finalize() method)

1. After hitting submit button, a JSP page processes a database transaction. You have accidentally closed the browser window. Will the database transaction continue or will get over? 2. What is the difference between http GET and POST methods ? 3. There are 10 servlets in your web application, and they are frequently used (sticky Servlet). How will you optimize their loading? 4. How will you communicate across Servlets? (or, how will you achieve Inter Servlet communication?) 5. Hope, you know the difference between RequestDispatcher.forward() and RequestDispatcher.sendRedirect(). So, which one is desirable to use? 6. What is the class path hierarchy for a Servlet? 7. You cant read files (located out of tomcat directory) from JSP and Servlets for security purpose. But, how will you access those files from JSP or Servlets, in case if you need them?

Design Patterns Interview Questions

1. How will you design your Singleton Patten class to be thread-safe? (a standard interview question!) 2. What Design Pattern can be used for classical Producer Consumer problem? (a simple question) 3. M.S Word can store million lines of text. Each character in the text will have set of properties like font-color, font-size, font-style and etc. So, M.S Word application has to maintain a property structure for each and every character and that may lead to heavy storage. What design pattern will you apply to overcome this problem? 4. Your application uses 1000 classes and they have interaction among each other. This will lead to complex communication across objects, so what design pattern can solve this problem? 5. An application reads input from various clients in multiple stages and creates a binary tree structure out of all received inputs. Which design pattern can be used to design such application? 6. You have to design a budget management application for global users. But, have to provide an option to configure their native tax rules. Which design pattern, do you think, can solve this? 7. You have a core application class. But, you have to be able assign extra functionalities to the core class on the fly (at runtime). Which patterns deserves this purpose? 1. ANSWER: Adding synchronized keyword tothe getSingleton() method is inefficient solution. Initialize the static private Singleton object within Synchronized block. In this way you can achieve it. 2.ANSWER: Use observer pattern (publisher subscriber model) 3. ANSWER: You have to create property group for each possible styles (font-size, fontcolor, font-face & etc). So, common characters will be part of a property group, there by reducing the storage of each character. This is called FlyWeight Pattern. 4. ANSWER: Use Mediator pattern to separate the direct communication across objects. 5. ANSWER: Building an object in multiple set - you call it Builder pattern! The realworld example is XSDBuilder class in Java. 6. ANSWER: Use Template Pattern. It provides templates of methods and allowing you to override certain portion of logic. 7. ANSWER: Decorator Pattern. This is similar to the pattern designed for java.io.* classes(BufferedReader, DataInputStream and etc.) Performance Tuning Question :

Assume a multiplication operation in java takes 10 milliseconds. So, what is the running time of the following for() loop?
int k = 10; for(int i=0; i<100; i++) { k = 20 * 100; // this takes 10 millisecond. }

You have to write a java program that can read files of varying sizes, ranging from 100 KB (very small) to few GBs (large size). You have to use JDBC (type 4 driver) to retrieve some values from two different tables in database. As you have to use join operation in this case, will you consider using join in the sql query level or in the program level? How will you plan your optimization strategy for a given J2EE (or Java) application? Give some strategy to optimize web tier (JSP/Servlets)? How will you tune the Data base tier?

public class X { private long myVar; public void setIt(long var){ myVar = var; } public long getIt() { return myVar; } } It's not thread-safe because the instance variable is a 64-bit primitive. Read-only operations on instance-level primitives are atomic for 32-bit variables. But atomicity is not guaranteed for 64-bit variables because the JVM spec allows implementations to use two 32-bit read operations to access a 64-bit value. If a thread is in the process of reading the two 32-bit words of myVar, an interrupting thread could write to the high or low word of myVar before the first thread successfully reads both. This would result in a corrupt return value from getIt().

Potrebbero piacerti anche