Java Interview Questions -23

Java Interview Questions -23
 

1. What does application client module contain?
The application client module contains:
--class files,
--an application client deployment descriptoor.
Application client modules are packaged as JAR files with a .jar extension.

2. What is "application client container" ?

A container that supports application client components.

3. What is "application client module" ?

A software unit that consists of one or more classes and an application client deployment descriptor.

4. What are the differences between Ear, Jar and War files? Under what circumstances should we use each one?

There are no structural differences between the files; they are all archived using zip-jar compression. However, they are intended for different purposes.
--Jar files (files with a .jar extension) arre intended to hold generic libraries of Java classes, resources, auxiliary files, etc.
--War files (files with a .war extension) arre intended to contain complete Web applications. In this context, a Web application is defined as a single group of files, classes, resources, .jar files that can be packaged and accessed as one servlet context.
--Ear files (files with a .ear extension) arre intended to contain complete enterprise applications. In this context, an enterprise application is defined as a collection of .jar files, resources, classes, and multiple Web applications.
Each type of file (.jar, .war, .ear) is processed uniquely by application servers, servlet containers, EJB containers, etc.

5. What is "applet" ?

A J2EE component that typically executes in a Web browser but can execute in a variety of other applications or devices that support the applet programming model.

6. What is "applet container" ?

A container that includes support for the applet programming model.

7. What is "application assembler" ?

A person who combines J2EE components and modules into deployable application units.

8. What is "application client" ?

A first-tier J2EE client component that executes in its own Java virtual machine. Application clients have access to some J2EE platform APIs.

9. What does web module contain?The web module contains:

--JSP files,
--class files for servlets,
--GIF and HTML files, and
--a Web deployment descriptor.
Web modules are packaged as JAR files with a .war (Web ARchive) extension.


10. What is "application component provider" ?

A vendor that provides the Java classes that implement components' methods, JSP page definitions, and any required deployment descriptors.

11. What is "application configuration resource file" ?

An XML file used to configure resources for a JavaServer Faces application, to define navigation rules for the application, and to register converters, validators, listeners, renderers, and components with the application.

12. What is "archiving" ?

The process of saving the state of an object and restoring it.

13. What are the four types of J2EE modules?

1. Application client module
2. Web module
3. Enterprise JavaBeans module
4. Resource adapter module

14. What is "asant" ?

A Java-based build tool that can be extended using Java classes. The configuration files are XML-based, calling out a target tree where various tasks get executed.

15. What is "attribute"What is "asant" ?

A qualifier on an XML tag that provides additional information.

16. What is authentication ?

The process that verifies the identity of a user, device, or other entity in a computer system, usually as a prerequisite to allowing access to resources in a system. The Java servlet specification requires three types of authentication-basic, form-based, and mutual-and supports digest authentication.

17. What is authorization?

The process by which access to a method or resource is determined. Authorization depends on the determination of whether the principal associated with a request through authentication is in a given security role. A security role is a logical grouping of users defined by the person who assembles the application. A deployer maps security roles to security identities. Security identities may be principals or groups in the operational environment.

18. What is authorization constraint ?

An authorization rule that determines who is permitted to access a Web resource collection.

19. What is the difference between Session bean and Entity bean?one?The Session bean and Entity bean are two main parts of EJB container.

Session Bean
--represents a workflow on behalf of a cliennt
--one-to-one logical mapping to a client. --created and destroyed by a client
--not permanent objects
--lives its EJB container(generally) does noot survive system shut down
--two types: stateless and stateful beans Entity Bean
--represents persistent data and behavior off this data
--can be shared among multiple clients
--persists across multiple invocations
--findable permanent objects
--outlives its EJB container, survives systeem shutdown
--two types: container managed persistence(CCMP) and bean managed persistence(BMP)

20. What is B2B ?

B2B stands for Business-to-business.

21. What is backing bean ?

A JavaBeans component that corresponds to a JSP page that includes JavaServer Faces components. The backing bean defines properties for the components on the page and methods that perform processing for the component. This processing includes event handling, validation, and processing associated with navigation.

22. What is J2EE?

J2EE is an environment for developing and deploying enterprise applications. The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols that provide the functionality for developing multitiered, web-based applications.

23. What is the J2EE module?

A J2EE module consists of one or more J2EE components for the same container type and one component deployment descriptor of that type.

24. What are the components of J2EE application?

A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and communicates with other components. The J2EE specification defines the following J2EE components:
Application clients and applets are client components.
Java Servlet and JavaServer PagesTM (JSPTM) technology components are web components.
Enterprise JavaBeansTM (EJBTM) components (enterprise beans) are business components.
Resource adapter components provided by EIS and tool vendors.

25. What is basic authentication ?

An authentication mechanism in which a Web server authenticates an entity via a user name and password obtained using the Web application's built-in authentication mechanism.

