- What is servlet exception?
It indicates that there is an exception occurred in the servlet.
-
What is a WAR file?
WAR stands for Web Archive. It is a compressed version of your web application. You can use this WAR file to deploy your web application.
-
Explain the directory structure of a web application?
The directory structure of a web application consists of two parts. A private directory called WEB-INF and a public resource directory which contains files server to public. WEB-INF folder consists of web.xml (the deployment descriptor), classes directory (where we keeps all our classes and servlets) and lib directory (where we keeps all our jar files). The public folder contains the static resources of the web application.
-
What is pre initialization of a servlet?
A container doesn’t initialize the servlets when it starts up. It initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or pre initializing a servlet.
-
What are the uses of ServletRequest?
The ServletRequest gives information such as the names of the parameters passed by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it. The input stream, ServletInputStream.
-
How will you communicate from an applet to servlet?
There are three ways to communicate from an applet to servlet and they are: HTTP Communication (Text-based and object-based) , Socket Communication and RMI Communication
-
Can we call a servlet with parameters in the URL?
Yes. You can call a servlet with parameters in the URL like ?param=value
-
How do servlets handle multiple simultaneous requests?
When a request comes in, the web server will start a new thread and the request is assigned to a thread, which calls a service method of the servlet.
-
Is HTML page a web component?
No. Static HTML pages and applets are not considered as web components by J2EE specification. Even the server-side utility classes are not considered web components.
-
Can we implement Runnable interface from within our servlet?
our servlet can implement the Runnable interface.
-
What are the uses of ServletResponse interface?
ServletResponse allows the servlet to set the content length and MIME type of that response. It provides an output stream, ServletOutputStream and a Writer through which the servlet can send data.
-
What is the web container?
Servlet and JSP containers are collectively referred to as Web containers.
-
What is deployment descriptor?
A deployment descriptor is an XML based file which describes a web application’s deployment settings. The name of deployment descriptor of a web application is web.xml.
-
Do objects stored in a HTTP Session need to be serializable? Or can it store any object?
No, the objects need not to be serializable. We can store any type of objects in session.
-
What is the container?
A container is a runtime support of a system-level entity. Containers provide components with services such as lifecycle management, security, deployment, and threading.
-
What is a servlet filter?
Servlet filters are pluggable Web components that allow us to implement pre-processing and post-processing logic in our Web applications.
-
How many JSP scripting elements are there and what are they?
There are three scripting language elements: declarations, scriptlets, expressions.
-
How can you implement singleton pattern in servlets ?
All servlets are singleton only , if the servlet is not implementing SingleThreadModel.
-
How HTTP Servlet handles client requests?
An HTTP Servlet handles client requests through its service method. The service method supports standard HTTP client requests by dispatching each request to a method designed to handle that request.
-
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.
-
What are the different scopes available ?
page, request, session, application
-
Is JSP extensible ?
Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
-
What is the difference between
<%@ include …> (directive include) and jsp:include ?
<%@ include is static include. It is inline inclusion. The contents of the file will get included on Translation phase. It is something like inline inclusion. We cannot have a dynamic filename for directive include. is dynamic include. Here the included file will be processed as a separate file and the response will be included. We can have a dynamic filename for . We can aslo pass parameters to jsp:include
-
Can I just abort processing a JSP?
Yes. You can put a return statement to abort JSP processing.
-
How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
By setting appropriate HTTP header attributes we can prevent caching by the browser
<%
response.setHeader(“Cache-Control”,”no-store”); //HTTP 1.1
response.setHeader(“Pragma”,”no-cache”); //HTTP 1.0
response.setDateHeader (“Expires”, 0); //prevents caching at the proxy server
%>
- What is JSP?
JSP is a server side scripting technology. JSP allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix must ends with .jsp.
- What are JSP Actions?
JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include: jsp:include, jsp:useBean, jsp:setProperty, jsp:getProperty, jsp:forward and Jsp: plugin
- How do you pass data (including JavaBeans) to a JSP from a servlet?
By forwarding the request to the servlet ( the data must be there in the request scope) we can pass the data from a JSP to servlet. Also we can use a session to pass the data.
- What JSP lifecycle methods we can override?
You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page.
- How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe adding the directive
<%@ page isThreadSafe=”false” % >
within your JSP page.
- What are the lifecycle of JSP?
When presented with JSP page the JSP engine does the following 7 phases.
Page translation: -page is parsed, and a java file which is a servlet is created.
Page compilation: page is compiled into a class file
Page loading : This class file is loaded.
Create an instance :- Instance of servlet is created
jspInit() method is called
_jspService is called to handle service calls
_jspDestroy is called to destroy it when the servlet is not required.
- How will you include a static file in a JSP page?
You can include a static resource to a JSP using or <%@ inlcude >.
- How you can perform browser redirection?
We can use the method sendRedirect of HttpServletResponse or forward method of RequestDispatcher.
- Can we use ServletOutputStream object from a JSP page?
No. You are supposed to use JSPWriter object (given to you in the form of the implicit object out) only for replying to clients.
- How can you stop JSP execution in the middle of processing a request?
We can use the return statement to stop the processing of JSP. Because JSP is compiled to servlet and all the statements will go inside service method, any time you can stop the processing using return statement.
- How can I invoke a JSP error page from a servlet?
You can invoke the JSP error page and pass the exception object to it from within a servlet. For that you need to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute.
- How will you pass information from JSP to included JSP?
By using jsp:param tag.
- How does JSP handle runtime exceptions?
Using errorPage attribute of page directive JSP handles runtime exceptions. We need to specify isErrorPage=true if the current page is intended to use as a JSP error page.
- How can I enable session tracking for JSP pages if the browser has disabled cookies?
By default session tracking uses cookies to associate a session identifier with a user. If the browser does not support cookies, or if cookies are disabled, you can still use session tracking using URL rewriting. For URL rewriting to be effective, you need to append the session ID for each and every link that is part of your servlet response. By using the methods response.encodeURL() and response.encodeRedirectURL() we can achieve this.
- How can you declare methods in your JSP page?
you can declare methods as declarations in your JSP page. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions.
- What is the difference between an application server and a web server?
Everything in web server must be achieved programmatically. But application server provides a lot of services like security, transaction , scalability. Application server will be having EJB support where web server don’t have an EJB support.
- How do you pass an init parameter to a JSP?
You need to configure the DD for passing init parameter to a JSP. You can configure the DD as follows.
<servlet>
<servlet-name>test.jsp</servlet-name>
<jsp-file>test.jsp</jsp-name>
<init-param>
<param-name>Abc</param-name>
<param-value>Xyz</param-value>
</init-param>
</servlet>
- What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable in a variety of different environments.
- How can I print the stack trace of an exception from a JSP page?
By creating an object of PrintWriter we can print the stack trace in JSP page. Eg:PrintWriter pw = response.getWriter();
exception.printStackTrace(pw);
- How to refer the “this” variable within a JSP page?
Under JSP 1.0, the page implicit object page is equivalent to “this”, and returns a reference to the servlet generated by the JSP page.
- How many JSP scripting elements and what are they?
There are three scripting elements in JSP . They are declarations, scriptlets, expressions.
- Can we implement an interface in JSP ?
No.
- What is the differecnce between JspWriter and PrintWriter?
JspWriter is buffered.
- Is HTML page a web component?
No. Static HTML pages and applets are bundled with web components during application assembly, but are not considered web components by the J2EE specification. Even the server-side utility classes are not considered web components, either.
- What do Enterprise JavaBeans components contain?
Enterprise JavaBeans components contains Business code, which is logic
that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier. All the business code is contained inside an Enterprise Bean which receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.
- Is J2EE application only a web-based?
No, It depends on type of application that client wants. A J2EE application can be web-based or non-web-based. if an application client executes on the client machine, it is a non-web-based J2EE application. The J2EE application can provide a way for users to handle tasks such as J2EE system or application administration. It typically has a graphical user interface created from Swing or AWT APIs, or a command-line interface. When user request, it can open an HTTP connection to establish communication with a servlet running in the web tier.
- Are JavaBeans J2EE components?
No. JavaBeans components are not considered J2EE components by the J2EE specification. They are written to manage the data flow between an application client or applet and components running on the J2EE server or between server components and a database. JavaBeans components written for the J2EE platform have instance variables and get and set methods for accessing the data in the instance variables. JavaBeans components used in this way are typically simple in design and implementation, but should conform to the naming and design conventions outlined in the JavaBeans component architecture.
- What can be considered as a web component?
J2EE Web components can be either servlets or JSP pages. Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.
- What is the container?
Containers are the interface between a component and the low-level platform specific functionality that supports the component. Before a Web, enterprise bean, or application client component can be executed, it must be assembled into a J2EE application and deployed into its container.
- What makes J2EE suitable for distributed multitiered Applications?
The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs. The J2EE application parts are:
Client-tier components run on the client machine.
Web-tier components run on the J2EE server.
Business-tier components run on the J2EE server.
Enterprise information system (EIS)-tier software runs on the EIS server.
- 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.
- 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 Pages technology components are web components.
Enterprise JavaBeans components (enterprise beans) are business components.
Resource adapter components provided by EIS and tool vendors.
- What are container services?
A container is a runtime support of a system-level entity. Containers provide components with services such as lifecycle management, security, deployment, and threading.
- What is the web container?
Servlet and JSP containers are collectively referred to as Web containers. It manages the execution of JSP page and servlet components for J2EE applications. Web components and their container run on the J2EE server.
- What is J2EE Connector?
The J2EE Connector API is used by J2EE tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged into any J2EE product. Each type of database or EIS has a different resource adapter. Note: A resource adapter is a software component that allows J2EE application components to access and interact with the underlying resource manager. Because a resource adapter is specific to its resource manager, there is typically a different resource adapter for each type of database or enterprise information system.
- What is the EAR file?
An EAR file is a standard JAR file with an .ear extension, named from Enterprise ARchive file. A J2EE application with all of its modules is delivered in EAR file.
- How do we package J2EE components?
J2EE components are packaged separately and bundled into a J2EE application for deployment. Each component, its related files such as GIF and HTML files or server-side utility classes, and a deployment descriptor are assembled into a module and added to the J2EE application. A J2EE application is composed of one or more enterprise bean,Web, or application client component modules. The final enterprise solution can use one J2EE application or be made up of two or more J2EE applications, depending on design requirements. A J2EE application and each of its modules has its own deployment descriptor. A deployment descriptor is an XML document with an .xml extension that describes a component’s deployment settings.
- What is a thin client?
A thin client is a lightweight interface to the application that does not have such operations like query databases, execute complex business rules, or connect to legacy applications.
- What are types of J2EE clients?
Following are the types of J2EE clients:
Applets
Application clients
Java Web Start-enabled rich clients, powered by Java Web Start technology.
Wireless clients, based on Mobile Information Device Profile (MIDP) technology.
- What is deployment descriptor?
A deployment descriptor is an Extensible Markup Language (XML) text-based file with an .xml extension that describes a component’s deployment settings. A J2EE application and each of its modules has its own deployment descriptor. For example, an enterprise bean module deployment descriptor declares transaction attributes and security authorizations
for an enterprise bean. Because deployment descriptor information is declarative, it can be changed without modifying the bean source code. At run time, the J2EE server reads the deployment descriptor and acts upon the component accordingly.
- What is Applet container?
IManages the execution of applets. Consists of a Web browser and Java Plugin running on the client together.
- What is JTA and JTS?
JTA is the abbreviation for the Java Transaction API. JTS is the abbreviation for the Jave Transaction Service. JTA provides a standard interface and allows you to demarcate transactions in a manner that is independent of the transaction manager implementation. The J2EE SDK implements the transaction manager with JTS. But your code doesn’t call the JTS methods directly. Instead, it invokes the JTA methods, which then call the lower-level JTS routines. Therefore, JTA is a high level transaction interface that your application uses to control transaction. and JTS is a low level transaction interface and ejb uses behind the scenes (client code doesn’t directly interact with JTS. It is based on object transaction service(OTS) which is part of CORBA.
- What is JAXP?
JAXP stands for Java API for XML. XML is a language for representing and describing text-based data which can be read and handled by any program or tool that uses XML APIs. It provides standard services to determine the type of an arbitrary piece of data, encapsulate access to it, discover the operations available on it, and create the appropriate JavaBeans component to perform those operations.
- What is Enterprise JavaBeans (EJB) container?
It manages the execution of enterprise beans for J2EE applications.Enterprise beans and their container run on the J2EE server.
- What is JAAP?
The Java Authentication and Authorization Service (JAAS) provides a way for a J2EE application to authenticate and authorize a specific user or group of users to run it. It is a standard Pluggable Authentication Module (PAM) framework that extends the Java 2 platform security architecture to support user-based authorization.
- What is Struts?
A Web page development framework. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
- How is the MVC design pattern used in Struts framework?
In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application’s business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain. Controller: Servlet controller which supplied by Struts itself; View: what you can see on the screen, a JSP page and presentation components; Model: System state and a business logic JavaBeans.
- What is Java Naming and Directory Service?
The JNDI provides naming and directory functionality. It provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes. Using JNDI, a J2EE application can store and retrieve any type of named Java object. Because JNDI is independent of any specific implementations, applications can use JNDI to access multiple naming and directory services, including existing naming and
directory services such as LDAP, NDS, DNS, and NIS.
- Difference between a Class and an Object ?
A class is a definition or prototype whereas an object is an instance or living representation of the prototype.
- What is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
- What are the four corner stones of OOP ?
Abstraction, Encapsulation, Polymorphism and Inheritance.
- What do you understand by private, protected and public ?
These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
- What is the difference between method overriding and overloading?
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.
- What is the restriction on an Overridden methods’ accessibility ?
Overriding methods cannot reduce accessibility – they can either have same or greater accessibility.
- Can a method be overloaded based on different return type but same argument type ?
No, because the methods can be called without using their return type in which case there is ambiquity for the compiler.What is a “stateless” protocol ?
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a
single request response combination.
- What happens to a static var that is defined within a method of a class ?
Can’t do it. You’ll get a compilation error.
- What is constructor chaining and how is it achieved in Java ?
A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args
constructor as the first statement.
- What is Hibernate?
Hibernate is a open source object-relational mapping and query service. In hibernate we can write HQL instead of SQL which save developers to spend more time on writing the native SQL. Hibernate has more powerful association, inheritance, polymorphism, composition, and collections. It is a beautiful approach for persisting into database using the java objects. Hibernate also allows you to express queries using java-based criteria .
- What is the limitation of hibernate?
Slower in executing the queries than queries are used directly.Only query language support for composite keys.
No shared references to value types.
- What are considered as a web component?
Java Servlet and Java Server Pages technology components are web components. Servlets are Java programming language that dynamically receive requests and make responses. JSP pages execute as servlets but allow a more natural approach to creating static content.
- Define Hash table?
HashTable is just like Hash Map,Collection having key(Unique),value pairs. Hashtable is a collection Synchronozed object .It does not allow duplicate values but it allows null values.
- What are the advantage of hibernate.
Hibernate is portable i mean database independent, Vendor independence.
Standard ORM also supports JPA
Mapping of Domain object to relational database.
Hibernate is better then plain JDBC.
JPA provider in JPA based applications.
- What is JSF?
JavaServer Faces (JSF) is a user interface (UI) designing framework for Java web applications. JSF provide a set of reusable UI components, standard for web applications.JSF is based on MVC design pattern. It automatically saves the form data to server and populates the form date when display at client side.
- What is ORM?
ORM stands for Object-Relational mapping. The objects in a Java class which is mapped in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.
- Difference between save and saveorupdate
save() – This method in hibernate is used to stores an object into the database. It insert an entry if the record doesn’t exist, otherwise not.
saveorupdate () -This method in the hibernate is used for updating the object using identifier. If the identifier is missing this method calls save(). If the identifier exists, it will call update method.
- What are the benefits of ORM?
Productivity
Maintainability
Performance
Vendor independence
- Difference between load and get method?
load() can’t find the object from cache or database, an exception is thrown and the load() method never returns null.
get() method returns null if the object can’t be found. The load() method may return a proxy instead of a real persistent instance get() never returns a proxy.
- How to invoke stored procedure in hibernate?
{ ? = call thisISTheProcedure() }
- What the Core interfaces are of hibernate framework?
Session Interface
SessionFactory Interface
Configuration Interface
Transaction Interface
Query and Criteria Interface
- How hibernate is database independent explain?
Only changing the property
<property name=”hibernate.dialect”>org.hibernate.dialect.Oracle9Dialect</property> and
<property name=”hibernate.connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>
full database can be replaced.
- Define connection pooling?
Connection pooling is a mechanism reuse the connection.which contains the number of already created object connection. So whenever there is a necessary for object, this mechanism is used to directly get objects without creating it.
- What is the hibernate proxy?
An object proxy is just a way to avoid retrieving an object until you need it. Hibernate 2 does not proxy objects by default.
- What is the file extension you use for hibernate mapping file?
The name of the file should be like this : filename.hbm.xml
- What is the file name of hibernate configuration file?
The name of the file should be like this : hibernate.cfg.xml
- What is HQL?
HQL stands for Hibernate Query Language. Hibernate allows to the user to express queries in its own portable SQL extension and this is called as HQL. It also allows the user to express in native SQL.
- What are the Collection types in Hibernate ?
Set, List, Array, Map, Bag
- What is a thin client?
A thin client is a program interface to the application that does not have any operations like query of databases, execute complex business rules, or connect to legacy applications.
- How to add hibernate mapping file in hibernate configuration file?
By <mapping resource=†filename.hbm.xmlâ€/>
- Differentiate between .ear, .jar and .war files.
.jar files: These files are with the .jar extenstion. The .jar files contains the libraries, resources and accessories files like property files.
.war files: These files are with the .war extension. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications.
.ear files: The .ear file contains the EJB modules of the application.
- What are the JSP tag?
In JSP tags can be divided into 4 different types.
Directives
Declarations
Scriplets
Expressions
- How to access web.xml init parameters from jsp page?
For example, if you have:
<context-param> <param-name>Id</param-name> <param-value>this is the value</param-value></context-param>
You can access this parameter
Id: <h:outputText value=â€#{initParam[‘Id’]}â€/>
- What are JSP Directives?
1.page Directives <%@page language=â€java†%>
2. include Directives: <%@ include file=â€/header.jsp†%>
3. taglib Directives <%@ taglib uri=â€tlds/taglib.tld†prefix=â€html†%>
- What is the EAR file?
An EAR file is a JAR file with an .ear extension. A J2EE application with all of its modules is delivered in EAR file.
- What is Struts?
Struts framework is a Model-View-Controller(MVC) architecture for designing large scale applications. Which is combines of Java Servlets, JSP, Custom tags, and message. Struts helps you to create an extensible development environment for your application, based on published standards and proven design patterns. Model in many applications represent the internal state of the system as a set of one or more JavaBeans.The View is most often constructed using JavaServer Pages (JSP) technology.The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.
- What is ActionErrors?
ActionErrors object that encapsulates any validation errors that have been found. If no errors are found, return null or an ActionErrors object with no recorded error messages.The default implementation attempts to forward to the HTTP version of this method. Holding request parameters mapping and request and returns set of validation errors, if validation failed; an empty set or null
- What is ActionForm?
ActionForm is a Java bean that associates one or more ActionMappings. A java bean become FormBean when extend org.apache.struts.action.ActionForm class. ActionForm object is automatically populated on the server side which data has been entered by the client from UI. ActionForm maintains the session state for web application.
- What is action mapping?
In action mapping we specify action class for particular url ie path and diffrent target view ie forwards on to which request response will be forwarded.The ActionMapping represents the information that the ActionServlet knows about the mapping of a particular request to an instance of a particular Action class.The mapping is passed to the execute() method of the Action class, enabling access to this information directly.
- What is the MVC on struts?
MVC stands Model-View-Controller.Model: Model in many applications represent the internal state of the system as a set of one or more JavaBeans.View: The View is most often constructed using JavaServer Pages (JSP) technology.
Controller: The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.
- What are different modules in spring?
There are seven core modules in spring
The Core container module
O/R mapping module (Object/Relational)
DAO module
Application context module
Aspect Oriented Programming
Web module
MVC module
- What is Spring?
Spring is a light weight open source framework for the development of enterprise application that resolves the complexity of enterprise application development also providing a cohesive framework for J2EE application development. Which is primarily based on IOC (inversion of control) or DI (dependency injection) design pattern.
- Functionality of ActionServlet and RequestProcessor?
Receiving the HttpServletRequest
Populating JavaBean from the request parameters
Displaying response on the web page Issues
Content type issues handling
Provide extension points
- POPULAR POSTS
- What is JSP?