1. What are the different kinds of enterprise beans?
Different kind of enterrise beans are Stateless session bean, Stateful session bean, Entity bean, Message-driven bean.
2. What is Session Bean?
A session bean is a non-persistent object that implements some business logic running on the server. One way to think of a session object.
3. What is Entity Bean?
The entity bean is used to represent data in the database. It provides an object-oriented interface to .
4. What are the methods of Entity Bean?
An entity bean consists of 4 groups of methods, create methods.
5. What is the difference between Container-Managed Persistent (CMP) bean and Bean-Managed Persistent(BMP) ?
Container-managed persistence (CMP) and bean-managed persistence (BMP). With CMP, the container manages the persistence of the entity bean.
6. What are the callback methods in Entity beans?
Callback methods allows the container to notify the bean of events in
its life cycle. The callback methods are defined in the javax.ejb.EntityBean interface.
7. What is software architecture of EJB?
Session and Entity EJBs consist of 4 and 5 parts respectively, a remote interface.
JAVA Interview Questions And Answers
Monday, 28 June 2010
Tuesday, 22 June 2010
Struts
1. What is Jakarta Struts Framework?
Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
2. What is ActionServlet?
The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
3. How you will make available any Message Resources Definitions file to the Struts Framework Environment?
Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through tag.
Example:message-resources parameter=\"MessageResources\" .
4. What is Action Class?
The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.
5. What is ActionForm?
An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
6. What is Struts Validator Framework?
Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.
The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
7. Give the Details of XML files used in Validator Framework?
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
8. How you will display validation fail errors on jsp page?
Following tag displays all the errors:
'<'html:errors'/>'
9. How you will enable front-end validation based on the xml in validation.xml?
The tag to allow front-end validation based on the xml in validation.xml. For example the code: generates the client side java script for the form \"logonForm\" as defined in the validation.xml file. The when added in the jsp file generates the client site validation script.
10. How to get data from the velocity page in a action class?
We can get the values in the action classes by using data.getParameter(\"variable name defined in the velocity page\");
Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
2. What is ActionServlet?
The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
3. How you will make available any Message Resources Definitions file to the Struts Framework Environment?
Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through
Example:message-resources parameter=\"MessageResources\" .
4. What is Action Class?
The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.
5. What is ActionForm?
An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
6. What is Struts Validator Framework?
Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.
The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
7. Give the Details of XML files used in Validator Framework?
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
8. How you will display validation fail errors on jsp page?
Following tag displays all the errors:
'<'html:errors'/>'
9. How you will enable front-end validation based on the xml in validation.xml?
The
10. How to get data from the velocity page in a action class?
We can get the values in the action classes by using data.getParameter(\"variable name defined in the velocity page\");
Thursday, 17 June 2010
JSP and Servlet
1. What is the difference between JSP and Servlets ?
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.
2. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag's behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences:Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
3. What are the different ways for session tracking?
Cookies, URL rewriting, HttpSession, Hidden form fields
4.What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information
5. Difference between GET and POST
In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure.
6. What is session?
The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server.
7. What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.
8. What is servlet context ?
The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.
9. What is a servlet ?
servlet is a java program that runs inside a web container.
10. Can we use the constructor, instead of init(), to initialize servlet?
Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
12. How many JSP scripting elements are there and what are they?
There are three scripting language elements: declarations, scriptlets, expressions.
13.How do I include static files within a JSP page?
Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.
14. How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe adding the directive
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.
2. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag's behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences:Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
3. What are the different ways for session tracking?
Cookies, URL rewriting, HttpSession, Hidden form fields
4.What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information
5. Difference between GET and POST
In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure.
6. What is session?
The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server.
7. What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.
8. What is servlet context ?
The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.
9. What is a servlet ?
servlet is a java program that runs inside a web container.
10. Can we use the constructor, instead of init(), to initialize servlet?
Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
12. How many JSP scripting elements are there and what are they?
There are three scripting language elements: declarations, scriptlets, expressions.
13.How do I include static files within a JSP page?
Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.
14. How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe adding the directive
Sunday, 13 June 2010
Core Java
1. What if the main method is declared as private?
The program compiles properly but at runtime it will give “Main method not public.” message.
2.What is meant by pass by reference and pass by value in Java?
Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value.
3.If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()
4. Expain the reason for each keyword of public static void main(String args[])?
public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.
static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.
void: main does not return anything so the return type must be void
The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.
5. what is difference between == and equals
The == operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory.
== compares references while .equals compares contents. The method public boolean equals(Object obj) is provided by the Object class and can be overridden. The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator == being used to compare aliases to the object. String, BitSet, Date, and File override the equals() method. For two String objects, value equality means that they contain the same character sequence. For the Wrapper classes, value equality means that the primitive values are equal.
6.What if the static modifier is removed from the signature of the main method?
Or
What if I do not provide the String array as the argument to the method?
Program compiles. But at runtime throws an error “NoSuchMethodError”.
7.What is the difference between final, finally and finalize? What do you understand by the java final keyword?
o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection
Variables defined in an interface are implicitly final. A final class can’t be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant). finalize() method is used just before an object is destroyed and garbage collected. finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.
The program compiles properly but at runtime it will give “Main method not public.” message.
2.What is meant by pass by reference and pass by value in Java?
Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value.
3.If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()
4. Expain the reason for each keyword of public static void main(String args[])?
public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.
static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.
void: main does not return anything so the return type must be void
The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.
5. what is difference between == and equals
The == operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory.
== compares references while .equals compares contents. The method public boolean equals(Object obj) is provided by the Object class and can be overridden. The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator == being used to compare aliases to the object. String, BitSet, Date, and File override the equals() method. For two String objects, value equality means that they contain the same character sequence. For the Wrapper classes, value equality means that the primitive values are equal.
6.What if the static modifier is removed from the signature of the main method?
Or
What if I do not provide the String array as the argument to the method?
Program compiles. But at runtime throws an error “NoSuchMethodError”.
7.What is the difference between final, finally and finalize? What do you understand by the java final keyword?
o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection
Variables defined in an interface are implicitly final. A final class can’t be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant). finalize() method is used just before an object is destroyed and garbage collected. finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.
8. Is sizeof a keyword in java?
The sizeof operator is not a keyword.
9. What is a native method?
A native method is a method that is implemented in a language other than Java.
10. In System.out.println(), what is System, out and println?
System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.
Saturday, 29 May 2010
INTERVIEW SKILLS
BEFORE INTERVIEW
First of all, prepare your mind in advance, that you are going to have an interview next morning. Relax yourself and do not get nervous, tense or tired at any cost. Before going for an interview, pre-planned few things:
1. Learn about the company, organization or educational institution and do some research in advance.
2. Why should you perform an advance research?
3. Simply to develop good answers and to prove yourself unique.
4. What you have to Research?
5. You can gather information about organizational structure; type of their clients/ students; departments and its branches; past and present achievements etc. Simply search yellow pages or ask your friend or family member/relative who are familiar about organization or you can collect information through newspapers and websites.
Prepare answers to typical questions. Practice your answer and never rote learn it. Here are few of the sampling questions, which you can practice in advance.
1. What do you feel about our organization?
2. What are your weaknesses?
3. Why do you want to become a part of our organization?
4. Tell me about your self and about your hobbies.
5. Who is your role model and why? If you are lucky to know the name of a person, who will interview you, then memorizes his/her name properly. Decide what to wear. Remember to Dress simply but elegantly. Dress should be well ironed without crease. Wear comfortable shoes. remember to wear basic hosiery. You can even check what management wears and dress similarly without over kill. Do not Dress casual or wear Athletic Shoes. Do not spray lots of cologne or wear lots of jewellery. Do not wear wrinkled attire or flashing tie. Prepare your file having your portfolio, educational degree copies and extra copies of your resume. Find proper address in advance, that where are you going in the morning. Last but not the least;get a good night sleep.
First of all, prepare your mind in advance, that you are going to have an interview next morning. Relax yourself and do not get nervous, tense or tired at any cost. Before going for an interview, pre-planned few things:
1. Learn about the company, organization or educational institution and do some research in advance.
2. Why should you perform an advance research?
3. Simply to develop good answers and to prove yourself unique.
4. What you have to Research?
5. You can gather information about organizational structure; type of their clients/ students; departments and its branches; past and present achievements etc. Simply search yellow pages or ask your friend or family member/relative who are familiar about organization or you can collect information through newspapers and websites.
Prepare answers to typical questions. Practice your answer and never rote learn it. Here are few of the sampling questions, which you can practice in advance.
1. What do you feel about our organization?
2. What are your weaknesses?
3. Why do you want to become a part of our organization?
4. Tell me about your self and about your hobbies.
5. Who is your role model and why? If you are lucky to know the name of a person, who will interview you, then memorizes his/her name properly. Decide what to wear. Remember to Dress simply but elegantly. Dress should be well ironed without crease. Wear comfortable shoes. remember to wear basic hosiery. You can even check what management wears and dress similarly without over kill. Do not Dress casual or wear Athletic Shoes. Do not spray lots of cologne or wear lots of jewellery. Do not wear wrinkled attire or flashing tie. Prepare your file having your portfolio, educational degree copies and extra copies of your resume. Find proper address in advance, that where are you going in the morning. Last but not the least;get a good night sleep.
Friday, 28 May 2010
How to Answer Interview Questions for a Java Job
Do you have an interview coming up for the Java job of your dreams and need to refresh your memory and prepare yourself for this important technical interview? You could be asked any number of questions about your knowledge of Java, so you want to be prepared. Here are some examples of the types of questions you might be expected to answer with expertise.
Step 1
Explain what the disparity is between an interface and an abstract class. For this question, you would elaborate on the fact that an abstract class has method bodies inside it's code which is not tolerated in an interface.
Step 2
Describe your understanding of the term synchronization. Here, you would explain that it is a technical directive that admits shared resources by various threads. The result is that only one thread can be accessed to one resource at any one time.
Step 3
Assess how you can force or coerce what is known as garbage collection. Here, you can correctly tell your interviewer that you can't do that. However, go on to explain that you could call up garbage collection by going to System.gc(), but it doesn't guarantee that it'll be started right away.
Step 4
Interpret you would use Java packages. Here, you would explain to your interviewer that Java packages are used to organize files for a project that has various modules. Further, you could elaborate that Java packages also help to clear up naming conflicts when various packages utilize the same class names.
Step 5
Decipher what OOPS means. Proudly tell the interviewer that OOPS stands for Object-Oriented Programming. Your interviewer may proceed to ask you to describe the principles of OOPS. Describe the three main ones--Polymorphism, Inheritance, and Encapsulation.
Step 6
Determine what the inheritance principle is and what the polymorphism principle is. This would be a two-part question. Phrase your wording carefully. First, tell the interviewer that the inheritance principle is the method by which one object takes over the properties of another. Continue to explain that polymorphism permits one entity to be utilized as a universal classification for a variety of actions.
Step 7
Identify what the differences are between a stack and a queue. Here, tell the interviewer that queues utilize the first-in-first-out rule (FIFO), and stacks work under the last-in-first-out rule (LIFO).
Step 1
Explain what the disparity is between an interface and an abstract class. For this question, you would elaborate on the fact that an abstract class has method bodies inside it's code which is not tolerated in an interface.
Step 2
Describe your understanding of the term synchronization. Here, you would explain that it is a technical directive that admits shared resources by various threads. The result is that only one thread can be accessed to one resource at any one time.
Step 3
Assess how you can force or coerce what is known as garbage collection. Here, you can correctly tell your interviewer that you can't do that. However, go on to explain that you could call up garbage collection by going to System.gc(), but it doesn't guarantee that it'll be started right away.
Step 4
Interpret you would use Java packages. Here, you would explain to your interviewer that Java packages are used to organize files for a project that has various modules. Further, you could elaborate that Java packages also help to clear up naming conflicts when various packages utilize the same class names.
Step 5
Decipher what OOPS means. Proudly tell the interviewer that OOPS stands for Object-Oriented Programming. Your interviewer may proceed to ask you to describe the principles of OOPS. Describe the three main ones--Polymorphism, Inheritance, and Encapsulation.
Step 6
Determine what the inheritance principle is and what the polymorphism principle is. This would be a two-part question. Phrase your wording carefully. First, tell the interviewer that the inheritance principle is the method by which one object takes over the properties of another. Continue to explain that polymorphism permits one entity to be utilized as a universal classification for a variety of actions.
Step 7
Identify what the differences are between a stack and a queue. Here, tell the interviewer that queues utilize the first-in-first-out rule (FIFO), and stacks work under the last-in-first-out rule (LIFO).
Subscribe to:
Posts (Atom)