26. What is bean-managed persistence ?

The mechanism whereby data transfer between an entity bean's variables and a resource manager is managed by the entity bean.

27. What is bean-managed transaction ?

A transaction whose boundaries are defined by an enterprise bean.

28. What is binding (XML) ?

Generating the code needed to process a well-defined portion of XML data.

29. What is binding (JavaServer Faces technology) ?

Wiring UI components to back-end data sources such as backing bean properties.

30. What is caller ?

Same as caller principal.

31. What is caller principal ?

The principal that identifies the invoker of the enterprise bean method.

32. What is build file ?

The XML file that contains one or more asant targets. A target is a set of tasks you want to be executed. When starting asant, you can select which targets you want to have executed. When no target is given, the project's default target is executed.

33. What is business logic ?

The code that implements the functionality of an application. In the Enterprise JavaBeans architecture, this logic is implemented by the methods of an enterprise bean.

34.What is business method ?

A method of an enterprise bean that implements the business logic or rules of an application.

35. What is cascade delete ?

A deletion that triggers another deletion. A cascade delete can be specified for an entity bean that has container-managed persistence.

36. What is callback methods ?

Component methods called by the container to notify the component of important events in its life cycle.

37. What is CDATA ?

A predefined XML tag for character data that means "don't interpret these characters," as opposed to parsed character data (PCDATA), in which the normal rules of XML syntax apply. CDATA sections are typically used to show examples of XML syntax.

38. What is certificate authority ?

A trusted organization that issues public key certificates and provides identification to the bearer.

39. What is client-certificate authentication ?

An authentication mechanism that uses HTTP over SSL, in which the server and, optionally, the client authenticate each other with a public key certificate that conforms to a standard that is defined by X.509 Public Key Infrastructure.

40. What is comment ?

In an XML document, text that is ignored unless the parser is specifically told to recognize it.

41.What is the purpose of serialization?

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialised – converted into a replica of the original object.

42.What is the difference between JDK and JRE?

Java Development Kit (JDK) is the most widely used Java Software Development Kit. Java Runtime Environment (JRE) is an implementation of the Java Virtual Machine which executes Java programs.

43.What is the difference between equals() and “==” ?

Equals is intended to check logical equality and == checks if both references point to same object. (Thanks Sandeep)

44.When will you use Comparator and Comparable interfaces?

java.util.Comparator and java.lang.Comparable
java.util.Comparator compares some other class’s instances, while java.lang.Comparable compares itself with another object.

45.What is the wait/notify mechanism?

This deals with concurrent programming. The wait() and notify() methods are designed to provide a mechanism to allow a thread to be block until a specific condition is met.
However, java.util.concurrent should be used instead of wait() and notify() to reduce complexity.

46.What is the difference between checked and unchecked exceptions?

In general, unchecked exceptions represent defects in the program (bugs), which are normally Runtime exceptions.
Furthermore, checked exceptions represent invalid conditions in areas outside the immediate control of the program.

47.What is the difference between final, finally and finalize?

“final” is the keyword to declare a constant AND prevents a class from producing subclasses. (Thanks Tom Ellis)
“finally” is a block of code that always executes when the try block is finished, unless System.exit() was called. finalize() is an method that is invoked before an object is discarded by the garbage collector.

48.What is the difference between web server and app server?

A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

49.Explain the Struts1/Struts2/MVC application architecture?

Struts was adopted by the Java developer community as a default web framework for developing web applications
The MVC(Model–view–controller) an application that consist of three distinct parts. The problem domain is represented by the Model. The output to the user is represented by the View. And, the input from the user is represented by Controller.

50.What is the difference between forward and sendredirect?

Both method calls redirect you to new resource/page/servlet. The difference between the two is that sendRedirect always sends a header back to the client/browser, containing the data in which you wanted to be redirected.

51.How does a 3 tier application differ from a 2 tier one?

Tiers are the physical units of separation or deployment, while layers are the logical units of separation.
Imagine that you’re designing an e-commerce website. A 3 tier architecture would consist of web pages, a web server and a database, with the corresponding 3 layers being the “Presentation”, “Business Logic” and “Database” layers.
If you take the database tier and layer out then your have a 2 tier architecture.

52.How does the version control process works?

initiate, pull, branch, merge, commit, push.
(Init) Make your own repository. (Pull) Download an existing repository from a url. (Branch / Merge )Make revisions. Commit then push your modifications.

53.What is the difference between JAR and WAR files?

JAR files (Java ARchive) allows aggregating many files into one, it is usually used to hold Java classes in a library.
WAR files (Web Application aRchive) stores XML, java classes, and JavaServer pages for Web Application purposes.

54.What is a Left outer join?

This deals with SQL. Left outer join preserves the unmatched rows from the first (left) table, joining them with a NULL row in the shape of the second (right) table.

55.Why should we go for interservlet communication?

Servlets running together in the same server communicate with each other in several ways.
The three major reasons to use interservlet communication are:
a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object)
b) Servlet reuse - allows the servlet to reuse the public methods of another servlet.
c) Servlet collaboration - requires to communicate with each other by sharing specific information(through method invocation)

56.Is it possible to call servlet with parameters in the URL?

Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).

57.What is Servlet chaining?

Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single
request.In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until
the last servlet is reached. Its output is then sent back to the client.

58.How do you debug the Servlet?

through servlet log();

59.How do u implement threads in servlet?

Intenally implemented

60.How do you handle DataBase access and in which method of the servlet do you like to create connection.

init()

61.If you want to improve the performance how do you create connections for multiple users?

Connection Pooling.

62.where the session data will store?

session objects

63.What is Servlet Context?

This object represents resources shared by a group of servlets like servlet's environment,
Application attributes shared in the context level.

64.How do you trap the debug the errors in servlets.

error log file

65.what is connection pooling?

Class which manages no of user requests for connections to improve the performance.

66. How do servlets handle multiple simultaneous requests?

The server has multiple threads that are available to handle requests. When a request comes in, it
is assigned to a thread, which calls a service method (for example: doGet(), doPost( ) and service( ) ) of the servlet.
For this reason, a single servlet object can have its service methods called by many threads at once.

67.What is use of parseQueryString ?

Parses a query string and builds a hashtable of key-value pairs, where the values are arrays of strings. The query string should have the form of a string packaged by the GET or POST method.

68.what are the types of servlets.

Genereic Servlets,HttpServlets.

69.what are the different methods in HttpServlet.

doGet(),doPost(),doHead,doDelete(),deTrace()

70. What is the ServletConfig() and why are using ServletConfig ?

This interface is implemented by services in order to pass configuration information to a servlet when it is first loaded.A service writer implementing this interface must write methods
for the servlet to use to get its initialization parameters and the context in which it is running.public interface ServletConfig

71. What is meant by the ServletContext() and use of the method ?

public interface ServletContext .The ServletContext interface gives servlets access to information about their environment ,and allows them to log significant events. Servlet writers decide what data to log. The interface is
implemented by services, and used byservlets. Different virtual hosts should have different servlet contexts.

72.What is servlet?
Ans: Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers.

73.What is the difference between an applet and a servlet?

a) Servlets are to servers what applets are to browsers.
b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.

74.what is the lifecycle of a servlet.

Each Servlet has the same life cycle:
a) A server loads and initializes the servlet by init () method.
b) The servlet handles zero or more client’s requests through service( ) method.
c) The server removes the servlet through destroy() method.

75.What is the difference between GET and POST.

a) doGet() method is used to get information, while doPost( ) method is used for posting information.
b) doGet() requests can’t send large amount of information and is limited to 240-255 characters.
However, doPost( )requests passes all of its data, of unlimited length.
c) A doGet( ) request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket
connection as part of its HTTP request body and the exchange are invisible to the client.

76.What are the advantage of using Sessions over Cookies and URLReWriting?

Sessions are more secure and fast becasue they are stored at serverside. But Sessions has to be used combindly with Cookies or URLReWriting for mainting the client id that is sessionid at
client side.Cookies are stored at client side so some clients may disable cookies so we may not sure that the cookies which we are mainting may work or not but in sessions cookies are disable we can
maintain our sessionid using URLReWriting . In URLReWriting we can't maintain large data because it leads to network traffic and access
may be become slow.Where as in seesions will not maintain the data which we have to maintain instead we will maintain only the session id.

77.Who is loading the init() method of servlet?

Web server

78.Why do you need both GET and POST method implementations in Servlet?

A single servlet can be called from differenr HTML pages,so Different method calls can be possible.

79.When init() and Distroy() will be called.

init() is called whenever the servlet is loaded for the first time into the webserver.Destroy will be called whenever the servlet is removed from the webserver.

80.What is the uses Sessions ?

Its a part of the SessionTracking and it is for mainting the client state at server side.

81.What is the advantage of Servlets over other serverside technologies.

PlatForm independent, so once compiled can be used in any webserver.For different processes different threads will execute inbuilt mutithreaded.

82.What is the use of setComment and getComment methods in Cookies ?

setComment:If a user agent (web browser) presents this cookie to a user, the cookie's purpose
will be described using this comment. This is not supported by version zero cookies.
public void setComment(String use)
{}
getComment:Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.

83.What is Server-Side Includes (SSI)?

Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from
servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension
is requested. So HTML files that include server-side includes must be stored with an .shtml extension.

84.What is Single Threaded Model in Servlets and how is it useful give one practical example.

For every single user a differnt copy of this servlet is executed. Credit card transactions.

