AJP Lab Manual
AJP Lab Manual
Place: __________
Date: __________
Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant
competencies in psychomotor domain. By keeping in view, GTU has designed competency
focused outcome-based curriculum for engineering degree programs where sufficient weightage
is given to practical work. It shows importance of enhancement of skills amongst the students
and it pays attention to utilize every second of time allotted for practical amongst students,
instructors and faculty members to achieve relevant outcomes by performing the experiments
rather than having merely study type experiments. It is must for effective implementation of
competency focused outcome-based curriculum that every practical is keenly designed to serve
as a tool to develop and enhance relevant competency required by the various industry among
every student. These psychomotor skills are very difficult to develop through traditional chalk
and board content delivery method in the classroom. Accordingly, this lab manual is designed to
focus on the industry defined relevant outcomes, rather than old practice of conducting practical
to prove concept and theory.
By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which creates an interest and students can have basic idea prior to
performance. This in turn enhances pre-determined outcomes amongst students. Each
experiment in this manual begins with competency, industry relevant skills, course outcomes as
well as practical outcomes (objectives). The students will also achieve safety and necessary
precautions to be taken while performing practical.
This manual also provides guidelines to faculty members to facilitate student centric lab
activities through each experiment by arranging and managing necessary resources in order that
the students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.
Advance Java Programming is an Elective course. It covers various java based technologies like
socket, JDBC, Servlet and JSP which help students to develop enterprise application. Web
application based on Java uses Servlet, JSP, JSF etc. To store the data database connectivity and
database JDBC component is needed. Networking components are needed to transfer data over
network. Model-View-Controller (MVC) architecture gives flexibility and makes the web
applications loosely coupled.
Utmost care has been taken while preparing this lab manual however always there is chances of
improvement. Therefore, we welcome constructive suggestions for improvement and removal
of errors if any.
Advance Java Programming (3160707)
DTE’s Vision
Institute’s Vision
Institute’s Mission
Department’s Vision
Department’s Mission
The following industry relevant competency are expected to be developed in the student by
undertaking the practical work of this laboratory.
1. Will be able to develop web application using Netbeans/Ecllipse IDE
2. Will be able to use MVC architecture for application development
3. Will be able to use JSF and Hibernate framework
Project Details: In the movie review website, the administrator will be able to
enter the new movie details like movie_name, genre, language, movie_certificate
details, release_date, etc. The administrator should be able to add, view, delete
and modify movie details. The movie details and user details should have been
stored in the database. Other users will be able to search the movie and fetch the
details about a particular movie. They should be able to comment and review the
movie. For review, the users will be entering a positive integer number between 0
to 10. For comment, they can write texts.
Sr. No. Objective(s) of Experiment
1 In java console application, provide the user with following options: add movie, view
movie, modify movie details, delete movie details. On entering a particular option on
the console by user, perform appropriate operation and display the success/failure or
any output on your console.
2 Make the practical 1 application as server for sending/receiving strings. Create a client
application that will send a search movie string to the server application and server will
replay with the matching movie name “string” back to the client application after
fetching from the database.
3 Modify practical 1 by replacing the console based user interface to a web based user
interface. Use a servlet.
4
Modify the practical 4 to use JSP instead of Servlet.
5
Use JSF framework to replace JSP and calculate the reduction in programming
6 Make custom tag for a component that will be able to add/view/delete/modify
Records
7 Use Object Relational Mapping and based on that prepare one configuration file along
with the hibernet mapping file for 1 table of the application and test its working by
replacing SQL to HQL.
8 Use Hibernet framework to replace JDBC calls and calculate the reduction in
programming efforts for the entire application
9 Use Spring or any other MVC architecture and implement the Interface in that
architecture that supports multi-tier architecture.
10
Compare and analyze the JSF with the Spring/any other framework.
Advance Java Programming (3160707)
Index
(Progressive Assessment Sheet)
Sr. Objective(s) of Experiment Page Date of Date of Assessme Sign. of Remar
No. No. perform submiss nt Teacher ks
ance ion Marks with date
Total
Experiment No: 1
In java console application, provide the user with following options: add movie, view movie,
modify movie details, delete movie details. On entering a particular option on the console by
user, perform appropriate operation and display the success/failure or any output on your
console.
Date:
Theory:
A JDBC program comprises the following FIVE steps:
Procedure:
1. Create a database for your project
2. Write java program to interact with tables in database using Type 4 JDBC driver.
Observations:
Conclusion:
Quiz:
1) List and explain all four types of JDBC Drivers.
2) What is parameterised query? How it can be executed in java? 3)
Write a note on various APIs of java.sql package.
Suggested Reference:
JDBC™ API Tutorial and Reference, Third Edition, Maydene Fisher, Jon Ellis, Jonathan Bruce,
Addison
Wesley
References used by the students:
Experiment No: 2
Make the practical 1 application as server for sending/receiving strings. Create a client
application that will send a search movie string to the server application and server will
replay with the matching movie name “string” back to the client application after
fetching from the database. Date:
Objectives: (a) To show how to implement TCP/UDP communication between two java
program using Socket/ ServerSocket and DatagramSocket/DatagramPacket.
(b) To show how to implement client server relationship between programs.
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Netbeans/eclipse
Theory:
Java Networking Terminology: IP Address, Protocol, Port Number, MAC Address, Connection-
oriented and connection-less protocol, Socket
2) Protocol: A protocol is a set of rules basically that is followed for communication. For example:
TCP, FTP, Telnet, SMTP, POP etc.
3) Port Number: The port number is used to uniquely identify different applications. It acts as a
communication endpoint between applications. The port number is associated with the IP address
for communication between two applications.
4) MAC Address: MAC (Media Access Control) address is a unique identifier of NIC (Network
Interface Controller). A network node can have multiple NIC but each with unique MAC address.
For example, an ethernet card may have a MAC address of 00:0d:83::b1:c0:8e.
java.net package
The java.net package can be divided into two sections: A Low-Level API: It deals with the
abstractions of addresses i.e. networking identifiers, Sockets i.e. bidirectional data communication
mechanism and Interfaces i.e. network interfaces .A High Level API: It deals with the abstraction of
URIs i.e. Universal Resource Identifier, URLs i.e. Universal Resource Locator, and Connections i.e.
connections to the resource pointed by URLs.
Observations:
Conclusion:
Quiz:
1. Explain InetAddress class and its use in network programming.
2. With the help of example show the use of URL and URLConnection class.
3. How can we do network programming using UDP in java? Explain DatagramSocket
and DatagramPacket in Java.
Experiment No: 3
Modify practical 1 by replacing the console based user interface to a web based user
interface.
Use a servlet.
Date:
Objectives: (a) implement webpages using HTML for collecting user input.
(b) able to do server side programming using Servlet to process user input.
(c) To show how Servlet can interact with Database
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Apache Tomcat Server,
Netbeans/eclipse, Oracle Xpress edition 11g, Type4 JDBC driver for Oracle
Theory:
• Servlet technology is used to create web application
• Servlet technology is robust and scalable because of java language.
• Before Servlet, CGI (Common Gateway Interface) scripting language was popular as a
server-side programming language.
• There are many interfaces and classes in the servlet API such as Servlet,
GenericServlet, HttpServlet, ServletRequest, ServletResponse etc.
Servlet APIs
• javax.servlet and javax.servlet.http
• javax.servlet package contains many interfaces and classes that are used by the
servlet or web container.
• javax.servlet.http package contains interfaces and classes that are responsible for http
requests
The servlet can be created by three ways:
By implementing Servlet interface,
By inheriting GenericServlet class,
By inheriting HttpServlet class
• The mostly used approach is by extending HttpServlet.
The steps are as follows:
• Create a directory structure
• Create a Servlet
• Compile the Servlet
• Create a deployment descriptor
• Start the server(Apache tomcat) and deploy the project
• Access the servlet
Safety and necessary Precautions:
1. Make sure the database server and application server are started before running
the program
2. Put you application directory in to root directory of Tomcat server
3. To run the program use any web browser
4. Handle all necessary compile time Exception
Procedure:
1. Create a directory structure for web application in application folder.
2. Create database for your project
3. Create an html file asking for data from user and submit those data to servlet in
application folder
4. Create a servlet class to receive the input and process it as per your requirement, Also
this servlet program can interact with database using Type 4 JDBC driver.
5. Prepare web.xml file to put deployment descriptor
6. Compile to servlet program
7. Put application folder into root directory of application server( wepapps folder of
Tomcat server)
8. Open any web browser and run the program by typing url in address bar.
Observations:
//Put Programs, HTML file, web.xml file along with Output of the program
Conclusion:
Quiz:
1. List various characteristics of Enterprise application.
2. Draw and explain servlet life cycle.
3. Compare servlet with JSP.
4. What is session tracking? How can we implement it in Servlet?
Suggested Reference:
Complete Reference J2EE by James Keogh mcgraw publication
Professional Java Server Programming by Subrahmanyam Allamaraju, Cedric Buest Wiley
Publication
Date:
Objectives: (a) implement webpages using HTML for collecting user input.
(b) able to do server side programming using JSP to process user input.
(c) To show how JSP can interact with Database
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Apache Tomcat Server,
Netbeans/eclipse, Oracle Xpress edition 11g, Type4 JDBC driver for Oracle
Theory:
Java Server Pages (JSP) is a server-side programming technology that enables the creation of
dynamic, platform-independent method for building Web-based applications.
JSP can be run as per the following diagram −
Steps to configure JDK and Tomcat server for servlet and JSP program
1) Download Java (JDK) and install it.
2) Set PATH and JAVA_HOME environment variable
set PATH = C:\jdk1.5.0_20\bin;%PATH% set JAVA_HOME = C:\jdk1.5.0_20
(Assuming java installed in c:\ and jdk1.5.0_20)
3) Download the latest version of Tomcat and install it
4) Create a CATALINA_HOME environment variable pointing to C:\apache-tomcat-5.5.29.
(assuming tomcat is installed in C:\apache-tomcat-5.5.29)
5) Run following command to start tomcat server
C:\apache-tomcat-5.5.29\bin\startup.bat
After a successful startup, the default web-applications included with Tomcat will be available by
visiting http://localhost:8080/.
6) Tomcat can be stopped by executing the following commands on the Windows machine −
C:\apache-tomcat-5.5.29\bin\shutdown
7) Set classpath as below, set CATALINA = C:\apache-tomcat-5.5.29
set CLASSPATH = %CATALINA%\common\lib\jsp-api.jar;%CLASSPATH%
Procedure:
1. Create a directory structure for web application in application folder.
2. Create database for your project
3. Create an html file asking for data from user and submit those data to jsp in
application folder
4. Create a jsp program to receive the input and process it as per your requirement,
Also this jsp program can interact with database using Type 4 JDBC driver.
5. Prepare web.xml file to put deployment descriptor
6. Put application folder into root directory of application server( wepapps folder of
Tomcat server)
7. Open any web browser and run the program by typing url in address bar.
Observations:
//Put Programs, HTML file, web.xml file along with Output of the program
Conclusion:
Quiz:
1. List advantages of JSP.
2. List and explain JSP implicit objects.
3. What is the difference between include directive and include action?
4. How can we forward a request from JSP to servlet?
Suggested Reference:
Complete Reference J2EE by James Keogh mcgraw publication
Professional Java Server Programming by Subrahmanyam Allamaraju, Cedric Buest Wiley
Publication
Date:
Competency and Practical Skills: Design a web application using JSF Framework
Theory:
Java Server Faces (JSF) is a Java-based web application framework intended to simplify development
integration of web-based user interfaces.
Basic understanding of Java programming language, and understanding of other web technologies
such as HTML, CSS, AJAX, etc. is required to use JSF.
JSF facilitates Web application development by −
A JSF application consists of web pages with JSF UI components. A JSF application
requires also some configuration files web.xm ("faces-config.xml" and ).
l
The faces-config.xml defines:
• Managed Bean - the data elements of the JSF application (managed beans and backing beans)
represent a Java class which will be created dynamically during runtime of the JSF application. It
can be defined for which scope the bean is valid (Session, Request, Application or none)
• the navigation between web pages
• data validators - Used to check the validity of UI input
• data converters -Used to translate between UI and model
Procedure:
1) Create database for your project
2) Open netbeans and create a new project (web application with JSF)
3) Add or modify the code in files mentioned in above screenshot
4) Run the project.
Observations:
//Put Programs, HTML file, web.xml file along with Output of the program
Conclusion:
Quiz:
1. What features Java Server Faces offer in web development?
2. Draw and Explain JSF life cycle.
3. What is the significance of managed beans in Java Server Faces?
4. List the advantages of using Facelet.
Suggested Reference:
Java Server Faces in Action, Kito D. Mann, Manning Publication
Beginning JSP, JSF andTomcat, Giulio Zambon, Apress
JSF2.0 CookBook, Anghel Leonard, PACKT publication
Date:
Relevant CO:CO3
Objectives: (a) To be able to use custom tag for use in JSP for converting java scriptlets to
tags in a JSP page.
(b) To be able to implement the custom tag for CRUD operations.
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Netbeans/eclipse, Oracle
Xpress edition 11g, Apache Tomcat / GlassFish / any other web server for Java.
Theory:
Custom tags are user-defined tags. They eliminates the possibility of scriptlet tag and separates the
business logic from the JSP page.
The same business logic can be used many times by the use of custom tag.
Eliminates the need of scriptlet tag The custom tags eliminates the need of scriptlet tag which is
considered bad programming approach in JSP.
Separation of business logic from JSP The custom tags separate the the business logic from the JSP
page so that it may be easy to maintain.
Re-usability The custom tags makes the possibility to reuse the same business logic again and again.
Procedure:
1. Create the Tag handler class and perform action at the start or at the end of the
tag. To create the Tag Handler, we are inheriting the TagSupport class and overriding
its method doStartTag().To write data for the jsp, we need to use the JspWriter
class.The PageContext class provides getOut() method that returns the instance of
JspWriter class. TagSupport class provides instance of pageContextbydefault.
2. Create the Tag Library Descriptor (TLD) file and define tags
Tag Library Descriptor (TLD) file contains information of tag and Tag Hander
classes. It must be contained inside the WEB-INF directory.
3. Create the JSP file that uses the Custom tag defined in the TLD file
Let's use the tag in our jsp file. Here, we are specifying the path of tld file directly.
But it is recommended to use the uri name instead of full path of tld file. We will learn
about urilater.It uses taglib directive to use the tags defined in the tld file.
Observations:
Conclusion:
Quiz:
1. List and explain types of custom tags.
2. What are the methods of Tag interface? Explain their importance.
3. Write and Explain the TLD file structure and steps for creating it.
Suggested Reference:
https://docs.oracle.com/cloud/latest/as111170/TAGLB/quickstart.htm
Date:
Objectives: (a) To understand object relational impedance and prepare the object relational
mapping and mapping file
(b) To understand and prepare hibernet configuration file
(c) To use HQL to execute a query
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Netbeans/eclipse,
Hibernetframwork
Theory:
Hibernate Framework
Hibernate framework is open source under the LGPL license and lightweight.
2) Fast Performance
The performance of hibernate framework is fast because cache is internally used in hibernate
framework. There are two types of cache in hibernate framework first level cache and second level
cache. First level cache is enabled by default.
HQL (Hibernate Query Language) is the object-oriented version of SQL. It generates the database
independent queries. So you don't need to write database specific queries. Before Hibernate, if
database is changed for the project, we need to change the SQL query as well that leads to the
maintenance problem.
Hibernate framework provides the facility to create the tables of the database automatically. So there
is no need to create tables in the database manually.
Hibernate supports Query cache and provide statistics about query and database status.
For creating the first hibernate application, we must know the elements of Hibernate architecture.
They are as follows:
SessionFactory
The SessionFactory is a factory of session and client of ConnectionProvider. It holds second level
cache (optional) of data. The org.hibernate.SessionFactory interface provides factory method to get
the object of Session.
Session
The session object provides an interface between the application and data stored in the database. It is a
short-lived object and wraps the JDBC connection. It is factory of Transaction, Query and Criteria. It
holds a first-level cache (mandatory) of data. The org.hibernate.Session interface provides methods to
insert, update and delete the object. It also provides factory methods for Transaction, Query and
Criteria.
Transaction
The transaction object specifies the atomic unit of work. It is optional. The org.hibernate.Transaction
interface provides methods for transaction management.
ConnectionProvider
TransactionFactory
Procedure:
For creating the first hibernate application, we need to follow the following steps:
Observations:
Conclusion:
Quiz:
4. Explain the Object Relational mis-match. How can we overcome in hibernet?
5. What is HQL? How is it different? What are the advantages?
6. What is a hibernet configuration file. Provide the steps to create the configuration file.
Suggested Reference:
https://docs.oracle.com/cd/E11035_01/workshop102/ormworkbench/hibernatetutorial/
tutHibernate1.html
Theory:
Hibernate Query Language (HQL) is same as SQL (Structured Query Language) but it
doesn't depends on the table of the database. Instead of table name, we use class name in
HQL. So it is database independent query language.
Advantage of HQL
There are many advantages of HQL. They are as follows:
1. database independent
2. supports polymorphic queries
3. easy to learn for Java Programmer
Query Interface
It is an object oriented representation of Hibernate Query. The object of Query can be
obtained by calling the createQuery() method Session interface.
The query interface provides many methods. There is given commonly used methods: Play
Video
Procedure:
For creating the first hibernate application in Eclipse IDE, we need to follow the following steps:
Conclusion:
Quiz:
1) How HQL supports database independence? Explain with example.
2) How HQL can help reduce the object querying for composite objects. 3) Explain the
difference between JPA and Hibernet.
Suggested Reference:
https://docs.oracle.com/cloud/latest/as111170/TAGLB/quickstart.htm
Objectives:
(a) To understand MVC architecture.
(b) To understand and use Spring as a reference MVC architecture for ease of
programming
(c) To assess the impact of using a framework instead of pure JSP file for development,
maintenance etc.
.
Equipment/Instruments: Personal Computer, JDK 1.8 or advance, Netbeans/eclipse, Spring
and Hibernetframwork
Theory:
The Spring framework comprises several modules such as IOC, AOP, DAO, Context, ORM,
WEB MVC etc. We will learn these modules in next page. Let's understand the IOC and
Dependency Injection first.
1) Predefined Templates
Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So there is
no need to write too much code. It hides the basic steps of these technologies.
Let's take the example of JdbcTemplate, you don't need to write the code for exception
handling, creating connection, creating statement, committing transaction, closing connection
etc. You need to write the code of executing query only. Thus, it save a lot of JDBC code.
2) Loose Coupling
The Spring applications are loosely coupled because of dependency injection.
3) Easy to test
The Dependency Injection makes easier to test the application. The EJB or Struts application
require server to run the application but Spring framework doesn't require server.
4) Lightweight
Spring framework is lightweight because of its POJO implementation. The Spring
Framework doesn't force the programmer to inherit any class or implement any interface.
That is why it is said non-invasive.
5) Fast Development
The Dependency Injection feature of Spring Framework and it support to various frameworks
makes the easy development of JavaEE application.
6) Powerful abstraction
It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA.
7) Declarative support
It provides declarative support for caching, validation, transactions and formatting.
- Create a table
Observations:
Conclusion:
Quiz:
1. What is Dependency Injection? How is it useful for creating the maintainable projects?
2. What is MVC? Why is it important?
3. Explain the roles of MVC components for a web application.
Date:
Theory:
JavaServer Faces
It is a server side component based user interface framework. It is used to develop web
applications. It provides a well-defined programming model and consists of rich API and tag
libraries. The latest version JSF 2 uses Facelets as its default templating system. It is written
in Java.
The JSF API provides components (inputText, commandButtonetc) and helps to manage their
states. It also provides server-side validation, data conversion, defining page navigation,
provides extensibility, supports for internationalization, accessibility etc.
The JSF Tag libraries are used to add components on the web pages and connect components
with objects on the server. It also contains tag handlers that implements the component tag.
With the help of these features and tools, you can easily and effortlessly create server-side
user interface.
2) JavaServer Faces API?s are layered directly on top of the Servlet API. Which enables
several various application use cases, such as using different presentation technologies,
creating your own custom components directly from the component classes.
Procedure:
A Simple JavaServer Faces Application
To create a JSF application, we are using NetBeans IDE 8.2. You can also refer to other Java
IDEs.
Here, we are creating a project after that we will run to test it's configuration settings. So, let's
create a new project fist.
- Go to file menu and select new Project.-> Select Category Java Web and Project Web
Application. -> Enter project name.
- Select Preferred Page Language: Earlier versions of JSF framework are default to JSP
for presentation pages. Now, in latest version 2.0 and later JSF has included powerful
tool "Facelets". So, here we have selected page language as facelets. We will talk
about facelets in more details in next chapter.
- Index.xhtml Page: After finishing, IDE creates a JSF project for you with a default
index.xhtml file. Xhtml is a extension of html and used to create facelets page.
- Run: Now, you can run your application by selecting run option after right click on
the project. It will produce a default message "Hello from Facelets".
Whenever we run the project, it renders index.xhtml as output. Now, we will create an
application which contains two web pages, one bean class and a configuration file.
Conclusion:
Quiz:
1. What is Java ServerFaces? How is it useful?
2. How JSF is different from Spring? Explain the limitations and advantages.
3. Explain the JSF lifecycle in detail.
Suggested Reference:
https://www.oracle.com/java/technologies/javaserverfaces.html