SlideShare a Scribd company logo
Advance Java 
Presented by 
Prince Soni
Company Profile
Advance Java 
• Java Core 
▫ Genesis of Java 
• Lesson 3: Name 
▫ Provide brief description, if desired.
Lesson 1: Genesis Of Java 
• Java’s Creator – James Gosling 
• Why Java is so important to Internet ? 
• Java’s Magic : The Bytecode 
• The Java Buzzwords
Quick Walkthrough of Java Core 
• Data Types, Variables, Arrays, 
Operators, Classes, Methods, 
Inheritence 
• Packages, Interfaces, Exception 
Handling, I/O Applets and Networking 
Basics, Collection Framework 
• Event Handling, AWT and Swing
Java Core : Wrap-up 
Few miscellaneous features of Java’s Core to be noted are :- 
• Java is a strongly typed language 
• Java’s Primitive data types – Default Values and size 
• Java’s Automatic Conversion 
• The this keyword 
• Garbage Collection ( Java’s Destructor !! ) 
• Argument passing – Call By Value and Call By Reference 
• Using super to access hidden data 
• Object Class 
• Packages it’s importance and where does Java looks for user defined packages. Role 
of Access Specifier in Packages 
• Java’s extend keyword only support single inheritance. Other forms of inheritance 
could be achieved through interfaces
Java Core : Wrap-up 
• Interfaces – dynamic lookup of a method. 
• Exception handling – Try, Catch, throw, throws, 
finally. Super class – Throwable. It’s sub class – 
Exception and Error 
• Thread Synchronization 
• Collection Framework – D/f Interfaces 
• Swing Using Net Beans IDE.
Lesson 2: JEEE – What is it ???? 
• What Is the Java 2 Enterprise Edition (J2EE)? 
Depending upon whom you ask, Java 2 Enterprise Edition 
(J2EE) is oneof many things :- 
• Web components such as JSPs, Servlets, or Web 
Archives. 
• EJB components, which are Java Archives containing EJB 
code and the deployment descriptor. 
• Client applications, which are stand-alone Java 
executable.
Archives, Descriptor and manifest 
• Descriptors provide configuration information ,environment 
settings, role-based security, and vendor-specific information. 
• The manifest is a packing slip that is automatically generated by 
the archive process. 
• 1. Java Archives (JAR)—A JAR file encapsulates one or more Java 
• classes, a manifest, and a descriptor. JAR files are the lowest 
• level of archive. JAR files are used in J2EE for packaging EJBs 
• and client-side Java Applications. 
• 2. Web Archives (WAR)—WAR files are similar to JAR files, except 
• that they are specifically for web applications made from 
• Servlets, JSPs, and supporting classes. 
• 3. Enterprise Archives (EAR)—An EAR file contains all of the 
• components that make up a particular J2EE application.
Introduction to J2EE Enterprise Architecture 
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
The Web Tier 
Servlets
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
J2EE Architecture 
• Multi-tiered, distributed application model 
• Component based 
• Unified security model 
• Flexible transaction control 
• Web services support 
• Open systems development - not tied into one vendor
Application Servers Copyright 2002 © Paulo Merson 
• In the 90’s, systems should be client-server
Application Servers Copyright 2002 © Paulo Merson 
• Today, enterprise applications use the 
multi-tier model
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
J2EE Components 
• A component is a self-contained functional software unit that is 
assembled into a J2EE application with its related classes and files and 
that communicates with other components. 
• Application clients and applets are components that run on the client. 
• Java Servlets and JavaServer Pages™ (JSP™) technology components are 
Web components that run on the server. 
• Enterprise JavaBeans™ (EJB™) components (enterprise beans) are 
business components that run on the server.
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
J2EE Components 
• Application client 
▫ Web client 
Consists of two parts: (1) dynamic web pages containing various types of markup language 
(HTML, XML, and so on), which are generated by web components running in the server’s web 
tier, and (2) a web browser, which renders the pages received from the server 
▫ Applets 
A web page received from the web tier can include an embedded applet. An applet is a small 
client application written in the Java programming language that executes in the Java virtual 
machine (JVM) installed in the web browser 
▫ Application client 
An application client runs on a client machine and provides a way for users to handle tasks that 
require a richer user interface than can be provided by a mark up language. It typically has a 
graphical user interface (GUI) created from Java’s Swing or AWT APIs, but a command-line 
interface is also possible
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
J2EE Components 
• JavaBeans Components 
▫ Application may include JavaBeans 
▫ Have properties, get- and set- methods 
▫ Not considered J2EE components by the J2EE specification 
• J2EE Web Components 
▫ Either Servlets or JSP pages 
Servlets are Java programming language classes that dynamically process requests and 
construct responses. 
JavaServer Pages are text-based documents that execute as servlets but allow a more natural 
approach to creating static content. 
• Business Components (Enterprise JavaBeans) 
▫ Business code, which is logic that solves or meets the needs of a particular business 
domain such as banking is handled by enterprise beans running in the business tier.
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
The Different Components 
Web browser 
Dynamic web pages 
Applet & optional 
JavaBeans 
components 
Application Client 
JavaServer 
Pages 
Servlets 
JavaBeans 
components 
(optional) 
Entity Beans 
Session Beans 
Message-driven 
Beans 
Database 
and Legacy 
Systems 
Web Tier Business Tier 
Client Tier 
J2EE Server (Container)
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M The Different Containers 
Applet Container 
Web browser 
Java Plug-in 
J2EE Server (Container) 
JavaServer 
Pages 
Servlets 
Entity Beans 
Session Beans 
Message-driven 
Beans 
Database 
and Legacy 
Systems 
Web Container 
EJB Container 
Application client 
Application client 
Container
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Containers and Server-side Technologies 
• A container is a runtime service provides the interface between components and 
the low-level functionality that supports the component 
• A container manages components that have been developed according to the API 
specifications 
• We shall use Sun’s Java System Application Server as our J2EE container. It provides 
both a web container (for servlets and JSPs) and an EJB container (for enterprise 
beans) 
• Servlets and JSPs are server-side technologies that accept HTTP requests from an 
HTML form and return responses in the form of HTML, XHTML or XML documents 
• At runtime, servlets and JSPs are equivalent: You could write an application just 
using servlets or just using JSPs or you could mix them up; we’ll have a look later at 
a suitable policy for choosing when to use servlets or JSPs
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Servlet interface 
• Architecturally all servlets must implement the servlet interface 
• The methods of the Servlet interface are invoked automatically by the servlet container 
• The interface has five methods 
• void init(ServletConfig config) 
▫ This method is called once during the servlet’s execution cycle to initialise the servlet (the argument is supplied by the 
container) 
• ServletConfig getServletConfig() 
▫ Returns an object reference to an object that implements interface ServletConfig (provides access to servlet configuration 
information as well as information about it’s environment (the container) 
• String getServiceInfo() 
▫ Returns information such as the servlet’s author and version 
• void service(ServletRequest request, ServletResponse response) 
▫ This method is called as a result of a client request 
• void destroy() 
▫ Clean up method called when the servlet is destroyed by it’s container
Servlet’s lifecycle - UML state diagram 
Instantiation based on 
a request or at 
container start up 
Does not exist Instantiated 
Initialisation 
Initialisation failed 
Unavailable Initialised and/or 
Ready for requests 
Back to service 
In case of temporary 
unavailability 
HTTP request(s) 
From client(s) 
Destroyed Service 
End of 
Service 
Temporary or permanent thread 
failure 
Time out or container shutdown
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
HttpServlet class 
• Web-based servlets typically extend the HttpServlet class 
• HttpServlet is an abstract class that must be extended to create an HTTP 
servlet suitable for a Web site. A subclass of HttpServlet must override at 
least one method, usually one of these: 
▫ doGet() – if the servlet is to support HTTP GET requests 
▫ doPost() – for HTTP POST requests 
▫ doPut() – for HTTP PUT requests 
▫ doDelete() – for HTTP DELETE requests 
▫ init() and destroy() – to manage resources that are held for the life of 
the servlet 
▫ getServletInfo() – if the servlet is to provide information about itself 
• There's almost no reason to override the service method, which handles 
standard HTTP requests by dispatching them to the handler methods for each 
HTTP request type (the doXXX methods listed above).
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
doGet() and doPost() methods 
• doGet(HttpServletRequest req, HttpServletResponse resp) 
▫ Processes an HTTP GET request; e.g. to retrieve the contents of a specified URL (an HTML 
or XHTML or XML page) 
▫ The response content can be generated dynamically by the servlet 
▫ URL can be typed into a browser’s address or Location field and can be bookmarked 
• doPost(HttpServletRequest req, HttpServletResponse resp) 
▫ Processes an HTTP POST request; typically used to post data from an HTML form to a 
server-side form handler that processes the data (save it in a database or retrieve data 
from the database.) 
▫ Cannot be typed into a browser’s address or Location field and cannot be bookmarked 
▫ an HTTP POST request does not have a restriction on the amount of data transmitted 
• Safer to use doPost() method! 
▫ Except if you’re using a servlet to display information without an associated html page – 
then use doGet() method
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Simple example using doGet() method 
• On the Client side we need: 
▫ An HTML client; e.g. a web browser 
• On the server side we need: 
▫ A servlet with a doGet() method 
▫ A web.xml file that relates the servlet’s URL to the servlet’s Java class 
Usually this is generated for you by the IDE (NetBeans in this case)
The web client 
<html> 
<head> 
<title>HelloServlet</title> 
</head> 
<body> 
<form action="hello" method="get"> 
<p>press Submit to invoke servlet HelloServlet</p> 
<p><input type="submit" name="Submit" value="Submit"></p> 
</form> 
</body> 
</html> 
• This file is called index.html 
• Note the form tags 
▫ The form’s action attribute specifies the servlet’s URL, i.e. hello 
J2EE Enterprise Architecture Enterprise Applications CE00465-M
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
<web-app> 
web.xml 
<display-name>HelloWorld</display-name> 
<servlet> 
<servlet-name>helloservlet</servlet-name> 
<servlet-class>entapps.HelloServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>helloservlet</servlet-name> 
<url-pattern>/hello</url-pattern> 
</servlet-mapping> 
</web-app> 
• Note for each servlet you need two tags 
▫ <servlet> 
▫ <servlet-mapping>
J2EE Enterprise 
Architecture 
Enterprise HelloServlet.java Applications CE00465-M 
package entapps; 
import javax.servlet.*; 
import javax.servlet.http.*; 
import java.io.*; 
public class HelloServlet extends HttpServlet 
{ 
public void doGet(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException 
{ 
response.setContentType("text/html"); 
PrintWriter out = response.getWriter(); 
out.println("<html>"); 
out.println("<head><title>Hello Servlet</title></head>"); 
out.println("<body bgcolor="lightblue">"); 
out.println("<p>Hello World.</p>"); 
out.println("</body></html>"); 
} 
}
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Running in NetBeans 
• In NetBeans you need to build the project, then deploy the project and finally run 
the project. If you choose the run option then NetBeans will automatically build, 
deploy and run the project. 
• Once the application is deployed and run you see the following URL in a web 
browser (assuming you called the project SimpleServlet) 
▫ http://localhost:8080/SimpleServlet/ 
▫ When you hit the submit button Hello World is displayed and the URL becomes 
▫ http://localhost:8080/SimpleServlet/hello?Submit=Submit 
• If you changed the doGet() method to a doPost() method and submit the form the 
URL becomes 
▫ http://localhost:8080/SimpleServlet/hello 
▫ You can’t see the input parameters 
▫ If you bookmark it then you can’t retrieve the URL
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M Adding in request parameters 
• If you wanted to add in the name of the user in the html page 
and display it in the servlets, we would add in 
UserID:<input type ="text" name = "requsername" > 
in the html file 
and 
out.println("<p>from"+request.getParameter("requsername")); 
in the servlet 
• Sometimes you may want to hide the request parameter from 
the user (but still visible when you choose view source from 
within the browser) 
▫ Set the type attribute to “hidden” 
<input type = "hidden" name = "action" value 
="entryform"> 
▫ This will be hidden from the user, you can use it in the servlet by 
String action = 
request.getParameter("action");
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Initialising Servlets 
• Common in real-life servlets 
▫ E.g. initialising database connection pools 
• Use SevletConfig.getInitParameters() to read initialisation parameters 
▫ Call getServletConfig() to obtain the ServletConfig object 
• Set initialisation parameters in web.xml 
• It is common to use the init() method even when you don’t read 
initialisation parameters 
▫ e.g. to set up data structures that don’t change during the life cycle of the 
servlet, to load information from disk, etc.
J2EE Enterprise 
Architecture 
Enterprise Example of Initialising parameters Applications CE00465-M 
<web-app> 
<display-name>HelloWorld</display-name> 
<servlet> 
<init-param> 
<param-name>defaultusername</param-name> 
<param-value>Harry</param-value> 
</init-param> 
<servlet-name>helloservlet</servlet-name> 
<servlet-class>web.HelloServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>helloservlet</servlet-name> 
<url-pattern>/helloservlet</url-pattern> 
</servlet-mapping> 
</web-app>
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Example of Initialising parameters 
public void doPost(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException 
{ 
response.setContentType("text/html"); 
PrintWriter out = response.getWriter(); 
ServletConfig config = getServletConfig(); 
out.println("<html>"); 
out.println("<head><title>HelloServlet</title></head>"); 
out.println("<body bgcolor="lightblue">"); 
out.println("<p>Hello World.</p>"); 
out.println("<p>from " + request.getParameter("requsername")); 
out.println("<p>and from " + 
config.getInitParameter("defaultusername") + 
"the default user"); 
out.println("</body></html>"); 
}
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Request Headers 
• Every request has header information associated with it e.g. whether 
the request is a post or get request, the protocol associated with the 
request, etc. The request object has methods associated to display 
these headers . Below is a servlet that prints these headers out for a 
particular request 
public class ShowRequestHeaders extends HttpServlet 
{ 
public void doGet(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException 
{ 
response.setContentType("text/html"); 
PrintWriter out = response.getWriter(); 
String title = "Servlet Example: Showing Request Headers";
J2EE Enterprise 
Architecture 
Enterprise Request Headers Applications CE00465-M 
out.println( 
"<head><title>Servlet Example: " + 
"Showing Request Headers</title></head>" + 
"<body bgcolor="#B0C4DE ">n" + 
"<h1 align=center>" + title + "</h1>n" + 
"<b>Request Method: </b>" + request.getMethod() + "<br>n" + 
"<b>Request URI: </b>" + 
request.getRequestURI() + "<br>n" + 
"<b>Request Protocol: </b>" + 
request.getProtocol() + "<br><br>n" + 
"<table border=1 align=center>n" + 
"<tr bgcolor=#6495ed">n" + 
"<th>Header Name<th>Header Value"); 
Enumeration headerNames = request.getHeaderNames(); 
while (headerNames.hasMoreElements()) 
{ 
String headerName = (String)headerNames.nextElement(); 
out.println("<tr><td>" + headerName + "</td><td>" ); 
out.println(request.getHeader(headerName) + "</td><td>" ); 
} 
out.println("</table>n</body></html>"); 
}
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M Request Headers
J2EE Enterprise 
Architecture 
Enterprise Statelessness and Sessions Applications CE00465-M 
• HTTP is a stateless protocol 
▫ Each request from a client is treated in isolation from all 
other requests from the same client i.e. there is no 
relationship between the different requests 
▫ A protocol is stateful if the response to a given request may 
depend not only on the current request but also on the 
outcome of previous requests 
• Stateful is important 
▫ With on-line banking you only need to register once 
e.g. looking at your balances, or transferring money from 
one account to another doesn’t require you to re-register for 
every request 
▫ Internet shopping with a shopping cart 
• Session 
▫ The server should be able to identify that a series of requests 
from a single client form a single working session 
• State 
▫ The server should be able to remember information related 
to previous requests in a single session
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Session Tracking with the Java Servlet API 
• The javax.servlet.http.HttpSession interface encapsulates the notion of a 
session 
▫ The request object provides the getSession() method which gives you access to 
the HttpSession object associated with the client making the request 
▫ The HttpSession object is an implicit object and is created for each client by the 
web container 
▫ The web container maintains this object for the duration of the client session 
▫ Each session consumes memory on the server-side, so it’s unwise to keep 
sessions open forever 
Most e-commerce sites limit this interval to less than 30 minutes 
You can specify the session limit time in the web.xml file using a deployment 
descriptor element <session-config>
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Session Methods for Managing State 
• setAttribute() method 
▫ public setAttribute(String name, Object attribute) 
 Binds an object to this session, using the name specified 
• getAttribute() method 
▫ public Object getAttribute(String name) 
This method returns the attribute bound with the specified name in this session, or null if no 
object is bound under the name 
• getAttributeNames() method 
▫ public Enumeration getAttributeNames(String name) 
Returns an Enumeration of String objects containing the names of all the objects bound to this 
session. 
• removeAttribute() method 
▫ public void removeAttribute(String name) 
Removes the object bound with the specified name from this session.
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Using the state management methods 
String un = request.getParameter("username"); 
request.getSession().setAttribute("user", un); 
String un=(String)request.getSession().getAttribute("user");
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Request Dispatching 
• Allows a servlet or a JSP page to dispatch a request to an HTML page, or another 
servlet or JSP page, which will then be responsible for any further processing and for 
generating the response. 
• The request object has an interface for this purpose: javax.servlet.RequestDispatcher 
• The request dispatcher object has two methods which allow delegation of the 
request-response processing to another resource after the dispatching servlet has 
finished any preliminary processing 
▫ public void forward(ServletRequest req, ServletResponse resp) throws ServletException, 
java.io.IOException) 
Allows the request to be forwarded to another servlet or JSP page which then assumes all 
responsibility for producing the response 
▫ public void include(ServletRequest req, ServletResponse resp) throws ServletException, 
java.io.IOException) 
Allows the inclusion of the content produced by another resource in the dispatching servlet’s 
response
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Examples of Request Dispatching 
RequestDispatcher rd = 
request.getRequestDispatcher("oracleconnection"); 
rd.include(request, response); 
String status = 
(String)request.getSession().getAttribute("status"); 
if (status.equalsIgnoreCase("OK")) 
{ 
response.sendRedirect("connection_established.html"); 
} 
else 
{ 
rd = request.getRequestDispatcher("viewerror"); 
rd.forward(request, response); 
}
J2EE Enterprise 
Architecture 
Enterprise Applications CE00465-M 
Examples of Request Dispatching 
• oracleconnection is the name of a servlet, 
OracleConnection.java 
▫ Specified in web.xml 
<servlet> 
<servlet-name>oracleconnection</servlet-name> 
<servlet-class>entapps.OracleConnection</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>oracleconnection</servlet-name> 
<url-pattern>/oracleconnection</url-pattern> 
</servlet-mapping>
Examples of Request Dispatching 
• Status is the name of an attribute that OracleConnection sets to either “OK” or “fail” 
• public void sendRedirect(java.lang.String location) throws java.io.IOException 
▫ Sends a temporary redirect response to the client using the specified redirect 
location URL. This method can accept relative URLs; the servlet container must 
convert the relative URL to an absolute URL before sending the response to the 
client. If the location is relative without a leading '/' the container interprets it as 
relative to the current request URI. If the location is relative with a leading '/' the 
container interprets it as relative to the servlet container root. (source 
java.sun.com) 
• viewerror is the name of a Servlet specified in web.xml.

More Related Content

What's hot

Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
myrajendra
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Java EE 8 Recipes
Java EE 8 RecipesJava EE 8 Recipes
Java EE 8 Recipes
Josh Juneau
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
myrajendra
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
myrajendra
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
Anurag
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
Hitesh-Java
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
Kelum Senanayake
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
myrajendra
 
Dao example
Dao exampleDao example
Dao example
myrajendra
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
IMC Institute
 
Java.sql package
Java.sql packageJava.sql package
Java.sql packagemyrajendra
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
Kaml Sah
 

What's hot (19)

Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
40020
4002040020
40020
 
Java EE 8 Recipes
Java EE 8 RecipesJava EE 8 Recipes
Java EE 8 Recipes
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Java part 3
Java part  3Java part  3
Java part 3
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 

Viewers also liked

Summer training java
Summer training javaSummer training java
Summer training java
Arshit Rai
 
J2EE and Servlet
J2EE and Servlet J2EE and Servlet
J2EE and Servlet
Rishikesh .
 
J2 EEE SIDES
J2 EEE  SIDESJ2 EEE  SIDES
J2 EEE SIDESbputhal
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
Sandeep Rawat
 
J2ee seminar
J2ee seminarJ2ee seminar
J2ee seminar
Sahil Kukreja
 
Pre colonial philippines
Pre colonial philippinesPre colonial philippines
Pre colonial philippinesjascalimlim
 

Viewers also liked (6)

Summer training java
Summer training javaSummer training java
Summer training java
 
J2EE and Servlet
J2EE and Servlet J2EE and Servlet
J2EE and Servlet
 
J2 EEE SIDES
J2 EEE  SIDESJ2 EEE  SIDES
J2 EEE SIDES
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
 
J2ee seminar
J2ee seminarJ2ee seminar
J2ee seminar
 
Pre colonial philippines
Pre colonial philippinesPre colonial philippines
Pre colonial philippines
 

Similar to Advance java1.1

Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
KalsoomTahir2
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1Д. Ганаа
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Rajesh Moorjani
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
ADEEBANADEEM
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup72
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdf
SPAMVEDANT
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
Middleware Training
 
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
SSA KPI
 
Introduction to java_ee
Introduction to java_eeIntroduction to java_ee
Introduction to java_eeYogesh Bindwal
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developement
Archana Jha
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai
raj esaki
 
4. J2EE.pptx
4. J2EE.pptx4. J2EE.pptx
4. J2EE.pptx
HariChandruduM
 
Devjyotippt
DevjyotipptDevjyotippt
Devjyotippt
Gaurav pathak
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
dharmawath
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Core web application development
Core web application developmentCore web application development
Core web application developmentBahaa Farouk
 

Similar to Advance java1.1 (20)

Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
Coursejspservlets00
Coursejspservlets00Coursejspservlets00
Coursejspservlets00
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 
EJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdfEJ NOV-18 (Sol) (E-next.in).pdf
EJ NOV-18 (Sol) (E-next.in).pdf
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
Java Platform and IDE Netbeans 6.7 for Developing Enterprise and Web Applicat...
 
Introduction to java_ee
Introduction to java_eeIntroduction to java_ee
Introduction to java_ee
 
Enterprise application developement
Enterprise application developementEnterprise application developement
Enterprise application developement
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai
 
4. J2EE.pptx
4. J2EE.pptx4. J2EE.pptx
4. J2EE.pptx
 
Devjyotippt
DevjyotipptDevjyotippt
Devjyotippt
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Core web application development
Core web application developmentCore web application development
Core web application development
 

More from Prince Soni

Prince soni btech_fresher_android
Prince soni btech_fresher_androidPrince soni btech_fresher_android
Prince soni btech_fresher_android
Prince Soni
 
4 stars
4 stars4 stars
4 stars
Prince Soni
 
Frequent english words
Frequent english wordsFrequent english words
Frequent english words
Prince Soni
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
Prince Soni
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And Rendering
Prince Soni
 
J2ee
J2eeJ2ee
Advance java1.2
Advance java1.2Advance java1.2
Advance java1.2
Prince Soni
 

More from Prince Soni (7)

Prince soni btech_fresher_android
Prince soni btech_fresher_androidPrince soni btech_fresher_android
Prince soni btech_fresher_android
 
4 stars
4 stars4 stars
4 stars
 
Frequent english words
Frequent english wordsFrequent english words
Frequent english words
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And Rendering
 
J2ee
J2eeJ2ee
J2ee
 
Advance java1.2
Advance java1.2Advance java1.2
Advance java1.2
 

Recently uploaded

NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 

Recently uploaded (20)

NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 

Advance java1.1

  • 1. Advance Java Presented by Prince Soni
  • 3. Advance Java • Java Core ▫ Genesis of Java • Lesson 3: Name ▫ Provide brief description, if desired.
  • 4. Lesson 1: Genesis Of Java • Java’s Creator – James Gosling • Why Java is so important to Internet ? • Java’s Magic : The Bytecode • The Java Buzzwords
  • 5. Quick Walkthrough of Java Core • Data Types, Variables, Arrays, Operators, Classes, Methods, Inheritence • Packages, Interfaces, Exception Handling, I/O Applets and Networking Basics, Collection Framework • Event Handling, AWT and Swing
  • 6. Java Core : Wrap-up Few miscellaneous features of Java’s Core to be noted are :- • Java is a strongly typed language • Java’s Primitive data types – Default Values and size • Java’s Automatic Conversion • The this keyword • Garbage Collection ( Java’s Destructor !! ) • Argument passing – Call By Value and Call By Reference • Using super to access hidden data • Object Class • Packages it’s importance and where does Java looks for user defined packages. Role of Access Specifier in Packages • Java’s extend keyword only support single inheritance. Other forms of inheritance could be achieved through interfaces
  • 7. Java Core : Wrap-up • Interfaces – dynamic lookup of a method. • Exception handling – Try, Catch, throw, throws, finally. Super class – Throwable. It’s sub class – Exception and Error • Thread Synchronization • Collection Framework – D/f Interfaces • Swing Using Net Beans IDE.
  • 8. Lesson 2: JEEE – What is it ???? • What Is the Java 2 Enterprise Edition (J2EE)? Depending upon whom you ask, Java 2 Enterprise Edition (J2EE) is oneof many things :- • Web components such as JSPs, Servlets, or Web Archives. • EJB components, which are Java Archives containing EJB code and the deployment descriptor. • Client applications, which are stand-alone Java executable.
  • 9. Archives, Descriptor and manifest • Descriptors provide configuration information ,environment settings, role-based security, and vendor-specific information. • The manifest is a packing slip that is automatically generated by the archive process. • 1. Java Archives (JAR)—A JAR file encapsulates one or more Java • classes, a manifest, and a descriptor. JAR files are the lowest • level of archive. JAR files are used in J2EE for packaging EJBs • and client-side Java Applications. • 2. Web Archives (WAR)—WAR files are similar to JAR files, except • that they are specifically for web applications made from • Servlets, JSPs, and supporting classes. • 3. Enterprise Archives (EAR)—An EAR file contains all of the • components that make up a particular J2EE application.
  • 10. Introduction to J2EE Enterprise Architecture J2EE Enterprise Architecture Enterprise Applications CE00465-M The Web Tier Servlets
  • 11. J2EE Enterprise Architecture Enterprise Applications CE00465-M J2EE Architecture • Multi-tiered, distributed application model • Component based • Unified security model • Flexible transaction control • Web services support • Open systems development - not tied into one vendor
  • 12. Application Servers Copyright 2002 © Paulo Merson • In the 90’s, systems should be client-server
  • 13. Application Servers Copyright 2002 © Paulo Merson • Today, enterprise applications use the multi-tier model
  • 14. J2EE Enterprise Architecture Enterprise Applications CE00465-M J2EE Components • A component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. • Application clients and applets are components that run on the client. • Java Servlets and JavaServer Pages™ (JSP™) technology components are Web components that run on the server. • Enterprise JavaBeans™ (EJB™) components (enterprise beans) are business components that run on the server.
  • 15. J2EE Enterprise Architecture Enterprise Applications CE00465-M J2EE Components • Application client ▫ Web client Consists of two parts: (1) dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the server’s web tier, and (2) a web browser, which renders the pages received from the server ▫ Applets A web page received from the web tier can include an embedded applet. An applet is a small client application written in the Java programming language that executes in the Java virtual machine (JVM) installed in the web browser ▫ Application client An application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a mark up language. It typically has a graphical user interface (GUI) created from Java’s Swing or AWT APIs, but a command-line interface is also possible
  • 16. J2EE Enterprise Architecture Enterprise Applications CE00465-M J2EE Components • JavaBeans Components ▫ Application may include JavaBeans ▫ Have properties, get- and set- methods ▫ Not considered J2EE components by the J2EE specification • J2EE Web Components ▫ Either Servlets or JSP pages Servlets are Java programming language classes that dynamically process requests and construct responses. JavaServer Pages are text-based documents that execute as servlets but allow a more natural approach to creating static content. • Business Components (Enterprise JavaBeans) ▫ Business code, which is logic that solves or meets the needs of a particular business domain such as banking is handled by enterprise beans running in the business tier.
  • 17. J2EE Enterprise Architecture Enterprise Applications CE00465-M The Different Components Web browser Dynamic web pages Applet & optional JavaBeans components Application Client JavaServer Pages Servlets JavaBeans components (optional) Entity Beans Session Beans Message-driven Beans Database and Legacy Systems Web Tier Business Tier Client Tier J2EE Server (Container)
  • 18. J2EE Enterprise Architecture Enterprise Applications CE00465-M The Different Containers Applet Container Web browser Java Plug-in J2EE Server (Container) JavaServer Pages Servlets Entity Beans Session Beans Message-driven Beans Database and Legacy Systems Web Container EJB Container Application client Application client Container
  • 19. J2EE Enterprise Architecture Enterprise Applications CE00465-M Containers and Server-side Technologies • A container is a runtime service provides the interface between components and the low-level functionality that supports the component • A container manages components that have been developed according to the API specifications • We shall use Sun’s Java System Application Server as our J2EE container. It provides both a web container (for servlets and JSPs) and an EJB container (for enterprise beans) • Servlets and JSPs are server-side technologies that accept HTTP requests from an HTML form and return responses in the form of HTML, XHTML or XML documents • At runtime, servlets and JSPs are equivalent: You could write an application just using servlets or just using JSPs or you could mix them up; we’ll have a look later at a suitable policy for choosing when to use servlets or JSPs
  • 20. J2EE Enterprise Architecture Enterprise Applications CE00465-M Servlet interface • Architecturally all servlets must implement the servlet interface • The methods of the Servlet interface are invoked automatically by the servlet container • The interface has five methods • void init(ServletConfig config) ▫ This method is called once during the servlet’s execution cycle to initialise the servlet (the argument is supplied by the container) • ServletConfig getServletConfig() ▫ Returns an object reference to an object that implements interface ServletConfig (provides access to servlet configuration information as well as information about it’s environment (the container) • String getServiceInfo() ▫ Returns information such as the servlet’s author and version • void service(ServletRequest request, ServletResponse response) ▫ This method is called as a result of a client request • void destroy() ▫ Clean up method called when the servlet is destroyed by it’s container
  • 21. Servlet’s lifecycle - UML state diagram Instantiation based on a request or at container start up Does not exist Instantiated Initialisation Initialisation failed Unavailable Initialised and/or Ready for requests Back to service In case of temporary unavailability HTTP request(s) From client(s) Destroyed Service End of Service Temporary or permanent thread failure Time out or container shutdown
  • 22. J2EE Enterprise Architecture Enterprise Applications CE00465-M HttpServlet class • Web-based servlets typically extend the HttpServlet class • HttpServlet is an abstract class that must be extended to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these: ▫ doGet() – if the servlet is to support HTTP GET requests ▫ doPost() – for HTTP POST requests ▫ doPut() – for HTTP PUT requests ▫ doDelete() – for HTTP DELETE requests ▫ init() and destroy() – to manage resources that are held for the life of the servlet ▫ getServletInfo() – if the servlet is to provide information about itself • There's almost no reason to override the service method, which handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above).
  • 23. J2EE Enterprise Architecture Enterprise Applications CE00465-M doGet() and doPost() methods • doGet(HttpServletRequest req, HttpServletResponse resp) ▫ Processes an HTTP GET request; e.g. to retrieve the contents of a specified URL (an HTML or XHTML or XML page) ▫ The response content can be generated dynamically by the servlet ▫ URL can be typed into a browser’s address or Location field and can be bookmarked • doPost(HttpServletRequest req, HttpServletResponse resp) ▫ Processes an HTTP POST request; typically used to post data from an HTML form to a server-side form handler that processes the data (save it in a database or retrieve data from the database.) ▫ Cannot be typed into a browser’s address or Location field and cannot be bookmarked ▫ an HTTP POST request does not have a restriction on the amount of data transmitted • Safer to use doPost() method! ▫ Except if you’re using a servlet to display information without an associated html page – then use doGet() method
  • 24. J2EE Enterprise Architecture Enterprise Applications CE00465-M Simple example using doGet() method • On the Client side we need: ▫ An HTML client; e.g. a web browser • On the server side we need: ▫ A servlet with a doGet() method ▫ A web.xml file that relates the servlet’s URL to the servlet’s Java class Usually this is generated for you by the IDE (NetBeans in this case)
  • 25. The web client <html> <head> <title>HelloServlet</title> </head> <body> <form action="hello" method="get"> <p>press Submit to invoke servlet HelloServlet</p> <p><input type="submit" name="Submit" value="Submit"></p> </form> </body> </html> • This file is called index.html • Note the form tags ▫ The form’s action attribute specifies the servlet’s URL, i.e. hello J2EE Enterprise Architecture Enterprise Applications CE00465-M
  • 26. J2EE Enterprise Architecture Enterprise Applications CE00465-M <web-app> web.xml <display-name>HelloWorld</display-name> <servlet> <servlet-name>helloservlet</servlet-name> <servlet-class>entapps.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloservlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app> • Note for each servlet you need two tags ▫ <servlet> ▫ <servlet-mapping>
  • 27. J2EE Enterprise Architecture Enterprise HelloServlet.java Applications CE00465-M package entapps; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Hello Servlet</title></head>"); out.println("<body bgcolor="lightblue">"); out.println("<p>Hello World.</p>"); out.println("</body></html>"); } }
  • 28. J2EE Enterprise Architecture Enterprise Applications CE00465-M Running in NetBeans • In NetBeans you need to build the project, then deploy the project and finally run the project. If you choose the run option then NetBeans will automatically build, deploy and run the project. • Once the application is deployed and run you see the following URL in a web browser (assuming you called the project SimpleServlet) ▫ http://localhost:8080/SimpleServlet/ ▫ When you hit the submit button Hello World is displayed and the URL becomes ▫ http://localhost:8080/SimpleServlet/hello?Submit=Submit • If you changed the doGet() method to a doPost() method and submit the form the URL becomes ▫ http://localhost:8080/SimpleServlet/hello ▫ You can’t see the input parameters ▫ If you bookmark it then you can’t retrieve the URL
  • 29. J2EE Enterprise Architecture Enterprise Applications CE00465-M Adding in request parameters • If you wanted to add in the name of the user in the html page and display it in the servlets, we would add in UserID:<input type ="text" name = "requsername" > in the html file and out.println("<p>from"+request.getParameter("requsername")); in the servlet • Sometimes you may want to hide the request parameter from the user (but still visible when you choose view source from within the browser) ▫ Set the type attribute to “hidden” <input type = "hidden" name = "action" value ="entryform"> ▫ This will be hidden from the user, you can use it in the servlet by String action = request.getParameter("action");
  • 30. J2EE Enterprise Architecture Enterprise Applications CE00465-M Initialising Servlets • Common in real-life servlets ▫ E.g. initialising database connection pools • Use SevletConfig.getInitParameters() to read initialisation parameters ▫ Call getServletConfig() to obtain the ServletConfig object • Set initialisation parameters in web.xml • It is common to use the init() method even when you don’t read initialisation parameters ▫ e.g. to set up data structures that don’t change during the life cycle of the servlet, to load information from disk, etc.
  • 31. J2EE Enterprise Architecture Enterprise Example of Initialising parameters Applications CE00465-M <web-app> <display-name>HelloWorld</display-name> <servlet> <init-param> <param-name>defaultusername</param-name> <param-value>Harry</param-value> </init-param> <servlet-name>helloservlet</servlet-name> <servlet-class>web.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloservlet</servlet-name> <url-pattern>/helloservlet</url-pattern> </servlet-mapping> </web-app>
  • 32. J2EE Enterprise Architecture Enterprise Applications CE00465-M Example of Initialising parameters public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ServletConfig config = getServletConfig(); out.println("<html>"); out.println("<head><title>HelloServlet</title></head>"); out.println("<body bgcolor="lightblue">"); out.println("<p>Hello World.</p>"); out.println("<p>from " + request.getParameter("requsername")); out.println("<p>and from " + config.getInitParameter("defaultusername") + "the default user"); out.println("</body></html>"); }
  • 33. J2EE Enterprise Architecture Enterprise Applications CE00465-M Request Headers • Every request has header information associated with it e.g. whether the request is a post or get request, the protocol associated with the request, etc. The request object has methods associated to display these headers . Below is a servlet that prints these headers out for a particular request public class ShowRequestHeaders extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Servlet Example: Showing Request Headers";
  • 34. J2EE Enterprise Architecture Enterprise Request Headers Applications CE00465-M out.println( "<head><title>Servlet Example: " + "Showing Request Headers</title></head>" + "<body bgcolor="#B0C4DE ">n" + "<h1 align=center>" + title + "</h1>n" + "<b>Request Method: </b>" + request.getMethod() + "<br>n" + "<b>Request URI: </b>" + request.getRequestURI() + "<br>n" + "<b>Request Protocol: </b>" + request.getProtocol() + "<br><br>n" + "<table border=1 align=center>n" + "<tr bgcolor=#6495ed">n" + "<th>Header Name<th>Header Value"); Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = (String)headerNames.nextElement(); out.println("<tr><td>" + headerName + "</td><td>" ); out.println(request.getHeader(headerName) + "</td><td>" ); } out.println("</table>n</body></html>"); }
  • 35. J2EE Enterprise Architecture Enterprise Applications CE00465-M Request Headers
  • 36. J2EE Enterprise Architecture Enterprise Statelessness and Sessions Applications CE00465-M • HTTP is a stateless protocol ▫ Each request from a client is treated in isolation from all other requests from the same client i.e. there is no relationship between the different requests ▫ A protocol is stateful if the response to a given request may depend not only on the current request but also on the outcome of previous requests • Stateful is important ▫ With on-line banking you only need to register once e.g. looking at your balances, or transferring money from one account to another doesn’t require you to re-register for every request ▫ Internet shopping with a shopping cart • Session ▫ The server should be able to identify that a series of requests from a single client form a single working session • State ▫ The server should be able to remember information related to previous requests in a single session
  • 37. J2EE Enterprise Architecture Enterprise Applications CE00465-M Session Tracking with the Java Servlet API • The javax.servlet.http.HttpSession interface encapsulates the notion of a session ▫ The request object provides the getSession() method which gives you access to the HttpSession object associated with the client making the request ▫ The HttpSession object is an implicit object and is created for each client by the web container ▫ The web container maintains this object for the duration of the client session ▫ Each session consumes memory on the server-side, so it’s unwise to keep sessions open forever Most e-commerce sites limit this interval to less than 30 minutes You can specify the session limit time in the web.xml file using a deployment descriptor element <session-config>
  • 38. J2EE Enterprise Architecture Enterprise Applications CE00465-M Session Methods for Managing State • setAttribute() method ▫ public setAttribute(String name, Object attribute)  Binds an object to this session, using the name specified • getAttribute() method ▫ public Object getAttribute(String name) This method returns the attribute bound with the specified name in this session, or null if no object is bound under the name • getAttributeNames() method ▫ public Enumeration getAttributeNames(String name) Returns an Enumeration of String objects containing the names of all the objects bound to this session. • removeAttribute() method ▫ public void removeAttribute(String name) Removes the object bound with the specified name from this session.
  • 39. J2EE Enterprise Architecture Enterprise Applications CE00465-M Using the state management methods String un = request.getParameter("username"); request.getSession().setAttribute("user", un); String un=(String)request.getSession().getAttribute("user");
  • 40. J2EE Enterprise Architecture Enterprise Applications CE00465-M Request Dispatching • Allows a servlet or a JSP page to dispatch a request to an HTML page, or another servlet or JSP page, which will then be responsible for any further processing and for generating the response. • The request object has an interface for this purpose: javax.servlet.RequestDispatcher • The request dispatcher object has two methods which allow delegation of the request-response processing to another resource after the dispatching servlet has finished any preliminary processing ▫ public void forward(ServletRequest req, ServletResponse resp) throws ServletException, java.io.IOException) Allows the request to be forwarded to another servlet or JSP page which then assumes all responsibility for producing the response ▫ public void include(ServletRequest req, ServletResponse resp) throws ServletException, java.io.IOException) Allows the inclusion of the content produced by another resource in the dispatching servlet’s response
  • 41. J2EE Enterprise Architecture Enterprise Applications CE00465-M Examples of Request Dispatching RequestDispatcher rd = request.getRequestDispatcher("oracleconnection"); rd.include(request, response); String status = (String)request.getSession().getAttribute("status"); if (status.equalsIgnoreCase("OK")) { response.sendRedirect("connection_established.html"); } else { rd = request.getRequestDispatcher("viewerror"); rd.forward(request, response); }
  • 42. J2EE Enterprise Architecture Enterprise Applications CE00465-M Examples of Request Dispatching • oracleconnection is the name of a servlet, OracleConnection.java ▫ Specified in web.xml <servlet> <servlet-name>oracleconnection</servlet-name> <servlet-class>entapps.OracleConnection</servlet-class> </servlet> <servlet-mapping> <servlet-name>oracleconnection</servlet-name> <url-pattern>/oracleconnection</url-pattern> </servlet-mapping>
  • 43. Examples of Request Dispatching • Status is the name of an attribute that OracleConnection sets to either “OK” or “fail” • public void sendRedirect(java.lang.String location) throws java.io.IOException ▫ Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. (source java.sun.com) • viewerror is the name of a Servlet specified in web.xml.