85.What is session tracking and how do you track a user session in servlets?

Session tracking is a mechanism that servlets use to maintain state about a series requests
from the same user across some period of time. The methods used for session tracking are:
a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password
b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’sbrowser. When the form containing the fields is submitted, the fields are sent back to the server
c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to
include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change.
d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser.
e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session.maxresidents property

86.How many Cookies is supported to the host ?

User agents excepted to support twenty per host.And its take four Kilobytes each.

87.What is meant by Httpsession and what is the use of sessions ?

The HttpSession interface is implemented by services to provide an association between an HTTP client and HTTP server. This session, persists over multiple connections and/or requests during a given time period.
Sessions are used to maintain state and user identity across multiple page requests.HttpSession session = req.getSession(true);

88.What is Cookies and what is the use of Cookies ?

Cookies are used to get user agents (web browsers etc) to hold small amounts of state associated with a user's web browsing.Later that infromation read by server

89.What are cookies and how will you use them?

Cookies are a mechanism that a servlet uses to have a client hold a small amount of stateinformation associated with the user.
a) Create a cookie with the Cookie constructor:
public Cookie(String name, String value)
b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse.addCookie(Cookie cookie)
c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest.getCookie( ).

90.What are the methods in HttpSession and use of those methods?

a) getCreationTime()
Returns the time at which this session representation was created.
b) getId()
Returns the identifier assigned to this session.
c) getLastAccessedTime()
Returns the last time the client sent a request carrying the identifier assigned to the session.
d) getSessionContext()
Returns the context in which this session is bound.
e) getValue(String)
Returns the object bound to the given name in the session's application layer data.
f) getValueNames()
Returns an array of the names of all the application layer data objects bound into the
session.
g) invalidate()
Causes this representation of the session to be invalidated and removed from its context.
h) isNew()
A session is considered to be "new" if it has been created by the server, but the client has
not yet acknowledged joining the session.
j) putValue(String, Object)
Binds the specified object into the session's application layer data with the given name.
k) removeValue(String)
Removes the object bound to the given name in the session's application layer data.

91.How do you communicate between the servlets.

a)servlet chaning
b)Servlet context(RequestDespatcher interface)

92.Can you send the mail from a servlet ,if yes tell how?

yes.using mail API

93.How are Servlets and JSP Pages related?

JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the
page into a servlet. Thus, JSP pages becomeservlets and are transformed into pure Java and then compiled, loaded into the server and executed.

94.How do servlets handle multiple simultaneous requests?

Using Threads

95.How do I automatically reload servlets?

depends upon the server's servlet reload properites.

96.My servlet, which ran correctly under the Servlet 2.0 APIs (Java Web Server 1.1.3) is not running under the Servlet 2.1 APIs (Java Web Server 2.0). What's wrong?

You might have used servlet to servlet communication by using servletcontext methods like getServlet(),getServlets() which are depricated and returns null from new release that is from
servlet2.1 API.

97.What are the types of ServletEngines?

Standalone ServletEngine: A standalone engine is a server that includes built-in support for servlets.
Add-on ServletEngine: Its a plug-in to an existing server.It adds servlet support to a server that was not
originally designed with servlets in mind. Embedded ServletEngine: it is a lightweight servlet deployment platform that can be embedded in
another application.that application become trueserver.

98. What is container in the Context of J2EE?

A container is the interface between a component and the low-level platform specific functionality.The applications such as EJB component must be assembled and deployed on the J2EE container before executing. In other words A J2EE container is a run-time environment for Enterprise Java Beans, Java Server Pages, Servlets, etc. It provides basic functions like security, life cycle management, transaction management, and deployment services. J2EE containers are generally supplied by a J2EE server. Container is a runtime entity that provides services to specialized Java components

99. What is a J2EE component?

A J2EE component is a software unit that is assembled into a J2EE application with related classes and files and it can communicate with other J2EE components
Following are the example of J2EE Componet:
a)Application clients and applets are client components.
b)Java Servlet and JavaServer Pages technology components are web components
c)Enterprise JavaBeans components (enterprise beans) are business components

100. What is a J2EE module?

A J2EE module has one or more J2EE components of the same container type along with one deployment descriptor of that type.

101. How many Types of modules is defined by J2EE specification?

There are four types of modules defined by J2EE specification:
a) Enterprise JavaBeans(EJB)
b) Web
c) application client and
d) resource adapter
Modules can be assembled to J2EE applications

102.What is a Java applet?

An applet is a J2EE component that run on the client. In other words An applet is a program written in the Java language that can be included in an HTML page,like an image.

103.. What is a Java application Client?

An application Client is a J2EE component that run on the client. An application is used to contain a full-function client non Web-based Java application that connects to the J2EE resources defined in the server.



-------------------------------------
Also Read:






































0 comments:

Post a Comment