JAVA
Programming
Language
Javaprogramminglanguageisahighlevellanguage,writtenina
human-readableform,makingitprogrammerfriendlyand
enablingittomorefocusontheproblemsolving.
Introduction to Enterprise Java
JAVA
Platform
Javaisaplatform,usedasanenvironmentinwhichJava
programmingapplicationsrun.
Introduction to Enterprise Java
JAVA
Programming
Language
Platform
Introduction to Enterprise Java
Hence,wecansaythatJavaisaprogramminglanguageaswellas
aplatform.
JVM and API
JVM and APIJVM and API
JVM and API
JAVA
PLATFORM
Standard
Edition
(Java SE)
Enterprise
Edition
(Java EE)
Java Programming Language Platforms
Micro
Edition
(Java ME)
JavaFX
JVM and API
JVM and APIJVM and API
JVM and API
JAVA
PLATFORM
Standard
Edition
(Java SE)
Enterprise
Edition
(Java EE)
Micro
Edition
(Java ME)
JavaFX
AlltheJavaplatformconsistsofJavaVirtualMachine(JVM)andan
ApplicationProgramInterface(API),enablingapplicationswrittenforthat
platformtorunonanycompatiblesystemwithallthebenefitsoftheJava
programminglanguage.
WhenwethinkoftheJavaprogramming,usuallywearethinkingaboutthe
JavaStandardEdition(JavaSE)API,whichisalsoknownasCoreJava.
Java Programming Language Platforms
Standard
Edition
(Java SE)
Java
Programming
Java SE API
(Core Java)
Java Programming Language Platforms
Standard
Edition
(Java SE)
JavaSEprovidesthefundamentalfeaturesofJavalanguageinthepurestform.
Itdescribesallthefeatureslikethebasictypes,objects,classesusedfor
developingapplicationsbasedondatabaseaccess,security,networkingand
developingGraphicalUserInterface(GUI).
Java EE platform has the fundamental base of the Java SE platform, used for
applications running on the servers.
Java Programming Language Platforms
Enterprise
Edition
(Java EE)
Java SE
Java EE
Virtual
Machine
Mobile
API
JavaMEplatformservesamobileAPIinconjunctionwithspace-efficient
virtualmachineforexecutingJavaapplicationsonsmalldevices,likemobile
phones.
Java Programming Language Platforms
Micro
Edition
(Java ME)
Java ME
Java Programming Language Platforms
Micro
Edition
(Java ME)
TheAPIisasubsetoftheJavaSEAPIhavingexceptionalclasslibraries
beneficialfordevelopingsmalldeviceapplications.
JavaFX Script
JavaFXisaplatformtobuildinternetbasedapplicationsusingalightweight
user-interfaceAPI,whichiswritteninJavaFXScript.
Java Programming Language Platforms
JavaFX
JavaFX
What is Enterprise Application?
Enterprise
Edition
(Java EE)
ItservesanApplicationProgrammingInterface(API)andruntimeenvironment
forcreating,developingandexecutingextensive,scalable,reliableandmulti-
tieredbusinessapplications.
Inmulti-tieredbusinessapplications,theworkingoftheapplicationis
partitionedintodifferentfunctionalareas,knownastiers.
What is Enterprise Application?
Client Tier
Web Tier
Business Tier
Enterprise Information Systems (EIS) Tier
Client
Tier
Middle
Tier
Data
Tier
What is Enterprise Application?
Client Tier
Web Tier
Business Tier
EIS Tier
Java EE
Server
Client
Machine
Database
Server
User Interface Layer
(Presentation Logic)
Business Processing Layer
(Business Logic)
Data Storage and Access Layer
(Persistence Logic)
What is Enterprise Application?
Java EE Application 1 Java EE Application 2
Client Tier
Client Application Dynamic HTML Pages
Web Tier
Business Tier
EIS Tier
JSP Pages
Enterprise Beans Enterprise Beans
Database Database
Java EE
Server
Client
Machine
Database
Server
RequestDispatcherin Servlet
1) public void forward(ServletRequestrequest,ServletResponse
response)throws ServletException,java.io.IOException:Forwardsa
request from a servlet to another resource (servlet, JSP file, or HTML
file) on the server.
RequestDispatcherin Servlet
2) public void include(ServletRequestrequest,ServletResponse
response)throws ServletException,java.io.IOException:Includesthe
content of a resource (servlet, JSP page, or HTML file) in the response.
Cookies and Sessions
Cookies
•A cookie is a small piece of information that is persisted between the
multiple client requests.
•A cookie has a name, a single value, and optional attributes such as a
comment, path and domain qualifiers, a maximum age, and a version
number.
•Working of Cookies is by default, each request is considered as a new
request.
•In cookies technique, we add cookie with response from the servlet.
Cookies and Sessions
Cookies
•So cookie is stored in the cache of the browser.
•After that if request is sent by the user, cookie is added with request
by default. Thus, we recognize the user as the old user.
Cookies and Sessions
Types of Cookies
1) Non-persistent cookie -It isvalid for single sessiononly. It is removed
each time when user closes the browser.
2) Persistent cookie -It isvalid for multiple session. It is not removed
each time when user closes the browser. It is removed only if user logout
or signout.
Cookies and Sessions
Sessions
•Sessionsimply means a particular interval of time.
•Session Trackingis a way to maintain state (data) of an user.
•It is also known assession managementin servlet.
•Http protocol is a stateless so we need to maintain state using session
tracking techniques.
•Each time user requests to the server, server treats the request as the
new request.
•So we need to maintain the state of an user to recognize to particular
user.
Java Server Pages (JSP)
Introduction
•Java Server Pages (JSP) is a server-side programming technology that
enables the creation of dynamic, platform-independent method for
building Web-based applications.
•JSP have access to the entire family of Java APIs, including the JDBC
API to access enterprise databases.
Java Server Pages (JSP)
Why JSP?
•Performance is significantly better because JSP allows embedding
Dynamic Elements in HTML Pages itself instead of having separate
CGI files.
•JSP are always compiled before they are processed by the server
unlike CGI/Perl which requires the server to load an interpreter and
the target script each time the page is requested.
Java Server Pages (JSP)
Why JSP?
•JavaServerPages are built on top of the Java Servlets API, so like
Servlets, JSP also has access to all the powerful Enterprise Java APIs,
including JDBC, JNDI, EJB, JAXP, etc.
•JSP pages can be used in combination with servlets that handle the
business logic, the model supported by Java servlet template engines.
Java Server Pages (JSP)
Why JSP?
•Finally, JSP is an integral part of Java EE, a complete platform for
enterprise class applications.
•This means that JSP can play a part in the simplest applications to the
most complex and demanding.
Java Server Pages (JSP)
Applications of JSP
1) JSP vs. Active Server Pages (ASP)
•The advantages of JSP are twofold. First, the dynamic part is written
in Java, not Visual Basic or other MS specific language, so it is more
powerful and easier to use. Second, it is portable to other operating
systems and non-Microsoft Web servers.
2) JSP vs. Pure Servlets
•It is more convenient to write (and to modify!) regular HTML than to
have plenty of printlnstatements that generate the HTML.
Java Server Pages (JSP)
Applications of JSP
3) JSP vs. Server-Side Includes (SSI)
•SSI is really only intended for simple inclusions, not for "real"
programs that use form data, make database connections, and the
like.
4) JSP vs. JavaScript
•JavaScript can generate HTML dynamically on the client but can
hardly interact with the web server to perform complex tasks like
database access and image processing etc.
5) JSP vs. Static HTML
•Regular HTML, of course, cannot contain dynamic information.
Java Server Pages (JSP)
Servlet vs JSP
•Following is the distinguish between Servlet and JSP
Java Server Pages (JSP)
JSP Life Cycle
•The JSP pages follow these phases:
1)Translation of JSP Page
2)Compilation of JSP Page
3)Classloading(the classloaderloads class file)
4)Instantiation (Object of the Generated Servlet is created).
5)Initialization ( the container invokes jspInit() method).
6)Request processing ( the container invokes _jspService() method).
7)Destroy ( the container invokes jspDestroy() method).
Java Server Pages (JSP)
JSP Comments
•JSP comment marks to text or statements that the JSP container
should ignore.
•A JSP comment is useful when you want to hide or "comment out", a
part of your JSP page.
•Following is the syntax of the JSP comments −
<%--This is JSP comment --%>
Java Server Pages (JSP)
JSP Documents
•According to the JSP specification, a JSP page can be written in 2
formats:
1)JSP Page Format-A JSP page written in an HTML format with JSP
elements expressed as <% ... %> tags as described in the previous
section.
2)JSP Document Format-A JSP page written in an XML format with
JSP elements expressed as XML elements.
Java Server Pages (JSP)
JSP Elements -JSP Declaration
•A declaration tag is a piece ofJava code for declaring variables,
methods and classes.
•If we declare a variable or method inside declaration tag it means that
the declaration is made inside the servlet class but outside the service
method.
•We can declare a static member, an instance variable (can declare a
number or string) and methods inside the declaration tag.
•Syntax of declaration tag :
<%! Dec var%>
•Here Dec varis the method or a variable inside the declaration tag.
Java Server Pages (JSP)
JSP Elements -JSP Scriptlet
•Scriptlettag allows to write Java code into JSP file.
•JSP container moves statements in _jspservice() method while
generating servlet from jsp.
•For each request of the client, service method of the JSP gets invoked
hence the code inside the Scriptletexecutes for every request.
•A Scriptletcontains java code that is executed every time JSP is
invoked.
•Syntax of Scriptlettag:
<% java code %>
•Here <%%> tags are scripletstag and within it, we can place java
code.
Java Server Pages (JSP)
JSP Elements -JSP Expression
•Expression tag evaluates the expression placed in it.
•It accesses the data stored in stored application.
•It allows create expressions like arithmetic and logical.
•It produces scriptlessJSP page.
•Syntax:
<%= expression %>
•Here the expression is the arithmetic or logical expression.
Java Server Pages (JSP)
JSP Elements -JSP Expression
•Expression tag evaluates the expression placed in it.
•It accesses the data stored in stored application.
•It allows create expressions like arithmetic and logical.
•It produces scriptlessJSP page.
•Syntax:
<%= expression %>
•Here the expression is the arithmetic or logical expression.