SlideShare a Scribd company logo
1 of 121
ADVANCED JAVA PROGRAMMING
Dr P PRABAKARAN
Assistant Professor
Department of Computer Applications
School of Computing Sciences
Vels Institute of Science Technology and Advanced Studies, Chennai
ADVANCED JAVA PROGRAMMING
APPLETS- ARCHITECTURE
ADVANCED JAVA PROGRAMMING
APPLET – BASICS
Applets in Java are small and dynamic internet-based programs. A Java Applet can be only
executed within the applet framework of Java. For an easy execution of applets, a restricted
‘sandbox’ is provided by the applet framework.
Generally, the applet code is embedded within an HTML page. The applet codes are
executed when the HTML pages get loaded into the Java-compatible web browsers.
ADVANCED JAVA PROGRAMMING
APPLET – BASICS
ADVANCED JAVA PROGRAMMING
APPLET- SKELETON
Four of these methods—init( ), start( ), stop( ), and destroy( )—are defined by Applet. Another, paint( ), is
defined by the AWT Component class.
init() : init() is the first method to be called. This is where variable are initialized. This method is called
only once during the runtime of applet.
start() : start() method is called after init(). This method is called to restart an applet after it has been
stopped.
stop() : stop() method is called to suspend thread that does not need to run when applet is not visible.
destroy() : destroy() method is called when your applet needs to be removed completely from memory.
ADVANCED JAVA PROGRAMMING
SIMPLE APPLET
/*<applet code = “Hell” width=300 height=300></applet>*/
import java.applet.Applet;
import java.awt.Graphics;
public class Hell extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello World", 20, 20);
}
}
ADVANCED JAVA PROGRAMMING
REQUESTING REPAINTING HTML APPLET TAG
An applet writes to its window only when its paint( ) method is called by the AWT.
Whenever your applet needs to update the information displayed in its window, it simply
calls repaint( ).
The repaint( ) method is defined by the AWT. It causes the AWT run-time system to execute
a call to your applet’s update( ) method,
ADVANCED JAVA PROGRAMMING
REQUESTING REPAINTING HTML APPLET TAG
1.void repaint( )
This version causes the entire window to be repainted.
2.void repaint(int left, int top, int width, int height)
This version specifies a region that will be repainted.
3. void repaint(long maxDelay)
Here, maxDelay specifies the maximum number of milliseconds that can elapse before update( ) is
called.
4.void repaint(long maxDelay, int x, int y, int width, int height)
ADVANCED JAVA PROGRAMMING
PASSING PARAMETERS TO APPLETS
Parameters specify extra information that can be passed to an applet from the HTML page.
Parameters are specified using the HTML’s param tag.
Param Tag
The <param> tag is a sub tag of the <applet> tag. The <param> tag contains two
attributes: name and value which are used to specify the name of the parameter and the
value of the parameter respectively.
ADVANCED JAVA PROGRAMMING
GRAPHICS
All graphics are drawn relative to a window. This can be the main window of an applet, a
child window of an applet, or a stand-alone application window.
The origin of each window is at the top-left Coordinates 0,0. Coordinates are specified in
pixels. All output to a window takes place through a graphics context.
A graphics context is encapsulated by the Graphics class and is obtained in two ways:
It is passed to an applet when one of its various methods, such as paint() or update(), is
called.
It is returned by the getGraphics( ) method of Component.
ADVANCED JAVA PROGRAMMING
GRAPHICS
Methods of Graphics class
public abstract void drawString(String str, int x, int y): is used to draw the specified string.
public void drawRect(int x, int y, int width, int height): draw a rectangle with the specified
width and height.
public abstract void fillRect(int x, int y, int width, int height): is used to fill the rectangle
with the default color and specified width and height.
public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with
the specified width and height.
ADVANCED JAVA PROGRAMMING
FONT
Font is a class that belongs to the java.awt package. It implements the Serializable
interface. FontUIResource is the direct known subclass of the Java Font class.
It represents the font that are used to render the text. In Java, there are two technical
terms that are used to represent font are characters and Glyphs.
Types of Fonts in Java
Physical Fonts
Logical Fonts
ADVANCED JAVA PROGRAMMING
COLORCLASSES
The primary purpose of AWT Color is to allow developers to create new colors using Java
code using RGB (red, green, blue), RGBA (red, green, blue, alpha), or HSB (hue, saturation,
BRI components) packages.
The class contains two values - the code of the shade and the value of
opacity/transparency.
Color defines several constants (for example, Color.black) to specify a number of common
colors. We can also create your own colors, using one of the color constructors.
ADVANCED JAVA PROGRAMMING
SWING-JAPPLET
JApplet is a java swing public class designed for developers usually written in Java. JApplet is
generally in the form of Java bytecode that runs with the help of a Java virtual machine
(JVM) or Applet viewer from Sun Microsystems. It was first introduced in 1995.
JApplet can also be written in other programming languages and can later be compiled to
Java byte code.
Java applets can be executed on multiple platforms which include Microsoft Windows,
UNIX, Mac OS and Linux. JApplet can also be run as an application, though this would
require a little extra coding.
ADVANCED JAVA PROGRAMMING
JFRAME
The javax.swing.JFrame class is a type of container which inherits the java.awt.Frame class.
JFrame works like the main window where components like labels, buttons, textfields are
added to create a GUI.
create a JFrame
JFrame class has many constructors that are used to create a new JFrame. You can create a
JFrame using these methods:
JFrame(): This helps in creating a frame which is invisible.
JFrame(String Title): Helps in creating a frame with a title.
JFrame(GraphicsConfiguration gc): Creates a frame with blank title and the graphics
configuration of screen.
ADVANCED JAVA PROGRAMMING
JCOMPONENT DIFFERENCES BETWEEN COMPONENT
No. Java AWT Java Swing
1)
AWT components are platform-
dependent.
Java swing components are platform-independent.
2)
AWT components are heavyweight. Swing components are lightweight.
3)
AWT doesn't support pluggable look and
feel.
Swing supports pluggable look and feel.
ADVANCED JAVA PROGRAMMING
CONTAINER
An applet container is the environment that runs a Java applet and provides secure applet
execution. Examples include Web browsers and the applet viewer in Java's software
development kit (SDK).
Types of Containers
The Container class, like Component is an abstract class. It has two direct subclasses:
Panel, which is only used for grouping components;
Window, which is, as its name says, for creating and handling windows.
ADVANCED JAVA PROGRAMMING
ICONS
Swing introduces the concept of an icon for use in a variety of components.
The Icon interface and ImageIcon class make dealing with simple images extremely easy.
The Icon interface is very simple, specifying just three methods used to determine the size
of the Icon and to display it. Implementors of this interface are free to store and display the
image in any way, providing a great deal of flexibility.
ADVANCED JAVA PROGRAMMING
JLabel
The object of JLabel class is a component for placing text in a container. It is used to display
a single line of read only text. The text can be changed by an application but a user cannot
edit it directly. It inherits JComponent class.
Java JTextField
The object of a JTextField class is a text component that allows the editing of a single line
text. It inherits JTextComponent class.
ADVANCED JAVA PROGRAMMING
Java JButton
The JButton class is used to create a labeled button that has platform independent
implementation. The application result in some action when the button is pushed. It
inherits AbstractButton class.
Java JCheckBox
The JCheckBox class is used to create a checkbox. It is used to turn an option on (true) or off
(false). Clicking on a CheckBox changes its state from "on" to "off" or from "off" to "on ". It
inherits JToggleButton class.
ADVANCED JAVA PROGRAMMING
Java JRadioButton
The JRadioButton class is used to create a radio button. It is used to choose one option
from multiple options. It is widely used in exam systems or quiz.
It should be added in ButtonGroup to select one radio button only.
Java JComboBox
The object of Choice class is used to show popup menu of choices. Choice selected by user
is shown on the top of a menu. It inherits JComponent class.
Remote Method Invocation
RMI – OVERVIEW
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing
in one system (JVM) to access/invoke an object running on another JVM.
RMI applications are often comprised of two separate programs:
 a server and
 a client.
RMI provides the mechanism by which the server and the client communicate and pass
information back and forth.
Remote Method Invocation
RMI – OVERVIEW
RMI system uses an existing web server to load class definitions, from server to client and
from client to server, for objects when needed.
Remote Method Invocation
RMI – OVERVIEW
Creating Distributed Applications by Using RMI
1. Designing and implementing the components of your distributed application.
2. Compiling sources.
3. Making classes network accessible.
4. Starting the application.
Remote Method Invocation
RMI ARCHITECTURE
It is always a need for communication between two different applications. In Java-based
applications, one application communicates with another remote/different application
running somewhere else by using a mechanism called RMI architecture.
Remote Method Invocation
RMI ARCHITECTURE
Application Layer
client and server, which are involved in communication. The java program on the client side
communicates with the java program on the server-side.
Stub
It is an object that resides on the client machine, and it acts as a proxy for the remote
object. It is like a gateway for the client program.
Remote Method Invocation
RMI ARCHITECTURE
Skeleton
The server object which resides in a server machine is known as Skeleton. Stub
communicates with server application with the help of an intermediate Skeleton object.
Stub / Skeleton layer
The Stub/Skeleton layer is responsible for intercepting calls made by the client and
redirecting these calls to the remote object. This layer is also called as Proxy Layer. Stub and
Skeleton are the proxies for client and server.
Remote Method Invocation
RMI ARCHITECTURE
Remote Reference Layer
The proxy layer is connected to the RMI mechanism through the Remote Reference Layer.
This layer is responsible for the communication and transfer of objects between client and
server.
Transport Layer
The transport layer is responsible for setting up communication between the two
machines. This layer uses standard TCP/IP protocol for connection.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
The following steps to write the RMI program.
 Create the remote interface
 Provide the implementation of the remote interface
 Compile the implementation class and create the stub and skeleton objects using the
rmic tool
 Start the registry service by rmiregistry tool
 Create and start the remote application
 Create and start the client application
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 1 - Define the Remote Interface
1. A remote interface provides describes all the methods of a particular remote object.
2. The client communicates with this remote interface.
3. To create a remote interface −
4. Create an interface that extends the predefined interface Remote which belongs to the
package.
5. Declare all the business methods that can be invoked by the client in this interface.
6. Since there is a chance of network issues during remote calls, an exception
RemoteException may occur; throw it.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 2 - Develop the Implementation Class or Remote Object
1. Implementation Class or Remote Object can be written separately or can be written
directly with the server program implementation.
2. To develop an implementation class −
3. Implement the interface created in the previous step.
4. Provide implementation to all the abstract methods of the remote interface.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
3 - Develop the Server Program
1. An RMI server program should implement the remote interface or extend the implementation
class. To develop a server program −
2. Create a client class from where you want to invoke the remote object.
3. Create a remote object by instantiating the implementation class as shown below.
4. Export the remote object using the method exportObject() of the class
UnicastRemoteObject which belongs to the package java.rmi.server.
5. Get the RMI registry using the getRegistry() method of the LocateRegistry class which belongs
to the package java.rmi.registry.
6. Bind the remote object created to the registry using the bind() method of the class Registry. To
this method, pass a string representing the bind name and the object exported, as parameters.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 4 - Develop the Client Program
1. Write a client program, fetch the remote object and invoke the required method using the
remote object. To develop a client program −
2. Create a client class from where your are intended to invoke the remote object.
3. Get the RMI registry using the getRegistry() method of the LocateRegistry class which belongs
to the package java.rmi.registry.
4. Fetch the object from the registry using the method lookup() of the class Registry which belongs
to the package java.rmi.registry.
5. To this method, you need to pass a string value representing the bind name as a parameter. This
will return you the remote object.
6. The lookup() returns an object of type remote.
7. Finally, invoke the required method using the obtained remote object.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 5 - Compile the Application
Compile the application in the following manner
1. Compile the Remote Interface.
2. Compile the Implementation Class.
3. Compile the Server Program.
4. Compile the Client Program. Or,
5. Open the folder where you have stored all the programs and compile all the Java files.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 5 - Compile the Application
Compile the application in the following manner
1. Compile the Remote Interface.
2. Compile the Implementation Class.
3. Compile the Server Program.
4. Compile the Client Program. Or,
5. Open the folder where you have stored all the programs and compile all the Java files.
Remote Method Invocation
DEVELOPING APPLICATION WITH RMI DECLARING
Step 6 - Execute the Application
1. Step 1 - Start the RMI registry using the command. start rmiregistry This will start an
RMI registry in a separate window.
2. Step 2 − Run the server class file java Server
3. Step 3 − Run the client class file java Client
Remote Method Invocation
EJB INTRODUCTION
 EJB is a server-side software element that summarizes business logic of an application.
 EJB (Enterprise Java Bean) is used to develop scalable, robust and secured enterprise
applications in java.
 The EJB enumeration aims to provide a standard way to implement the server-side
business software typically found in enterprise applications.
 To run EJB application we need an application server (EJB Container) such as Jboss,
Glassfish, Weblogic, Websphere etc.
Remote Method Invocation
EJB INTRODUCTION
Types of Enterprise Java Beans
 Session beans
 Message-driven beans
Session Beans
Session beans are plain old Java objects which function as server-side extension performing
business logic.
Session beans are plain old Java objects which function as server-side extension performing
business logic.
Remote Method Invocation
EJB INTRODUCTION
Types of Session beans
Stateless Session Beans (SLSB) - Provide user generic business processing and are not tied
to a specific client.
Stateful Session Beans (SFSB) - Provide user-specific business processing and are tied to a
specific client.
Singleton Session Beans (SSB) - Provide shared data access to clients and components
within an application and are instantiated only once per application.
Remote Method Invocation
EJB INTRODUCTION
Message-driven beans
Message-driven beans are EJB beans which are driven with the help of messages.
Types of Message-driven beans
JMS (Java Messaging System) Message-driven beans
Non-JMS Message-driven beans
Remote Method Invocation
EJB TRANSACTION
A transaction is a single unit of work items, which follows the ACID properties. ACID stands
for Atomic, Consistent, Isolated, and Durable.
Atomic − If any of the work item fails, the whole unit will be considered failed. Success
meant, all items execute successfully.
Consistent − A transaction must keep the system in consistent state.
Isolated − Each transaction executes independent of any other transaction.
Durable − Transaction should survive system failure if it has been executed or committed.
Remote Method Invocation
EJB TRANSACTION
A transaction is a single unit of work items, which follows the ACID properties. ACID stands
for Atomic, Consistent, Isolated, and Durable.
Atomic − If any of the work item fails, the whole unit will be considered failed. Success
meant, all items execute successfully.
Consistent − A transaction must keep the system in consistent state.
Isolated − Each transaction executes independent of any other transaction.
Durable − Transaction should survive system failure if it has been executed or committed.
Java Server Page
INTRODUCTION TO JSP
 It stands for Java Server Pages.
 It is a server side technology.
 It is used for creating web application.
 It is used to create dynamic web content.
 In this JSP tags are used to insert JAVA code into HTML pages.
 It is an advanced version of Servlet Technology.
Java Server Page
INTRODUCTION TO JSP
Features of JSP
Coding in JSP is easy :- As it is just adding JAVA code to HTML/XML.
Reduction in the length of Code :- In JSP we use action tags, custom tags etc.
Connection to Database is easier :-It is easier to connect website to database and allows to
read or write data easily to the database.
Make Interactive websites :- In this we can create dynamic web pages which helps user to
interact in real time environment.
Portable, Powerful, flexible and easy to maintain :- as these are browser and server
independent.
Java Server Page
INTRODUCTION TO JSP
JSP syntax
Declaration Tag :-It is used to declare variables.
Syntax:-
<%! Dec var %>
Example:-
<%! int var=10; %>
Java Server Page
INTRODUCTION TO JSP
Java Scriplets :- It allows us to add any number of JAVA code, variables and expressions.
Syntax:-
<% java code %>
JSP Expression :- It evaluates and convert the expression to a string.
Syntax:-
<%= expression %>
Java Server Page
INTRODUCTION TO JSP
Process of Execution
 Create html page from where request will be sent to server eg try.html.
 To handle to request of user next is to create .jsp file Eg. new.jsp
 Create project folder structure.
 Create XML file eg my.xml.
 Create WAR file.
 Start Tomcat
 Run Application
Java Server Page
JSP LIFE CYCLE
JSP Life Cycle is defined as translation of JSP Page into servlet as a JSP Page needs to be
converted into servlet first in order to process the service requests. The Life Cycle starts
with the creation of JSP and ends with the disintegration of that.
Following steps are involved in the JSP life cycle:
1.Translation Phase
2.Compilation Phase
3.Initialization Phase
4.Execution Phase
5.Destruction(Cleanup) Phase
Java Server Page
JSP LIFE CYCLE
Java Server Page
JSP LIFE CYCLE
Transalation Phase
When a user navigates to a page ending with a .jsp extension in their web browser, the web
browser sends an HTTP request to the webserver.
The webserver checks if a compiled version of the JSP page already exists.
If the JSP page's compiled version does not exist, the file is sent to the JSP Servlet engine, which
converts it into servlet content (with .java extension). This process is known as translation.
The web container automatically translates the JSP page into a servlet. So as a developer, you don't
have to worry about converting it manually.
Java Server Page
JSP LIFE CYCLE
Compilation Phase
In case the JSP page was not compiled previously or at any point in time, then the JSP page is compiled by the
JSP engine.
In this compilation phase, the Translated .java file of the servlet is compiled into the Java servlet .class file.
Initialization Phase
In this Initialization phase: Here, the container will:
Load the equivalent servlet class.
Create instance.
Call the jspInit() method for initializing the servlet instance.
Java Server Page
JSP LIFE CYCLE
Execution Phase
This Execution phase is responsible for all JSP interactions and logic executions for all
requests until the JSP gets destroyed. As the requested JSP page is loaded and initiated, the
JSP engine has to invoke the _jspService() method. This method is invoked as per the
requests, responsible for generating responses for the associated requests, and responsible
for all HTTP methods.
Java Server Page
JSP LIFE CYCLE
Destruction (Cleanup) Phase
This destruction phase is invoked when the JSP has to be cleaned up from use by the
container. The jspDestroy() method is invoked. You can incorporate and write cleanup
codes inside this method for releasing database connections or closing any file.
Java Server Page
ATTRIBUTES IN JSP
.
S.No. Attribute & Purpose
1
buffer
Specifies a buffering model for the output stream.
2
autoFlush
Controls the behavior of the servlet output buffer.
3
contentType
Defines the character encoding scheme.
4
errorPage
Defines the URL of another JSP that reports on Java unchecked runtime exceptions.
5
isErrorPage
Indicates if this JSP page is a URL specified by another JSP page's errorPage attribute.
Java Server Page
JSP ELEMENTS
 JSP Declaration
 JSP Scriptlet
 JSP Expression
 JSP Comments
Java Server Page
JSP ELEMENTS
JSP Declaration
A declaration tag is a piece of Java 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.
Syntax of declaration tag:
<%! Dec var %>
Java Server Page
JSP ELEMENTS
JSP Scriptlet
Scriptlet tag 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
Scriptlet executes for every request.
A Scriptlet contains java code that is executed every time JSP is invoked.
Syntax of Scriptlet tag:
<% java code %>
Java Server Page
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 scriptless JSP page.
Syntax:
<%= expression %>
Java Server Page
JSP ELEMENTS
JSP Comments
Comments are the one when JSP container wants to ignore certain texts and statements.
When we want to hide certain content, then we can add that to the comments section.
Syntax:
<% -- JSP Comments %>
Java Server Page
JSP DIRECTIVES
 JSP directives are the messages to JSP container. They provide global information about an
entire JSP page.

 JSP directives are used to give special instruction to a container for translation of JSP to servlet
code.

 In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.

 They give instructions to the container on how to handle certain aspects of JSP processing
Java Server Page
JSP DIRECTIVES
 JSP directives are the messages to JSP container. They provide global information about an
entire JSP page.
 JSP directives are used to give special instruction to a container for translation of JSP to servlet
code.
 In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.
 They give instructions to the container on how to handle certain aspects of JSP processing
Syntax of Directive:
<%@ directive attribute="" %>
Java Server Page
JSP DIRECTIVES
 JSP directives are the messages to JSP container. They provide global information about an
entire JSP page.

 JSP directives are used to give special instruction to a container for translation of JSP to servlet
code.

 In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.

 They give instructions to the container on how to handle certain aspects of JSP processing
Java Server Page
JSP DIRECTIVES
Types of directives:
Page directive
Include directive
Taglib directive
Java Server Page
JSP DIRECTIVES
JSP Page directive
Syntax of Page directive:
<%@ page…%>
It provides attributes that get applied to entire JSP page.
It defines page dependent attributes, such as scripting language, error page, and buffering
requirements.
It is used to provide instructions to a container that pertains to current JSP page.
Java Server Page
JSP DIRECTIVES
JSP Include directive
JSP “include directive”( codeline 8 ) is used to include one file to the another file
This included file can be HTML, JSP, text files, etc.
It is also useful in creating templates with the user views and break the pages into header & footer and
sidebar actions.
It includes file during translation phase
Syntax of include directive:
<%@ include….%>
Java Server Page
JSP DIRECTIVES
JSP Taglib Directive
JSP taglib directive is used to define the tag library with “taglib” as the prefix, which we can use in JSP.
More detail will be covered in JSP Custom Tags section
JSP taglib directive is used in the JSP pages using the JSP standard tag libraries
It uses a set of custom tags, identifies the location of the library and provides means of identifying custom tags in JSP page.
Syntax of taglib directive:
<%@ taglib uri="uri" prefix="value"%>
Java Server Page
JSP DECLARATIONS
A JSP declaration is used to declare variables and methods in a page's scripting language.
The code written inside the jsp declaration tag is placed outside the service() method of auto
generated servlet.
So it doesn't get memory at each request.
Syntax of JSP declaration tag
<%! field or method declaration %>
Java Server Page
EXPRESSIONS
Expression tag evaluates the expression placed in it, converts the result into String and
send the result back to the client through response object. Basically it writes the result to
the client(browser).
Syntax of expression tag in JSP:
<%= expression %>
Java Server Page
SCRIPT LET
In JSP, java code can be written inside the jsp page using the scriptlet tag. Let's see what are
the scripting elements first.
A scriptlet tag is used to execute java source code in JSP. Syntax is as follows:
<% java source code %>
Java Server Page
ACTION ELEMENTS
Each JSP action tag is used to perform some specific tasks.
The action tags are used to control the flow between pages and to use Java Bean.
JSP Action Tags Description
jsp:forward forwards the request and response to another resource.
jsp:include includes another resource.
jsp:useBean creates or locates bean object.
jsp:setProperty sets the value of property in bean object.
Java Server Page
USING SESSION OBJECT AND COOKIES
Cookies
Generally Cookies are defined as the text files it will be stored in the computer mainly in
the client machine for tracking purposes like login details, file transfer, etc.
We can also saw the cookies in web browsers in web applications using debug mode
choose “Application -> Storage-. Cookies” we can see whatever we see the web
applications or websites in the cookies column.
Java Server Page
JSP WORKING WITH JAVA MAIL
JavaMail API and the Java Activation Framework (JAF) should be installed on the machine
to send emails using JSP. Download these files and unzip them in newly formed directories.
Amongst many jar files, add mail.jar and activation.jar file to the Classpath.
Java Server Page
USAGE OF USE BEAN TAG
The jsp:useBean action tag is used to locate or instantiate a bean class. If bean object of
the Bean class is already created, it doesn't create the bean depending on the scope. But if
object of bean is not created, it instantiates the bean.
Syntax of jsp:useBean action tag
<jsp:useBean id= "instanceName" scope= "page | request | session | application"
class= "packageName.className" type= "packageName.className"
beanName="packageName.className | <%= expression >" >
</jsp:useBean>
Java Server Page
USAGE OF USE BEAN TAG
The jsp:useBean action tag is used to locate or instantiate a bean class. If bean object of
the Bean class is already created, it doesn't create the bean depending on the scope. But if
object of bean is not created, it instantiates the bean.
Syntax of jsp:useBean action tag
<jsp:useBean id= "instanceName" scope= "page | request | session | application"
class= "packageName.className" type= "packageName.className"
beanName="packageName.className | <%= expression >" >
</jsp:useBean>
JDBC CONNECTION SETTINGS
 Register the Driver class
 Create connection
 Create statement
 Execute queries
 Close connection
JDBC CONNECTION SETTINGS
THE CONCEPT OF JDBC
JDBC is an abbreviation for the term Java Database Connection.
JDBC is a software tool.
We can use JDBC API to access tabular data stored in any relational
database.
THE CONCEPT OF JDBC
JDBC is an abbreviation for the term Java Database Connection.
JDBC is a software tool.
We can use JDBC API to access tabular data stored in any relational
database.
THE CONCEPT OF JDBC
Java JDBC Architecture
Steps to Connect Java JDBC
 Import-Package Dependencies
 Load and Register the Driver
 Connect to the Database
 Frame Query
 Execute Query
 Process Result
 Close Statement
 Close connection
JDBC DRIVERS TYPES
JDBC drivers are client-side adapters (installed on the client
machine, not on the server) that convert requests from Java
programs to a protocol that the DBMS can understand.
 Type-1 driver or JDBC-ODBC bridge driver
 Type-2 driver or Native-API driver
 Type-3 driver or Network Protocol driver
 Type-4 driver or Thin driver
JDBC DRIVERS TYPES
JDBC drivers are client-side adapters (installed on the client
machine, not on the server) that convert requests from Java
programs to a protocol that the DBMS can understand.
 Type-1 driver or JDBC-ODBC bridge driver
 Type-2 driver or Native-API driver
 Type-3 driver or Network Protocol driver
 Type-4 driver or Thin driver
JDBC PACKAGES
JDBC API is contained in two packages.
java.sql contains core JDBC interfaces that provide the basics for
connecting to the DBMS and interacting with data stored in the
DBMS.java.sql is part of the J2SE.
javax.sql, is the JDBC interface that interacts with Java Naming and
Directory Interface (JNDI) and manages connection pooling, among
other advanced JDBC features.
A BRIEF OVERVIEW OF THE JDBC PROCESS
JDBC API consists of the following main components:
1. JDBC Driver
2. Connection
3. Statement
4. ResultSet
A BRIEF OVERVIEW OF THE JDBC PROCESS
JDBC Driver
A JDBC driver is set of Java classes that implement JDBC interfaces
for interacting with a specific database. Almost all database
vendors such as MySQL, Oracle, Microsoft SQL Server, provide JDBC
drivers.
A BRIEF OVERVIEW OF THE JDBC PROCESS
JDBC Driver
A JDBC driver is set of Java classes that implement JDBC interfaces
for interacting with a specific database. Almost all database
vendors such as MySQL, Oracle, Microsoft SQL Server, provide JDBC
drivers.
Types of JDBC drivers including
1. JDBC-native API Driver,
2. JDBC-net Driver, and
3. JDBC Driver.
DATABASE CONNECTION
Steps For Connectivity Between Java Program and Database
1. Import the Packages
2. Load the drivers using the forName() method
3. Register the drivers using DriverManager
4. Establish a connection using the Connection class object
5. Create a statement
6. Execute the query
7. Close the connections
ASSOCIATING THE JDBC/ODBC BRIDGE WITH THE
DATABASE
STATEMENT OBJECTS
Java provides different types of interface to the user, in which the
Java language provides JDBC statements.
Normally a JDBC statement is used to execute the different queries
of the database.
STATEMENT OBJECTS
1. Creating Statement Object
 Boolean string SQL statement
 ExecuteUpdate string SQL statement
 ExecuteQuery ResultSet string SQL statement
 Closing Statement Object
STATEMENT OBJECTS
2. Prepared Statement
Execute()
executeQuery()
executeUpdate()
3. Callable Statement
RESULT SET
The SQL statements that read data from a database query, return
the data in a result set.
The SELECT statement is the standard way to select rows from a
database and view them in a result set.
The java.sql.ResultSet interface represents the result set of a
database query.
RESULT SET
The methods of the ResultSet interface can be broken down into
three categories –
Navigational methods − Used to move the cursor around.
Get methods − Used to view the data in the columns of the current
row being pointed by the cursor.
Update methods − Used to update the data in the columns of the
current row. The updates can then be updated in the underlying
database as well.
RESULT SET
JDBC provides the following connection methods to create
statements with desired ResultSet –
createStatement(int RSType, int RSConcurrency);
prepareStatement(String SQL, int RSType, int RSConcurrency);
prepareCall(String sql, int RSType, int RSConcurrency);
BACKGROUND OF SERVLET
Servlet technology offers advantages over applet technology for
server-intensive applications such as those accessing a database.
The Web server or data server in which a servlet is running is on the
same side of the network firewall as the data being accessed.
BACKGROUND OF SERVLET
A background thread started in init() performs continuous work while
request-handling threads display the current status with doGet().
Servlet technology has emerged as a powerful way to extend Web
server functionality through dynamic HTML pages.
BACKGROUND OF SERVLET
A Java servlet, by definition, implements the standard
javax.servlet.Servlet interface.
This interface specifies methods to initialize a servlet, process
requests, get the configuration and other basic information of a
servlet, and terminate a servlet instance.
BACKGROUND OF SERVLET
For Web applications, you can implement the Servlet interface by extending
the standard javax.servlet.http.HttpServlet abstract class. The HttpServlet
class includes the following methods:
 init(...) and destroy(...)--to initialize and terminate the servlet,
respectively
 doGet(...)--for HTTP GET requests
 doPost(...)--for HTTP POST requests
 doPut(...)--for HTTP PUT requests
 doDelete(...)--for HTTP DELETE requests
 service(...)--to receive HTTP requests and, by default, dispatch them to
the appropriate doXXX() methods
 getServletInfo(...)--for use by the servlet to provide information about
itself
BACKGROUND OF SERVLET
Servlet Containers
Servlet containers, sometimes referred to as servlet engines, execute
and manage servlets. A servlet container is usually written in Java
and is either part of a Web server (if the Web server is also written in
Java) or otherwise associated with and used by a Web server.
 Servlet class is loaded.
 Servlet instance is created.
 init method is invoked.
 service method is invoked.
 destroy method is invoked
1.Servlet class is loaded
The class loader is responsible to load the servlet class. The servlet
class is loaded when the first request for the servlet is received by
the web container.
2.Servlet instance is created
The web container creates the instance of a servlet after loading the
servlet class. The servlet instance is created only once in the servlet
life cycle.
3.init method is invoked
The web container calls the init method only once after creating the
servlet instance. The init method is used to initialize the servlet. It is
the life cycle method of the javax.servlet.Servlet interface.
4.service method is invoked
The web container calls the service method each time when request
for the servlet is received. If servlet is not initialized, it follows the
first three steps as described above then calls the service method.
5.destroy method is invoked
The web container calls the destroy method before removing the
servlet instance from the service. It gives the servlet an opportunity
to clean up any resource for example memory, thread etc.
JSDK is the Java Servlet Developers Kit.
The JSDK has the additional files needed in order to compile Java
servlets.
The Servlet Runner is a program that runs on your workstation, and
allows you to test servlets you have written without running a web
server.
Required Software to Develop Java Servlet Program,
 JDK1.8 or later
 Tomcat server
 Web browser
 Any text editor
 Create deployment directory or staging directory structure for
Java web application.
 Develop the servlet component DateServlet.java
 Add <Tomcat_home>libservlet-api.jar file to the classpath.
 Compile Servlet component DateServlet.java
 Develop deployment descriptor i.e. web.xml file.
 Deploy the web application.
 Start tomcat server.
 Test the web application in the browser address bar.
Java servlet API consist of two packages.
1. javax.servlet
2. javax.servlet.http.
javax.servlet package contains all the classes and interfaces which
can be used to write protocol-independent servlets.
javax.servlet.http contains all the classes and interfaces which are
necessary to write HTTP-specific servlets.
The javax.servlet and javax.servlet.http packages provide interfaces
and classes for writing servlets. All servlets must implement the
Servlet interface, which defines life-cycle methods.
Servlet Technology is used to create web applications. Servlet
technology uses Java language to create web applications.
Advantages of using Servlets
 Less response time because each request runs in a separate
thread.
 Servlets are scalable.
 Servlets are robust and object oriented.
 Servlets are platform independent.
Components of Servlet Architecture
The ServletRequest class includes methods that allow you to read the
names and values of parameters that arc included in a client
,request.
doGet and doPost are the commonly used methods of HTTPServlet.
Get
1. Its main job is to get some resource From server based on
client request
2. Total number of characters that get can carry to server is very
less/limited.
3. This appends URL with client request data
4. One can Cache the requests of this type
5. Requests parameters remain in browsing history
6. Because of above limitations, GET is not supposed to used for
complex and sensitive requests
Post
1. Its main job is to send client data and get the resource from
server based on client request.
2. Post can handle more characters that get can carry to server
is very less/limited.
3. This does not append client request data to URL
4. These requests cannot be cached
5. These do not remain in browsing history
6. This is more preferred for complex and sensitive requests (like
login)
A cookie is a small piece of data stored on the client-side which
servers use when communicating with clients.
The cookie is stored in the user browser, the client (user’s browser)
sends this cookie back to the server for all the subsequent requests
until the cookie is valid.
The Servlet container checks the request header for cookies and get
the session information from the cookie and use the associated
session from the server memory.
Types of Cookies
We can classify the cookie based on their expiry time:
1. Session
2. Persistent
1) SessionCookies:
Session cookies do not have expiration time. It lives in the browser memory. As
soon as the web browser is closed this cookie gets destroyed.
2) Persistent Cookies:
Unlike Session cookies they have expiration time, they are stored in the user hard
drive and gets destroyed based on the expiry time.
SESSION TRACKING
Session Tracking tracks a user’s requests and maintains their state. It
is a mechanism used to store information on specific users and in
order to recognize these user’s requests when they connect to the
web server.
SESSION TRACKING
Session Tracking tracks a user’s requests and maintains their state. It
is a mechanism used to store information on specific users and in
order to recognize these user’s requests when they connect to the
web server.

More Related Content

Similar to AdvancedJava.pptx

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programmingsrijavel
 
java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...Indu32
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Appletsamitksaha
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
Java basics notes
Java basics notesJava basics notes
Java basics notesNexus
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programmingKuntal Bhowmick
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCFAKHRUN NISHA
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsQUONTRASOLUTIONS
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basicsRaffaella D'angelo
 

