Practical 1 2 3
Practical 1 2 3
Practical 1 2 3
Place:
Date:
Preface
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
1 In java console application, provide the user with following options: add, view, modify
details, delete 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 book string to the server application and server will
replay with the matching book 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)
Total
Experiment No: 1
In java console application, provide the user with following options: add, view, modify
details, delete 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:
STEP 1: Allocate a Connection object, for connecting to the database server.
STEP 2: Allocate a Statement object, under the Connection created earlier, for holding a SQL command.
STEP 3: Write a SQL query and execute the query, via the Statement and Connection created.
STEP 4: Process the query result.
STEP 5: Close the Statement and Connection to free up the resources.
1) Make sure the database server is started before running the program
2) Handle all necessary compile time Exception
Procedure:
1. Create a database for your project
2. Write java program to interact with tables in database using Type 4 JDBC driver.
Observations:
import java.sql.*;
class data {
int sid;
String s_name;
String s_email;
String s_phone;
}
}
} catch (Exception e) {
System.out.println(e);
}
}
stmt.executeUpdate(sql);
} catch (Exception e) {
System.out.println(e);
}
}
} catch (Exception e) {
System.out.println(e);
}
}
} catch (Exception e) {
System.out.println();
}
return rs;
}
try {
conn = getConnection();
stmt = conn.createStatement();
createTable(stmt);
insertstudentDetail(stmt, new data(3, "dakshesh", "[email protected]", "8752832478" ));
updatestudentDetail(stmt,new data(2, "princy", "[email protected]", "9567537850" ));
// deletestudentDetail(stmt,2);
rs = searchData(stmt, "");
System.out.println(getSearchResult(rs));
stmt.close();
conn.close();
Output :
Insert details
Update details
Delete details
Conclusion:
JDBC API can be used in order to access the tabular data stored in any of the relational
databases. By using JDBC API, you can save, update, delete, and fetch the data from the database.
Therefore, it is considered to be Open Database Connectivity, that is, ODBC provided by
Microsoft.
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:
JDBC™ API Tutorial and Reference, Third Edition, Maydene Fisher, Jon Ellis, Jonathan Bruce, Addison
Wesley
marks obtained:
Knowledge of Programming Team work (2) Communication Skill Ethics(2)
subject (2) Skill (2)
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Average
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 2
Make the practical 1 application as server for sending/receiving strings. Create a client
application that will send a search string to the server application and server will replay
with the matching 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.
Safety and necessary Precautions:
1. Make sure the server/receiver program runs first
2. Handle all necessary compile time Exception
Procedure:
1. Create a Sender/Client program and Receiver/Server program.
2. Compile them
3. Run Server/Receiver program first and then run Client/Sender program
Observations:
//server side
import java.io.IOException;
import java.net.*;
import java.sql.*;
import Driver;
public class Server extends Driver{
private static final int PORT = 12345; // the port number the server listens on
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(PORT);
System.out.println("Server listening on port " + PORT);
//client side
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) {
try {
// Establish socket connection with server application
Socket socket = new Socket("localhost", 12345);
// Send search string to server application
(server)
(client)
Conclusion:
This practical based on TCP Connection based Protocol. Now client request to the server using
port and client enter the string and server will response .
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.
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Average
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
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
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:
package tanmay;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author HP
*/
public class tanmay {
public static void main(String[] args){
public class MaterialServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
} else if (operation.equals("view")) {
ResultSet rs = Driver.searchData(stmt, search);
String searchResult = Driver.getSearchResult(rs);
out.println("<html><body>");
out.println("<h2>student Details</h2>");
out.println("<pre>" + searchResult + "</pre>");
out.println("</body></html>");
} else if (operation.equals("modify")) {
Driver.updatestudentDetail(stmt, new Data(sid, s_name, s_email, s_phone, publisher, year, language));
out.println("<html><body>");
out.println("<h2>student Modified Successfully!</h2>");
out.println("</body></html>");
} else if (operation.equals("delete")) {
Driver.deletestudentDetail(stmt, sid);
out.println("<html><body>");
out.println("<h2>student Deleted Successfully!</h2>");
out.println("</body></html>");
} else {
out.println("<html><body>");
out.println("<h2>Invalid operation!</h2>");
out.println("</body></html>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
Output:
Html:-
Database:-
Conclusion:
This are servlet class using this servlet class Make a interface and make form in the interface.
Now if user add the data in the form and select the add Data and that Data add in the Database and
if user wish to delete data than select delete and than Data was deleted and many other operation
can do.
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
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Average
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks