PSD1B Advance Java Programming Unit : I-V PSD1B- Advance Java Programming 1
UNIT I - SYLLABUS Servlets Client Vs Server Types of Servlets Life Cycle of Servlets Architecture Session Tracking Cookies JDBC & Servlet PSD1B- Advance Java Programming 2
Servlets A server-side software component, written in Java, that dynamically extends the functionality of a server PSD1B- Advance Java Programming 3
Client vs Server PSD1B- Advance Java Programming 4
Response Request Model PSD1B- Advance Java Programming 5
Servlets vs. CGI PSD1B- Advance Java Programming 6
Types of Servlets PSD1B- Advance Java Programming 7
Servlet Life Cycle PSD1B- Advance Java Programming 8
Servlet Architecture PSD1B- Advance Java Programming 9
Servlet Hierachy PSD1B- Advance Java Programming 10
Session Tracking PSD1B- Advance Java Programming 11
Cookies PSD1B- Advance Java Programming 12
JDBC & Servlet PSD1B- Advance Java Programming 13
Role of Servlet PSD1B- Advance Java Programming 14
UNIT II - SYLLABUS Java Bean Life Cycle of Bean Bean Components Persistence Events BDK Tools Properties Info Bus PSD1B- Advance Java Programming 15
Java Beans A Bean is a reusable software component model based on sun s java bean specification that can be manipulated visually in a builder tool. The term software component model describe how to create and use reusable software components to build an application We create simple components using java beans. We can directly embed these beans into the software. PSD1B- Advance Java Programming 16
Life Cycle of Beans Creation : when JavaBean classes are written and compiled. Packaging : when one or more JavaBean classes or serialized instances (prototypes) and their satellites are stored in a Jar file along with their resources PSD1B- Advance Java Programming 17
Life Cycle Instantiation : when an instance of a JavaBean is created either from a JavaBean class or from a prototype, this can happen either in Design Time (inside a builder tool) or in Run Time Customization : when a JavaBean instance's properties are modified, during Design Time. Serialization : when a JavaBean instance is stored to eventually become a prototype for other instances (if further packaged) Storage as assembly: when a set of JavaBean instances are stored as an assembly. PSD1B- Advance Java Programming 18
Bean components It supports the standard component architecture features of Properties Events Methods Persistence. In addition, Java Beans provides support for Introspection (Allows Automatic Analysis of a java beans) Customization(To make it easy to configure a java beans component) PSD1B- Advance Java Programming 19
Persistence Enables developers to customize Beans and then retrieve those Beans later, with customized features intact PSD1B- Advance Java Programming 20
Events Events are messages sent from one object to another notifying the recipient that something has happened PSD1B- Advance Java Programming 21
BDK BDK is a development environment to create, configure, and test JavaBeans. The features of BDK environment are: Provides a GUI to create, configure, and test JavaBeans. Enables you to modify Java Bean properties and link multiple JavaBeans in an application using BDK. Provides a set of sample JavaBeans. Enables you to associate pre-defined events with sample JavaBeans PSD1B- Advance Java Programming 22
Tools The components of BDK development environment are: ToolBox - Lists the sample JavaBeans of BDK. BeanBox - Is a workspace for creating the layout of JavaBean application. Properties - Displays all the exposed properties of a JavaBean. Method Tracer - Displays the debugging messages and method calls for a JavaBean application PSD1B- Advance Java Programming 23
Bean Box PSD1B- Advance Java Programming 24
JavaBeans Properties Types of JavaBeans Properties Simple properties Boolean properties Indexed properties Simple Properties: Simple properties can have only a single value. Boolean properties: A Boolean property is used to represent the values True or False Indexed properties: Indexed Properties are consists of multiple values. PSD1B- Advance Java Programming 25
Info Bus Two or more JavaBeans can dynamically exchange data through the Information Bus. PSD1B- Advance Java Programming 26
Roles Three different roles in an InfoBus: Data producers: Beans mainly responsible for accessing data from their native store, such as files, DBMS, etc. Data consumers: Beans responsible for retrieving data from the bus for analysis or visual display Data controllers: An optional component that regulates or redirects the flow of events between data producers and consumers. PSD1B- Advance Java Programming 27
UNIT III - SYLLABUS EJB Server 3-Tier Topology Types of EJB Entity Bean Session Bean EJB Architecture PSD1B- Advance Java Programming 28
EJB Server EJB is a semi-automated server-side component management architecture that facilitates the deployment of enterprise-class distributed object applications in Java. PSD1B- Advance Java Programming 29
EJB PSD1B- Advance Java Programming 30
3-Tier In enterprise systems, EJB clients are usually: Servlets, JSPs, or Other EJBs PSD1B- Advance Java Programming 31
EJB Topology PSD1B- Advance Java Programming 32
Types of EJB PSD1B- Advance Java Programming 33
Entity Bean PSD1B- Advance Java Programming 34
Life Cycle PSD1B- Advance Java Programming 35
Session Bean PSD1B- Advance Java Programming 36
Life Cycle of Session Bean PSD1B- Advance Java Programming 37
Role of EJB PSD1B- Advance Java Programming 38
EJB Architecture PSD1B- Advance Java Programming 39
JVM PSD1B- Advance Java Programming 40
UNIT IV - SYLLABUS RMI Stub Skeleton RMI Architecture Process Rmi Registry Compiling & Executing the RMI Application PSD1B- Advance Java Programming 41
RMI The RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed application in java. The RMI provides remote communication between the applications using two objects stub and skeleton. PSD1B- Advance Java Programming 42
Stub The stub is an object, acts as a gateway for the client side. All the outgoing requests are routed through it. It resides at the client side and represents the remote object. When the caller invokes method on the stub object, it does the following tasks: It initiates a connection with remote Virtual Machine (JVM), It writes and transmits (marshals) the parameters to the remote Virtual Machine (JVM), It waits for the result It reads (unmarshals) the return value or exception, and It finally, returns the value to the caller. PSD1B- Advance Java Programming 43
Skeleton The skeleton is an object, acts as a gateway for the server side object. All the incoming requests are routed through it. When the skeleton receives the incoming request, it does the following tasks: It reads the parameter for the remote method It invokes the method on the actual remote object, and It writes and transmits (marshals) the result to the caller. PSD1B- Advance Java Programming 44
RMI Architecture PSD1B- Advance Java Programming 45
Process PSD1B- Advance Java Programming 46
RMIRegistry PSD1B- Advance Java Programming 47
Goals of RMI To minimize the complexity of the application. To preserve type safety. Distributed garbage collection. Minimize the difference between working with local and remote objects. PSD1B- Advance Java Programming 48
Compiling the Application To compile the application Compile the Remote interface. Compile the implementation class. Compile the server program. Compile the client program. PSD1B- Advance Java Programming 49
Executing the Application Step 1 Start the rmi registry using the following command. Start rmiregistry PSD1B- Advance Java Programming 50
Step2 Run the server class file as shown below. java Server PSD1B- Advance Java Programming 51
Step 3 Run the client class file as shown below. java client PSD1B- Advance Java Programming 52
Verification PSD1B- Advance Java Programming 53
UNIT V - SYLLABUS JSP Stub Skeleton RMI Architecture Process Rmi Registry Compiling & Executing the RMI Application PSD1B- Advance Java Programming 54
JSP A JSP page is a page created by the web developer that includes JSP technology-specific tags, declarations, and possibly scriptlets, in combination with other static HL or XML tags. A JSP page has the extension.jsp This signals to the web server that the JSP engine will process elements on this page. The page is compiled into a Java Servlet class and remains in server memory, so subsequent calls to the page have very fast response times. PSD1B- Advance Java Programming 55
Client and Server with JSP PSD1B- Advance Java Programming 56
Simple JSP Page <%@ page info= A Simple JSP Sample %> <HL> <H1> First JSP Page </H1> <BODY> <% out.println( Welcome to JSP world ); %> </BODY> </HL> PSD1B- Advance Java Programming 57
How JSP Works? User Request JSP File Requested Server Create Source from JSP File Changed Compile Execute Servlet PSD1B- Advance Java Programming 58
JSP Elements Declarations <%! code %> <jsp:declaration> </jsp:declaration > Expressions <%= expression %> <jsp:expression> </jsp:expression> Scriplets <% code %> <jsp:scriplet> </jsp:scriplet > PSD1B- Advance Java Programming 59
JSP Example <HL> <HEAD><TITLE>JSP Declarations</TITLE></HEAD> <BODY><H1>JSP Declarations</H1> <%! private int keepcount = 0; %> <H2> Page accessed: <%= ++keepcount %> times </H2> </BODY> </HL> PSD1B- Advance Java Programming 60
Predefined Variable - Object request Object of HttpServletRequest (request parameters, HTTP headers, cookies response Object of HttpServletResponse out - Object of PrintWriter buffered version JspWriter session - Object of HttpSession associated with the request application - Object of ServletContext shared by all servlets in the engine config - Object of ServletConfig pagecontext - Object of PageContext in JSP for a single point of access PSD1B- Advance Java Programming 61
Expression Syntax Description: An expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. Contains an expression valid in the scripting language used in the JSP page. <%= expression %> <%! String name = new String( JSP World ); %> <%! public String getname() { return name; } %> <B><%= getname() %></B> PSD1B- Advance Java Programming 62
JSP Life Cycle Servlet from JSP Init Event jspinit() Request Response jspservice() Destroy Event jspdestroy() PSD1B- Advance Java Programming 63
JSP Page Directive Directives are messages to the JSP container and do not produce output into the current output stream Syntax: <%@ directive attribute= value %> <%@ directive attribute1= value1 attribute1 = value2 %> There are three types of directives: 1. page 2. include 3. taglib XML form: <jsp:directive.directivetype attribute= value /> PSD1B- Advance Java Programming 64
Different Scope Most visible Application Objects accessible from pages Belong to the same application. Session Request Objects accessible from pages Belonging to the same session. Objects accessible from pages processing the request. Page Objects accessible only within pages where they were created. Least visible PSD1B- Advance Java Programming 65
Jsp with Beans public class MessageBean { private String message = "No Message"; public String getmessage() { return message; } public void setmessage(string message) { this.message = message; } } PSD1B- Advance Java Programming 66
Conclusion JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HL. 1. One can simply write the regular HL in the normal manner, using whatever Web-page-building tools you normally use. 2. One can enclose then the code for the dynamic parts in special tags, most of which start with "<%" and end with "%>" PSD1B- Advance Java Programming 67