Similar to AdvancedJava.pptx (20)

Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
 
java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basics
 

More from DrPrabakaranPerumal (10)

Java.pptx
Java.pptxJava.pptx
Java.pptx
 
IoT.pptx
IoT.pptxIoT.pptx
IoT.pptx
 
EthicalHacking.pptx
EthicalHacking.pptxEthicalHacking.pptx
EthicalHacking.pptx
 
SoftwareEngineering.pptx
SoftwareEngineering.pptxSoftwareEngineering.pptx
SoftwareEngineering.pptx
 
SoftwareTesting.pptx
SoftwareTesting.pptxSoftwareTesting.pptx
SoftwareTesting.pptx
 
Html-Prabakaran
Html-PrabakaranHtml-Prabakaran
Html-Prabakaran
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming-in-C
Programming-in-CProgramming-in-C
Programming-in-C
 
VOSUnit
VOSUnitVOSUnit
VOSUnit
 
OpeatingSystemPPT
OpeatingSystemPPTOpeatingSystemPPT
OpeatingSystemPPT
 

Recently uploaded

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

AdvancedJava.pptx

  • 1. ADVANCED JAVA PROGRAMMING Dr P PRABAKARAN Assistant Professor Department of Computer Applications School of Computing Sciences Vels Institute of Science Technology and Advanced Studies, Chennai
  • 3. ADVANCED JAVA PROGRAMMING APPLET – BASICS Applets in Java are small and dynamic internet-based programs. A Java Applet can be only executed within the applet framework of Java. For an easy execution of applets, a restricted ‘sandbox’ is provided by the applet framework. Generally, the applet code is embedded within an HTML page. The applet codes are executed when the HTML pages get loaded into the Java-compatible web browsers.
  • 5. ADVANCED JAVA PROGRAMMING APPLET- SKELETON Four of these methods—init( ), start( ), stop( ), and destroy( )—are defined by Applet. Another, paint( ), is defined by the AWT Component class. init() : init() is the first method to be called. This is where variable are initialized. This method is called only once during the runtime of applet. start() : start() method is called after init(). This method is called to restart an applet after it has been stopped. stop() : stop() method is called to suspend thread that does not need to run when applet is not visible. destroy() : destroy() method is called when your applet needs to be removed completely from memory.
  • 6. ADVANCED JAVA PROGRAMMING SIMPLE APPLET /*<applet code = “Hell” width=300 height=300></applet>*/ import java.applet.Applet; import java.awt.Graphics; public class Hell extends Applet { public void paint(Graphics g) { g.drawString("Hello World", 20, 20); } }
  • 7. ADVANCED JAVA PROGRAMMING REQUESTING REPAINTING HTML APPLET TAG An applet writes to its window only when its paint( ) method is called by the AWT. Whenever your applet needs to update the information displayed in its window, it simply calls repaint( ). The repaint( ) method is defined by the AWT. It causes the AWT run-time system to execute a call to your applet’s update( ) method,
  • 8. ADVANCED JAVA PROGRAMMING REQUESTING REPAINTING HTML APPLET TAG 1.void repaint( ) This version causes the entire window to be repainted. 2.void repaint(int left, int top, int width, int height) This version specifies a region that will be repainted. 3. void repaint(long maxDelay) Here, maxDelay specifies the maximum number of milliseconds that can elapse before update( ) is called. 4.void repaint(long maxDelay, int x, int y, int width, int height)
  • 9. ADVANCED JAVA PROGRAMMING PASSING PARAMETERS TO APPLETS Parameters specify extra information that can be passed to an applet from the HTML page. Parameters are specified using the HTML’s param tag. Param Tag The <param> tag is a sub tag of the <applet> tag. The <param> tag contains two attributes: name and value which are used to specify the name of the parameter and the value of the parameter respectively.
  • 10. ADVANCED JAVA PROGRAMMING GRAPHICS All graphics are drawn relative to a window. This can be the main window of an applet, a child window of an applet, or a stand-alone application window. The origin of each window is at the top-left Coordinates 0,0. Coordinates are specified in pixels. All output to a window takes place through a graphics context. A graphics context is encapsulated by the Graphics class and is obtained in two ways: It is passed to an applet when one of its various methods, such as paint() or update(), is called. It is returned by the getGraphics( ) method of Component.
  • 11. ADVANCED JAVA PROGRAMMING GRAPHICS Methods of Graphics class public abstract void drawString(String str, int x, int y): is used to draw the specified string. public void drawRect(int x, int y, int width, int height): draw a rectangle with the specified width and height. public abstract void fillRect(int x, int y, int width, int height): is used to fill the rectangle with the default color and specified width and height. public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.
  • 12. ADVANCED JAVA PROGRAMMING FONT Font is a class that belongs to the java.awt package. It implements the Serializable interface. FontUIResource is the direct known subclass of the Java Font class. It represents the font that are used to render the text. In Java, there are two technical terms that are used to represent font are characters and Glyphs. Types of Fonts in Java Physical Fonts Logical Fonts
  • 13. ADVANCED JAVA PROGRAMMING COLORCLASSES The primary purpose of AWT Color is to allow developers to create new colors using Java code using RGB (red, green, blue), RGBA (red, green, blue, alpha), or HSB (hue, saturation, BRI components) packages. The class contains two values - the code of the shade and the value of opacity/transparency. Color defines several constants (for example, Color.black) to specify a number of common colors. We can also create your own colors, using one of the color constructors.
  • 14. ADVANCED JAVA PROGRAMMING SWING-JAPPLET JApplet is a java swing public class designed for developers usually written in Java. JApplet is generally in the form of Java bytecode that runs with the help of a Java virtual machine (JVM) or Applet viewer from Sun Microsystems. It was first introduced in 1995. JApplet can also be written in other programming languages and can later be compiled to Java byte code. Java applets can be executed on multiple platforms which include Microsoft Windows, UNIX, Mac OS and Linux. JApplet can also be run as an application, though this would require a little extra coding.
  • 15. ADVANCED JAVA PROGRAMMING JFRAME The javax.swing.JFrame class is a type of container which inherits the java.awt.Frame class. JFrame works like the main window where components like labels, buttons, textfields are added to create a GUI. create a JFrame JFrame class has many constructors that are used to create a new JFrame. You can create a JFrame using these methods: JFrame(): This helps in creating a frame which is invisible. JFrame(String Title): Helps in creating a frame with a title. JFrame(GraphicsConfiguration gc): Creates a frame with blank title and the graphics configuration of screen.
  • 16. ADVANCED JAVA PROGRAMMING JCOMPONENT DIFFERENCES BETWEEN COMPONENT No. Java AWT Java Swing 1) AWT components are platform- dependent. Java swing components are platform-independent. 2) AWT components are heavyweight. Swing components are lightweight. 3) AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel.
  • 17. ADVANCED JAVA PROGRAMMING CONTAINER An applet container is the environment that runs a Java applet and provides secure applet execution. Examples include Web browsers and the applet viewer in Java's software development kit (SDK). Types of Containers The Container class, like Component is an abstract class. It has two direct subclasses: Panel, which is only used for grouping components; Window, which is, as its name says, for creating and handling windows.
  • 18. ADVANCED JAVA PROGRAMMING ICONS Swing introduces the concept of an icon for use in a variety of components. The Icon interface and ImageIcon class make dealing with simple images extremely easy. The Icon interface is very simple, specifying just three methods used to determine the size of the Icon and to display it. Implementors of this interface are free to store and display the image in any way, providing a great deal of flexibility.
  • 19. ADVANCED JAVA PROGRAMMING JLabel The object of JLabel class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by an application but a user cannot edit it directly. It inherits JComponent class. Java JTextField The object of a JTextField class is a text component that allows the editing of a single line text. It inherits JTextComponent class.
  • 20. ADVANCED JAVA PROGRAMMING Java JButton The JButton class is used to create a labeled button that has platform independent implementation. The application result in some action when the button is pushed. It inherits AbstractButton class. Java JCheckBox The JCheckBox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a CheckBox changes its state from "on" to "off" or from "off" to "on ". It inherits JToggleButton class.
  • 21. ADVANCED JAVA PROGRAMMING Java JRadioButton The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz. It should be added in ButtonGroup to select one radio button only. Java JComboBox The object of Choice class is used to show popup menu of choices. Choice selected by user is shown on the top of a menu. It inherits JComponent class.
  • 22. Remote Method Invocation RMI – OVERVIEW RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM. RMI applications are often comprised of two separate programs:  a server and  a client. RMI provides the mechanism by which the server and the client communicate and pass information back and forth.
  • 23. Remote Method Invocation RMI – OVERVIEW RMI system uses an existing web server to load class definitions, from server to client and from client to server, for objects when needed.
  • 24. Remote Method Invocation RMI – OVERVIEW Creating Distributed Applications by Using RMI 1. Designing and implementing the components of your distributed application. 2. Compiling sources. 3. Making classes network accessible. 4. Starting the application.
  • 25. Remote Method Invocation RMI ARCHITECTURE It is always a need for communication between two different applications. In Java-based applications, one application communicates with another remote/different application running somewhere else by using a mechanism called RMI architecture.
  • 26. Remote Method Invocation RMI ARCHITECTURE Application Layer client and server, which are involved in communication. The java program on the client side communicates with the java program on the server-side. Stub It is an object that resides on the client machine, and it acts as a proxy for the remote object. It is like a gateway for the client program.
  • 27. Remote Method Invocation RMI ARCHITECTURE Skeleton The server object which resides in a server machine is known as Skeleton. Stub communicates with server application with the help of an intermediate Skeleton object. Stub / Skeleton layer The Stub/Skeleton layer is responsible for intercepting calls made by the client and redirecting these calls to the remote object. This layer is also called as Proxy Layer. Stub and Skeleton are the proxies for client and server.
  • 28. Remote Method Invocation RMI ARCHITECTURE Remote Reference Layer The proxy layer is connected to the RMI mechanism through the Remote Reference Layer. This layer is responsible for the communication and transfer of objects between client and server. Transport Layer The transport layer is responsible for setting up communication between the two machines. This layer uses standard TCP/IP protocol for connection.
  • 29. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING The following steps to write the RMI program.  Create the remote interface  Provide the implementation of the remote interface  Compile the implementation class and create the stub and skeleton objects using the rmic tool  Start the registry service by rmiregistry tool  Create and start the remote application  Create and start the client application
  • 30. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 1 - Define the Remote Interface 1. A remote interface provides describes all the methods of a particular remote object. 2. The client communicates with this remote interface. 3. To create a remote interface − 4. Create an interface that extends the predefined interface Remote which belongs to the package. 5. Declare all the business methods that can be invoked by the client in this interface. 6. Since there is a chance of network issues during remote calls, an exception RemoteException may occur; throw it.
  • 31. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 2 - Develop the Implementation Class or Remote Object 1. Implementation Class or Remote Object can be written separately or can be written directly with the server program implementation. 2. To develop an implementation class − 3. Implement the interface created in the previous step. 4. Provide implementation to all the abstract methods of the remote interface.
  • 32. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING 3 - Develop the Server Program 1. An RMI server program should implement the remote interface or extend the implementation class. To develop a server program − 2. Create a client class from where you want to invoke the remote object. 3. Create a remote object by instantiating the implementation class as shown below. 4. Export the remote object using the method exportObject() of the class UnicastRemoteObject which belongs to the package java.rmi.server. 5. Get the RMI registry using the getRegistry() method of the LocateRegistry class which belongs to the package java.rmi.registry. 6. Bind the remote object created to the registry using the bind() method of the class Registry. To this method, pass a string representing the bind name and the object exported, as parameters.
  • 33. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 4 - Develop the Client Program 1. Write a client program, fetch the remote object and invoke the required method using the remote object. To develop a client program − 2. Create a client class from where your are intended to invoke the remote object. 3. Get the RMI registry using the getRegistry() method of the LocateRegistry class which belongs to the package java.rmi.registry. 4. Fetch the object from the registry using the method lookup() of the class Registry which belongs to the package java.rmi.registry. 5. To this method, you need to pass a string value representing the bind name as a parameter. This will return you the remote object. 6. The lookup() returns an object of type remote. 7. Finally, invoke the required method using the obtained remote object.
  • 34. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 5 - Compile the Application Compile the application in the following manner 1. Compile the Remote Interface. 2. Compile the Implementation Class. 3. Compile the Server Program. 4. Compile the Client Program. Or, 5. Open the folder where you have stored all the programs and compile all the Java files.
  • 35. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 5 - Compile the Application Compile the application in the following manner 1. Compile the Remote Interface. 2. Compile the Implementation Class. 3. Compile the Server Program. 4. Compile the Client Program. Or, 5. Open the folder where you have stored all the programs and compile all the Java files.
  • 36. Remote Method Invocation DEVELOPING APPLICATION WITH RMI DECLARING Step 6 - Execute the Application 1. Step 1 - Start the RMI registry using the command. start rmiregistry This will start an RMI registry in a separate window. 2. Step 2 − Run the server class file java Server 3. Step 3 − Run the client class file java Client
  • 37. Remote Method Invocation EJB INTRODUCTION  EJB is a server-side software element that summarizes business logic of an application.  EJB (Enterprise Java Bean) is used to develop scalable, robust and secured enterprise applications in java.  The EJB enumeration aims to provide a standard way to implement the server-side business software typically found in enterprise applications.  To run EJB application we need an application server (EJB Container) such as Jboss, Glassfish, Weblogic, Websphere etc.
  • 38. Remote Method Invocation EJB INTRODUCTION Types of Enterprise Java Beans  Session beans  Message-driven beans Session Beans Session beans are plain old Java objects which function as server-side extension performing business logic. Session beans are plain old Java objects which function as server-side extension performing business logic.
  • 39. Remote Method Invocation EJB INTRODUCTION Types of Session beans Stateless Session Beans (SLSB) - Provide user generic business processing and are not tied to a specific client. Stateful Session Beans (SFSB) - Provide user-specific business processing and are tied to a specific client. Singleton Session Beans (SSB) - Provide shared data access to clients and components within an application and are instantiated only once per application.
  • 40. Remote Method Invocation EJB INTRODUCTION Message-driven beans Message-driven beans are EJB beans which are driven with the help of messages. Types of Message-driven beans JMS (Java Messaging System) Message-driven beans Non-JMS Message-driven beans
  • 41. Remote Method Invocation EJB TRANSACTION A transaction is a single unit of work items, which follows the ACID properties. ACID stands for Atomic, Consistent, Isolated, and Durable. Atomic − If any of the work item fails, the whole unit will be considered failed. Success meant, all items execute successfully. Consistent − A transaction must keep the system in consistent state. Isolated − Each transaction executes independent of any other transaction. Durable − Transaction should survive system failure if it has been executed or committed.
  • 42. Remote Method Invocation EJB TRANSACTION A transaction is a single unit of work items, which follows the ACID properties. ACID stands for Atomic, Consistent, Isolated, and Durable. Atomic − If any of the work item fails, the whole unit will be considered failed. Success meant, all items execute successfully. Consistent − A transaction must keep the system in consistent state. Isolated − Each transaction executes independent of any other transaction. Durable − Transaction should survive system failure if it has been executed or committed.
  • 43. Java Server Page INTRODUCTION TO JSP  It stands for Java Server Pages.  It is a server side technology.  It is used for creating web application.  It is used to create dynamic web content.  In this JSP tags are used to insert JAVA code into HTML pages.  It is an advanced version of Servlet Technology.
  • 44. Java Server Page INTRODUCTION TO JSP Features of JSP Coding in JSP is easy :- As it is just adding JAVA code to HTML/XML. Reduction in the length of Code :- In JSP we use action tags, custom tags etc. Connection to Database is easier :-It is easier to connect website to database and allows to read or write data easily to the database. Make Interactive websites :- In this we can create dynamic web pages which helps user to interact in real time environment. Portable, Powerful, flexible and easy to maintain :- as these are browser and server independent.
  • 45. Java Server Page INTRODUCTION TO JSP JSP syntax Declaration Tag :-It is used to declare variables. Syntax:- <%! Dec var %> Example:- <%! int var=10; %>
  • 46. Java Server Page INTRODUCTION TO JSP Java Scriplets :- It allows us to add any number of JAVA code, variables and expressions. Syntax:- <% java code %> JSP Expression :- It evaluates and convert the expression to a string. Syntax:- <%= expression %>
  • 47. Java Server Page INTRODUCTION TO JSP Process of Execution  Create html page from where request will be sent to server eg try.html.  To handle to request of user next is to create .jsp file Eg. new.jsp  Create project folder structure.  Create XML file eg my.xml.  Create WAR file.  Start Tomcat  Run Application
  • 48. Java Server Page JSP LIFE CYCLE JSP Life Cycle is defined as translation of JSP Page into servlet as a JSP Page needs to be converted into servlet first in order to process the service requests. The Life Cycle starts with the creation of JSP and ends with the disintegration of that. Following steps are involved in the JSP life cycle: 1.Translation Phase 2.Compilation Phase 3.Initialization Phase 4.Execution Phase 5.Destruction(Cleanup) Phase
  • 49. Java Server Page JSP LIFE CYCLE
  • 50. Java Server Page JSP LIFE CYCLE Transalation Phase When a user navigates to a page ending with a .jsp extension in their web browser, the web browser sends an HTTP request to the webserver. The webserver checks if a compiled version of the JSP page already exists. If the JSP page's compiled version does not exist, the file is sent to the JSP Servlet engine, which converts it into servlet content (with .java extension). This process is known as translation. The web container automatically translates the JSP page into a servlet. So as a developer, you don't have to worry about converting it manually.
  • 51. Java Server Page JSP LIFE CYCLE Compilation Phase In case the JSP page was not compiled previously or at any point in time, then the JSP page is compiled by the JSP engine. In this compilation phase, the Translated .java file of the servlet is compiled into the Java servlet .class file. Initialization Phase In this Initialization phase: Here, the container will: Load the equivalent servlet class. Create instance. Call the jspInit() method for initializing the servlet instance.
  • 52. Java Server Page JSP LIFE CYCLE Execution Phase This Execution phase is responsible for all JSP interactions and logic executions for all requests until the JSP gets destroyed. As the requested JSP page is loaded and initiated, the JSP engine has to invoke the _jspService() method. This method is invoked as per the requests, responsible for generating responses for the associated requests, and responsible for all HTTP methods.
  • 53. Java Server Page JSP LIFE CYCLE Destruction (Cleanup) Phase This destruction phase is invoked when the JSP has to be cleaned up from use by the container. The jspDestroy() method is invoked. You can incorporate and write cleanup codes inside this method for releasing database connections or closing any file.
  • 54. Java Server Page ATTRIBUTES IN JSP . S.No. Attribute & Purpose 1 buffer Specifies a buffering model for the output stream. 2 autoFlush Controls the behavior of the servlet output buffer. 3 contentType Defines the character encoding scheme. 4 errorPage Defines the URL of another JSP that reports on Java unchecked runtime exceptions. 5 isErrorPage Indicates if this JSP page is a URL specified by another JSP page's errorPage attribute.
  • 55. Java Server Page JSP ELEMENTS  JSP Declaration  JSP Scriptlet  JSP Expression  JSP Comments
  • 56. Java Server Page JSP ELEMENTS JSP Declaration A declaration tag is a piece of Java 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. Syntax of declaration tag: <%! Dec var %>
  • 57. Java Server Page JSP ELEMENTS JSP Scriptlet Scriptlet tag 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 Scriptlet executes for every request. A Scriptlet contains java code that is executed every time JSP is invoked. Syntax of Scriptlet tag: <% java code %>
  • 58. Java Server Page 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 scriptless JSP page. Syntax: <%= expression %>
  • 59. Java Server Page JSP ELEMENTS JSP Comments Comments are the one when JSP container wants to ignore certain texts and statements. When we want to hide certain content, then we can add that to the comments section. Syntax: <% -- JSP Comments %>
  • 60. Java Server Page JSP DIRECTIVES  JSP directives are the messages to JSP container. They provide global information about an entire JSP page.   JSP directives are used to give special instruction to a container for translation of JSP to servlet code.   In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.   They give instructions to the container on how to handle certain aspects of JSP processing
  • 61. Java Server Page JSP DIRECTIVES  JSP directives are the messages to JSP container. They provide global information about an entire JSP page.  JSP directives are used to give special instruction to a container for translation of JSP to servlet code.  In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.  They give instructions to the container on how to handle certain aspects of JSP processing Syntax of Directive: <%@ directive attribute="" %>
  • 62. Java Server Page JSP DIRECTIVES  JSP directives are the messages to JSP container. They provide global information about an entire JSP page.   JSP directives are used to give special instruction to a container for translation of JSP to servlet code.   In JSP life cycle phase, JSP has to be converted to a servlet which is the translation phase.   They give instructions to the container on how to handle certain aspects of JSP processing
  • 63. Java Server Page JSP DIRECTIVES Types of directives: Page directive Include directive Taglib directive
  • 64. Java Server Page JSP DIRECTIVES JSP Page directive Syntax of Page directive: <%@ page…%> It provides attributes that get applied to entire JSP page. It defines page dependent attributes, such as scripting language, error page, and buffering requirements. It is used to provide instructions to a container that pertains to current JSP page.
  • 65. Java Server Page JSP DIRECTIVES JSP Include directive JSP “include directive”( codeline 8 ) is used to include one file to the another file This included file can be HTML, JSP, text files, etc. It is also useful in creating templates with the user views and break the pages into header & footer and sidebar actions. It includes file during translation phase Syntax of include directive: <%@ include….%>
  • 66. Java Server Page JSP DIRECTIVES JSP Taglib Directive JSP taglib directive is used to define the tag library with “taglib” as the prefix, which we can use in JSP. More detail will be covered in JSP Custom Tags section JSP taglib directive is used in the JSP pages using the JSP standard tag libraries It uses a set of custom tags, identifies the location of the library and provides means of identifying custom tags in JSP page. Syntax of taglib directive: <%@ taglib uri="uri" prefix="value"%>
  • 67. Java Server Page JSP DECLARATIONS A JSP declaration is used to declare variables and methods in a page's scripting language. The code written inside the jsp declaration tag is placed outside the service() method of auto generated servlet. So it doesn't get memory at each request. Syntax of JSP declaration tag <%! field or method declaration %>
  • 68. Java Server Page EXPRESSIONS Expression tag evaluates the expression placed in it, converts the result into String and send the result back to the client through response object. Basically it writes the result to the client(browser). Syntax of expression tag in JSP: <%= expression %>
  • 69. Java Server Page SCRIPT LET In JSP, java code can be written inside the jsp page using the scriptlet tag. Let's see what are the scripting elements first. A scriptlet tag is used to execute java source code in JSP. Syntax is as follows: <% java source code %>
  • 70. Java Server Page ACTION ELEMENTS Each JSP action tag is used to perform some specific tasks. The action tags are used to control the flow between pages and to use Java Bean. JSP Action Tags Description jsp:forward forwards the request and response to another resource. jsp:include includes another resource. jsp:useBean creates or locates bean object. jsp:setProperty sets the value of property in bean object.
  • 71. Java Server Page USING SESSION OBJECT AND COOKIES Cookies Generally Cookies are defined as the text files it will be stored in the computer mainly in the client machine for tracking purposes like login details, file transfer, etc. We can also saw the cookies in web browsers in web applications using debug mode choose “Application -> Storage-. Cookies” we can see whatever we see the web applications or websites in the cookies column.
  • 72. Java Server Page JSP WORKING WITH JAVA MAIL JavaMail API and the Java Activation Framework (JAF) should be installed on the machine to send emails using JSP. Download these files and unzip them in newly formed directories. Amongst many jar files, add mail.jar and activation.jar file to the Classpath.
  • 73. Java Server Page USAGE OF USE BEAN TAG The jsp:useBean action tag is used to locate or instantiate a bean class. If bean object of the Bean class is already created, it doesn't create the bean depending on the scope. But if object of bean is not created, it instantiates the bean. Syntax of jsp:useBean action tag <jsp:useBean id= "instanceName" scope= "page | request | session | application" class= "packageName.className" type= "packageName.className" beanName="packageName.className | <%= expression >" > </jsp:useBean>
  • 74. Java Server Page USAGE OF USE BEAN TAG The jsp:useBean action tag is used to locate or instantiate a bean class. If bean object of the Bean class is already created, it doesn't create the bean depending on the scope. But if object of bean is not created, it instantiates the bean. Syntax of jsp:useBean action tag <jsp:useBean id= "instanceName" scope= "page | request | session | application" class= "packageName.className" type= "packageName.className" beanName="packageName.className | <%= expression >" > </jsp:useBean>
  • 75. JDBC CONNECTION SETTINGS  Register the Driver class  Create connection  Create statement  Execute queries  Close connection
  • 77. THE CONCEPT OF JDBC JDBC is an abbreviation for the term Java Database Connection. JDBC is a software tool. We can use JDBC API to access tabular data stored in any relational database.
  • 78. THE CONCEPT OF JDBC JDBC is an abbreviation for the term Java Database Connection. JDBC is a software tool. We can use JDBC API to access tabular data stored in any relational database.
  • 81. Steps to Connect Java JDBC  Import-Package Dependencies  Load and Register the Driver  Connect to the Database  Frame Query  Execute Query  Process Result  Close Statement  Close connection
  • 82. JDBC DRIVERS TYPES JDBC drivers are client-side adapters (installed on the client machine, not on the server) that convert requests from Java programs to a protocol that the DBMS can understand.  Type-1 driver or JDBC-ODBC bridge driver  Type-2 driver or Native-API driver  Type-3 driver or Network Protocol driver  Type-4 driver or Thin driver
  • 83. JDBC DRIVERS TYPES JDBC drivers are client-side adapters (installed on the client machine, not on the server) that convert requests from Java programs to a protocol that the DBMS can understand.  Type-1 driver or JDBC-ODBC bridge driver  Type-2 driver or Native-API driver  Type-3 driver or Network Protocol driver  Type-4 driver or Thin driver
  • 84. JDBC PACKAGES JDBC API is contained in two packages. java.sql contains core JDBC interfaces that provide the basics for connecting to the DBMS and interacting with data stored in the DBMS.java.sql is part of the J2SE. javax.sql, is the JDBC interface that interacts with Java Naming and Directory Interface (JNDI) and manages connection pooling, among other advanced JDBC features.
  • 85. A BRIEF OVERVIEW OF THE JDBC PROCESS JDBC API consists of the following main components: 1. JDBC Driver 2. Connection 3. Statement 4. ResultSet
  • 86. A BRIEF OVERVIEW OF THE JDBC PROCESS JDBC Driver A JDBC driver is set of Java classes that implement JDBC interfaces for interacting with a specific database. Almost all database vendors such as MySQL, Oracle, Microsoft SQL Server, provide JDBC drivers.
  • 87. A BRIEF OVERVIEW OF THE JDBC PROCESS JDBC Driver A JDBC driver is set of Java classes that implement JDBC interfaces for interacting with a specific database. Almost all database vendors such as MySQL, Oracle, Microsoft SQL Server, provide JDBC drivers. Types of JDBC drivers including 1. JDBC-native API Driver, 2. JDBC-net Driver, and 3. JDBC Driver.
  • 88. DATABASE CONNECTION Steps For Connectivity Between Java Program and Database 1. Import the Packages 2. Load the drivers using the forName() method 3. Register the drivers using DriverManager 4. Establish a connection using the Connection class object 5. Create a statement 6. Execute the query 7. Close the connections
  • 89. ASSOCIATING THE JDBC/ODBC BRIDGE WITH THE DATABASE
  • 90. STATEMENT OBJECTS Java provides different types of interface to the user, in which the Java language provides JDBC statements. Normally a JDBC statement is used to execute the different queries of the database.
  • 91. STATEMENT OBJECTS 1. Creating Statement Object  Boolean string SQL statement  ExecuteUpdate string SQL statement  ExecuteQuery ResultSet string SQL statement  Closing Statement Object
  • 92. STATEMENT OBJECTS 2. Prepared Statement Execute() executeQuery() executeUpdate() 3. Callable Statement
  • 93. RESULT SET The SQL statements that read data from a database query, return the data in a result set. The SELECT statement is the standard way to select rows from a database and view them in a result set. The java.sql.ResultSet interface represents the result set of a database query.
  • 94. RESULT SET The methods of the ResultSet interface can be broken down into three categories – Navigational methods − Used to move the cursor around. Get methods − Used to view the data in the columns of the current row being pointed by the cursor. Update methods − Used to update the data in the columns of the current row. The updates can then be updated in the underlying database as well.
  • 95. RESULT SET JDBC provides the following connection methods to create statements with desired ResultSet – createStatement(int RSType, int RSConcurrency); prepareStatement(String SQL, int RSType, int RSConcurrency); prepareCall(String sql, int RSType, int RSConcurrency);
  • 96. BACKGROUND OF SERVLET Servlet technology offers advantages over applet technology for server-intensive applications such as those accessing a database. The Web server or data server in which a servlet is running is on the same side of the network firewall as the data being accessed.
  • 97. BACKGROUND OF SERVLET A background thread started in init() performs continuous work while request-handling threads display the current status with doGet(). Servlet technology has emerged as a powerful way to extend Web server functionality through dynamic HTML pages.
  • 98. BACKGROUND OF SERVLET A Java servlet, by definition, implements the standard javax.servlet.Servlet interface. This interface specifies methods to initialize a servlet, process requests, get the configuration and other basic information of a servlet, and terminate a servlet instance.
  • 99. BACKGROUND OF SERVLET For Web applications, you can implement the Servlet interface by extending the standard javax.servlet.http.HttpServlet abstract class. The HttpServlet class includes the following methods:  init(...) and destroy(...)--to initialize and terminate the servlet, respectively  doGet(...)--for HTTP GET requests  doPost(...)--for HTTP POST requests  doPut(...)--for HTTP PUT requests  doDelete(...)--for HTTP DELETE requests  service(...)--to receive HTTP requests and, by default, dispatch them to the appropriate doXXX() methods  getServletInfo(...)--for use by the servlet to provide information about itself
  • 100. BACKGROUND OF SERVLET Servlet Containers Servlet containers, sometimes referred to as servlet engines, execute and manage servlets. A servlet container is usually written in Java and is either part of a Web server (if the Web server is also written in Java) or otherwise associated with and used by a Web server.
  • 101.  Servlet class is loaded.  Servlet instance is created.  init method is invoked.  service method is invoked.  destroy method is invoked
  • 102.
  • 103. 1.Servlet class is loaded The class loader is responsible to load the servlet class. The servlet class is loaded when the first request for the servlet is received by the web container. 2.Servlet instance is created The web container creates the instance of a servlet after loading the servlet class. The servlet instance is created only once in the servlet life cycle.
  • 104. 3.init method is invoked The web container calls the init method only once after creating the servlet instance. The init method is used to initialize the servlet. It is the life cycle method of the javax.servlet.Servlet interface. 4.service method is invoked The web container calls the service method each time when request for the servlet is received. If servlet is not initialized, it follows the first three steps as described above then calls the service method.
  • 105. 5.destroy method is invoked The web container calls the destroy method before removing the servlet instance from the service. It gives the servlet an opportunity to clean up any resource for example memory, thread etc.
  • 106. JSDK is the Java Servlet Developers Kit. The JSDK has the additional files needed in order to compile Java servlets. The Servlet Runner is a program that runs on your workstation, and allows you to test servlets you have written without running a web server.
  • 107. Required Software to Develop Java Servlet Program,  JDK1.8 or later  Tomcat server  Web browser  Any text editor
  • 108.  Create deployment directory or staging directory structure for Java web application.  Develop the servlet component DateServlet.java  Add <Tomcat_home>libservlet-api.jar file to the classpath.  Compile Servlet component DateServlet.java  Develop deployment descriptor i.e. web.xml file.  Deploy the web application.  Start tomcat server.  Test the web application in the browser address bar.
  • 109. Java servlet API consist of two packages. 1. javax.servlet 2. javax.servlet.http. javax.servlet package contains all the classes and interfaces which can be used to write protocol-independent servlets. javax.servlet.http contains all the classes and interfaces which are necessary to write HTTP-specific servlets.
  • 110. The javax.servlet and javax.servlet.http packages provide interfaces and classes for writing servlets. All servlets must implement the Servlet interface, which defines life-cycle methods. Servlet Technology is used to create web applications. Servlet technology uses Java language to create web applications.
  • 111.
  • 112. Advantages of using Servlets  Less response time because each request runs in a separate thread.  Servlets are scalable.  Servlets are robust and object oriented.  Servlets are platform independent.
  • 113. Components of Servlet Architecture
  • 114. The ServletRequest class includes methods that allow you to read the names and values of parameters that arc included in a client ,request.
  • 115. doGet and doPost are the commonly used methods of HTTPServlet.
  • 116. Get 1. Its main job is to get some resource From server based on client request 2. Total number of characters that get can carry to server is very less/limited. 3. This appends URL with client request data 4. One can Cache the requests of this type 5. Requests parameters remain in browsing history 6. Because of above limitations, GET is not supposed to used for complex and sensitive requests
  • 117. Post 1. Its main job is to send client data and get the resource from server based on client request. 2. Post can handle more characters that get can carry to server is very less/limited. 3. This does not append client request data to URL 4. These requests cannot be cached 5. These do not remain in browsing history 6. This is more preferred for complex and sensitive requests (like login)
  • 118. A cookie is a small piece of data stored on the client-side which servers use when communicating with clients. The cookie is stored in the user browser, the client (user’s browser) sends this cookie back to the server for all the subsequent requests until the cookie is valid. The Servlet container checks the request header for cookies and get the session information from the cookie and use the associated session from the server memory.
  • 119. Types of Cookies We can classify the cookie based on their expiry time: 1. Session 2. Persistent 1) SessionCookies: Session cookies do not have expiration time. It lives in the browser memory. As soon as the web browser is closed this cookie gets destroyed. 2) Persistent Cookies: Unlike Session cookies they have expiration time, they are stored in the user hard drive and gets destroyed based on the expiry time.
  • 120. SESSION TRACKING Session Tracking tracks a user’s requests and maintains their state. It is a mechanism used to store information on specific users and in order to recognize these user’s requests when they connect to the web server.
  • 121. SESSION TRACKING Session Tracking tracks a user’s requests and maintains their state. It is a mechanism used to store information on specific users and in order to recognize these user’s requests when they connect to the web server.