You are on page 1of 63

SILVER OAK UNIVERSITY

COLLEGE OF TECHNOLOGY

BACHELOR OF ENGINEERING
Advanced Java (1010043339)

6th SEMESTER

College Name:

Enrolment No/Roll No:

Name of Student:

Branch:

Semester:

Division:

DEPARTMENT OF INFORMATION TECHNOLOGY

1
VISION
● To create competent professionals in the field of Information Technology and
promote research with a motive to serve as a valuable resource for the CE/IT
industry and society.

MISSION
1. To produce technically competent and ethically sound Information
Technology professionals by imparting quality education, training, hands on
experience and value based education.
2. To inculcate ethical attitude, sense of responsibility towards society and
leadership ability required for a responsible professional computer engineer.
3. To pursue creative research, adapt to rapidly changing technologies and
promote self-learning approaches in Information Technology and across
disciplines to serve the dynamic needs of industry, government and society.

2
Program Educational Objectives (PEO):
PEO1: To provide the fundamentals of science, mathematics, electronics and
computer science and engineering and skills necessary for a successful CE/ IT
professional.

PEO2: To provide scope to learn, apply skills, techniques and competency to use
modern engineering tools to solve computational problems.

PEO3: To enable young graduates to adapt to the challenges of evolving career


opportunities in their chosen fields of career including higher studies, research
avenues, entrepreneurial activities etc.

PEO4: To inculcate life-long learning aptitude, leadership qualities and teamwork


ability with sense of ethics for a successful professional career in their chosen field.

3
PROGRAM OUTCOMES (POs)

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health
and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and
IT tools including prediction and modeling to complex engineering activities with an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering
practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal
and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams,
and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent
and life-long learning in the broadest context of technological change.

4
ADVANCED JAVA PROGRAMMING PRACTICAL BOOK

DEPARTMENT OF INFORMATION TECHNOLOGY

PREFACE

It gives us immense pleasure to present the first edition of the Basics of Advanced Java
Programming Practical Book for the Degree Engineering 3nd year students of Silver Oak Group of
Institutes.

The Advanced Java Programming theory and laboratory course at Silver Oak Group of Institutes,
Ahmedabad is designed in such a way that students develop the basic understanding of the subject
in the theory classes and gain hands-on practical experience during their laboratory sessions. The
Lab Manual has been designed in such a way that students will get exposure to different kinds of
programs. Difficulty level of programs is increased with each subsequent practical. Students will
get an opportunity to use various sets of instructions. It covers not only practical from the suggested
list of Silver Oak university syllabus but also various programs which have been asked in
university examination. It will surely help students to recall the theoretical knowledge acquired
during lectures and apply it for practical execution of practical. In a way it will draw analogies
between theory and practical and will strengthen the understanding of various topics.

We acknowledge the authors and publishers of all the books which we have consulted while
developing this Practical book. Hopefully this advanced Java Practical Book will serve the purpose
for which it has been developed.

Lab Manual Prepared by: Prof. Shalu Peshwani (ASOIT CE/IT Department)

Lab Manual Revision No.: SOU_LM_2022_1

5
CERTIFICATE

This is to certify that

Mr./Ms................................................................................................................

with enrolment no. ................................................................from Semester

………Div.…….. has successfully completed his/her laboratory experiments

in the ADVANCED JAVA (1010043339) from the department of

................................................................during the academic year ........... -

........

Date of Submission: ......................... Staff In charge: ...........................

Head of Department: ...........................................

6
TABLE OF CONTENT
Page No Date
Sr. Date of Marks
Experiment Title of Sign
No Completion (out of 10)
To From Start

1 Implement TCP Server for transferring


files using Socket and ServerSocket.
Write an RMI application where client
supplies two numbers and server response by
2
summing it. Provide your custom security
policy for this application.
Implement student registration form with
enrolment number, first name, last name,
3 semester, contact number. Store the details
in a database(JDBC). Also implement search,
delete and modify facilities for student records.
Write a Servlet program to print system date
4
and time.

5 Create Servlet file and study web descriptor


file.
Create login form and perform state
6 management using Cookies, HttpSession and
URL Rewriting.
Create database of student subject-wise data
and retrieve all data using JSP and generate
7
xml structure along with DTD and XML
Schema definition
Design a web page that takes the Username
8 from user and if it is a valid username prints
“Welcome Username”. Use JSF to implement.
Write Hibernate application to store customer
9 records and retrieve the customer record
including name, contact number, address.
Write an application to keep record and
retrieve record of student. The record includes
10
student id, enrolment number, semester, SPI.
Use MVC architecture.

7
PRACTICAL-1

Description:
TCP sockets are used for communication between a server and a client process. The server’s code runs
first, which opens a port and listens for incoming connection requests from clients. Once a client connects
to the same (server) port, the client or server may send a message. Once the message is sent, whoever
receives it (server or client) will process it accordingly.

Socket Programming
Sockets provide the communication mechanism between two computers using TCP. A client program
creates a socket on its end of the communication and attempts to connect that socket to a server.
When the connection is made, the server creates a socket object on its end of the communication. The
client and the server can now communicate by writing to and reading from the socket.
The java.net.Socket class represents a socket, and the java.net.ServerSocket class provides a mechanism
for the server program to listen for clients and establish connections with them.
The following steps occur when establishing a TCP connection between two
computers using sockets −
● The server instantiates a ServerSocket object, denoting which port number communication is
to occur on.
● The server invokes the accept() method of the ServerSocket class. This method waits until a
client connects to the server on the given port.
● After the server is waiting, a client instantiates a Socket object, specifying the server name
and the port number to connect to.
● The constructor of the Socket class attempts to connect the client to the specified server and
the port number. If communication is established, the client now has a Socket object capable
of communicating with the server.
● On the server side, the accept() method returns a reference to a new socket on the server that
is connected to the client's socket.
After the connections are established, communication can occur using I/O streams. Each socket has both
an OutputStream and an InputStream. The client's OutputStream is connected to the server's InputStream,
and the client's InputStream is connected to the server's OutputStream.
TCP is a two-way communication protocol, hence data can be sent across both streams at the same time.
Following are the useful classes providing complete set of methods to implement sockets.

8
Aim: Implement TCP Server for transferring files using Socket and ServerSocket.

Code:

9
10
OUTPUT:

Post Practical Questions:

1. How does applet and servlet communicate?


A)HTTP B) HTTPS
C) FTP D) HTTP Tunneling

2. Which class provides system independent server side implementation?


A) Socket B) ServerSocket
C) Server D) ServerReader

3. What happens if ServerSocket is not able to listen on the specified port?


A) The system exits gracefully with appropriate message
B) The system will wait till port is free
C) IOException is thrown when opening the socket
D) PortOccupiedException is thrown

4.What does a local IP address start with?


A) 10.X.X.X
B) 172.X.X.X
C) 192.168.X.X
D) 10.X.X.X, 172.X.X.X, or 192.168.X.X

5.What happens if the IP Address of the host cannot be determined?


A) The system exit with no message
B) UnknownHostException is thrown
C) IOException is thrown
D) Temporary IP Address is assigned

Conclusion:

11
PRACTICAL - 2

Description:
To write an RMI Java application, you would have to follow the steps given
below −
● Define the remote interface
● Develop the implementation class (remote object)
● Develop the server program
● Develop the client program
● Compile the application
● Execute the application

Defining the Remote Interface


A remote interface provides the description of all the methods of a particular remote object. The client
communicates with this remote interface.
To create a remote interface −
● Create an interface that extends the predefined interface Remote which belongs to the
package.
● Declare all the business methods that can be invoked by the client in this interface.
● Since there is a chance of network issues during remote calls, an exception named
RemoteException may occur; throw it.

Developing the Implementation Class (Remote Object)


We need to implement the remote interface created in the earlier step. (We can write an implementation
class separately or we can directly make the server program implement this interface.)
To develop an implementation class −
● Implement the interface created in the previous step.
● Provide implementation to all the abstract methods of the remote interface.

Developing the Server Program


An RMI server program should implement the remote interface or extend the implementation class. Here,
we should create a remote object and bind it to the RMIregistry.
To develop a server program −
● Create a client class from where you want invoke the remote object.
● Create a remote object by instantiating the implementation class as shown below.

12
● Export the remote object using the method exportObject() of the class named
UnicastRemoteObject which belongs to the package java.rmi.server.
● Get the RMI registry using the getRegistry() method of the LocateRegistry class which
belongs to the package java.rmi.registry.
● Bind the remote object created to the registry using the bind() method of the class named
Registry. To this method, pass a string representing the bind name and the object exported,
as parameters.

Developing the Client Program


Write a client program in it, fetch the remote object and invoke the required method using this object.
To develop a client program −
● Create a client class from where your intended to invoke the remote object.
● Get the RMI registry using the getRegistry() method of the LocateRegistry class which
belongs to the package java.rmi.registry.
● Fetch the object from the registry using the method lookup() of the class Registry which
belongs to the package java.rmi.registry.

To this method, you need to pass a string value representing the bind name as a parameter. This will
return you the remote object.
● The lookup() returns an object of type remote, down-cast it to the type Hello.
● Finally invokes the required method using the obtained remote object.

Compiling the Application


To compile the application −
● Compile the Remote interface.
● Compile the implementation class.
● Compile the server program.
● Compile the client program.

Aim: Write an RMI application where client supplies two numbers and server response by
summing it. Provide your custom security policy for this application.

Code:

13
14
15
OUTPUT:

Post Practical Questions:


1. Java supports RMI, RMI Stands for?
A) Random Method Invocation
B) Remote Memory Interface
C) Remote Method Invocation
D) Random Method Invocation

2. An RMI Server is responsible for _______


A) Creating an instance of the remote object
B) Exporting the remote object
C) Binding the instance of the remote object to the RMI registry
D) All mentioned above

3. RMI and EJB, provides services to access an object running in another JVM (known as remote
object).
A) True B)False

4. What are the exceptions which have to be handled in a RMI client program?
A) RemoteException
B) NotBoundException
C) MalFormedURLException
D) All mentioned above

Conclusion:

16
PRACTICAL - 3

Description:
Step 1 : Registering The Driver Class
First step in establishing the connection with any database is registering the JDBC driver class of that
database with DriverManager. As we are using Oracle database in our examples, we register
‘oracle.jdbc.driver.OracleDriver‘ class, which is the JDBC driver class of the Oracle, with the
DriverManager. As this step has to be performed only once for the whole execution, it is better to keep
this step in Static Initialization Block. Don’t forget to update your classpath with JDBC driver of the
Oracle database. Otherwise you will get ClassNotFoundException at run time.

Step 2 : Creating The Connection Object


In the second step, we create java.sql.Connection object using DriverManager.getConnection() method
by passing URL(jdbc:oracle:thin:@localhost:1521:XE), username and password of the database.

Step 3 : Creating The Statement Object


In the third step, we create java.sql.Statement object using con.createStatement() method where ‘con’ is
the reference to Connection object created in the second step.

Step 4 : Executing The Queries


In the fourth step, we send the queries to the database. While sending we use following methods of
Satement object depending upon the type of queries we are sending to the database.
ResultSet executeQuery(String sql) throws SQLException : This method is generally used for SQL
query statements which retrieve some data from the database. For example SELECT statement. This
method returns java.sql.ResultSet object which contains the results returned by the SELECT query.
int executeUpdate(String sql) throws SQLException : This method is generally used for SQL
statements which update the database. For example INSERT, UPDATE and DELETE. This method is
also used for SQL statements which return nothing. For example CREATE and ALTER statements.
This method returns an int value that represents the number of rows affected by the query. This value
will be 0 for the statements which return nothing.
boolean execute(String sql) throws SQLException : This method can be used to execute any kind of
SQL statements. If you don’t know which method to use for your SQL query, then this method is the
best option. This method returns a boolean value. TRUE indicates that query returned ResultSet object
and FALSE indicates that query returned an int value.

Step 5 : Closing The DB Resources


In the last step, we close all the DB resources – Connection, Statement and ResultSet objects.

17
Aim: Implement student registration form with enrolment number, first name, last name,
semester, contact number. Store the details in a database(JDBC). Also implement search, delete
and modify facilities for student records.

Code:

18
19
20
Output:

21
Post Practical Questions:
1. What does setAutoCommit(false) do?
A)It will not commit transactions automatically after each query.
B)It explicitly commits the transaction.
C)It never commits the transactions.
D)It does not commit transaction automatically after each query.
2. A good way to debug JDBC-related problems is to enable?
A)JDBC tracing
B)Exception handling
C)Both a and b
D)Only b
3. JDBC-ODBC driver is also known as?
A)Type 4
B)Type 3
C)Type 1
D)Type 2
4. What are the types of ResultSet in JDBC?
A)Forward ResultSet
B)Scrollable ResultSet
C)Only a
D)Both a and b
5. How many statement objects can be created using a Connection?
A)2
B)1
C)3
D)Multiple
Conclusion:

22
PRACTICAL - 4

Description:
One of the most important advantages of using Servlet is that you can use most of the methods
available in core Java. This tutorial would take you through Java provided Date class which is available
in java.util package, this class encapsulates the current date and time. The Date class supports two
constructors. The first constructor initializes the object with the current date and time.
Date( )
The following constructor accepts one argument that equals the number of milliseconds that have
elapsed since midnight, January 1, 1970
Date(long millisec)
Simple DateFormat Format Codes
To specify the time format use a time pattern string. In this pattern, all
ASCII letters are reserved as pattern letters, which are defined as the
following −
Character Description Example

G Era designator AD

y Year in four digits 2001

M Month in year July or 07

d Day in month 10

h Hour in A.M./P.M. (1~12) 12

H Hour in day (0~23) 22

m Minute in hour 30

23
s Second in minute 55

S Millisecond 234

E Day in week Tuesday

D Day in year 360

F Day of week in month 2 (second Wed. in July)

w Week in year 40

W Week in month 1

a A.M./P.M. marker PM

k Hour in day (1~24) 24

K Hour in A.M./P.M. (0~11) 10

z Time zone Eastern Standard Time

' Escape for text Delimiter

" Single quote `

Aim: Write a Servlet program to print system date and time.

Code:

24
Output:

Post Practical Questions:


1. Which of the following package contains servlet classes?
A) javax.servlet B) javax.servlet.http
C) Both of the above. D) None of the above.

25
2. Which of the following code is used to get a particular attribute in servlet?
A) request.getAttribute(name) B) response.getAttribute(name)
C) new Attribute(name) D) None of the above.

3. Which of the following code is used to set auto refresh of a page after 5 seconds?
A) session.setIntHeader("Refresh", 5) B) response.setIntHeader("Refresh", 5)
C) request.setIntHeader("Refresh", 5) D) None of the above.

Conclusion:

PRACTICAL - 5

Description:

Servlet technology is used to create a web application (resides at server side and generates a dynamic
web page). Servlet technology is robust and scalable because of java language. Before Servlet, CGI
(Common Gateway Interface) scripting language was common as a server-side programming language.
However, there were many disadvantages to this technology. We have discussed these disadvantages
below. There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet,
HttpServlet, ServletRequest, ServletResponse, etc.

What is a Servlet?

Servlet can be described in many ways, depending on the context.

● Servlet is a technology which is used to create a web application.


● Servlet is an API that provides many interfaces and classes including documentation.
● Servlet is an interface that must be implemented for creating any Servlet.
● Servlet is a class that extends the capabilities of the servers and responds to the incoming requests.
It can respond to any requests.
● Servlet is a web component that is deployed on the server to create a dynamic web page.

26
Aim: Create Servlet file and study web descriptor file

Code:

27
28
Post Practical Questions:

1. Which are the three ways to create the servlet?


A) By implementing the Servlet interface
B) By inheriting the GenericServlet class
C) By inheriting the HttpServlet class
D) All of the above

2. Using mail API we cannot send mail from a servlet.

A)True B)False

3. Can servlet class declare a constructor with ServletConfig object as an argument?

A) True B) False

4. When destroy() method of a filter is called?

A) The destroy() method is called only once at the end of the life cycle of a filter
B) The destroy() method is called after the filter has executed doFilter method
C) The destroy() method is called only once at the beginning of the life cycle of a filter
D) The destroyer() method is called after the filter has executed

Conclusion:

29
PRACTICAL- 6

Description

A cookie is a small piece of information that is persisted between the multiple client requests.

A cookie has a name, a single value, and optional attributes such as a comment, path and domain
qualifiers, a maximum age, and a version number.

How Cookie works

By default, each request is considered as a new request. In cookies technique, we add cookie with
response from the servlet. So cookie is stored in the cache of the browser. After that if request is sent by
the user, cookie is added with request by default. Thus, we recognize the user as the old user.

30
Types of Cookie

There are 2 types of cookies in servlets.

1. Non-persistent cookie
2. Persistent cookie

Non-persistent cookie

It is valid for single session only. It is removed each time when user closes the browser.

Persistent cookie

It is valid for multiple session . It is not removed each time when user closes the browser. It is removed
only if user logout or signout.

Session simply means a particular interval of time.

Session Tracking is a way to maintain state (data) of an user. It is also known as session management in
servlet.

Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user
requests to the server, server treats the request as the new request. So we need to maintain the state of an
user to recognize to particular user.

HTTP is stateless that means each request is considered as the new request. It is shown in the figure given
below:

00:00/06:31
10

31
Aim: Create login form and perform state management using Cookies, HttpSession and URL
Rewriting.

Code:

32
33
34
35
36
Output:

Post Practical Questions:


1. Which of the following code retrieves any extra path information associated with the URL the
client sent?
A)Header.getPathInfo()
B)response.getPathInfo()
C)request.getPathInfo()
D)None of the above.
2. Which of the following code encodes the specified URL by including the session ID in it?
A)response.encodeURL(url)
B)request.encodeURL(url)
C)Header.encodeURL(url)
D)None of the above.
3. Which of the following code can be used to redirect user to different url?
A) request.sendRedirect(location)
B)response.sendRedirect(location)
C)header.sendRedirect(location)
D)None of the above.
Conclusion:

37
PRACTICAL - 7

Description:

JSP technology is used to create web application just like Servlet technology. It can be thought of as an
extension to Servlet because it provides more functionality than servlet such as expression language,
JSTL, etc.

A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than Servlet
because we can separate designing and development. It provides some additional features such as
Expression Language, Custom Tags, etc.

The Lifecycle of a JSP Page

The JSP pages follow these phases:

● Translation of JSP Page


● Compilation of JSP Page
● Classloading (the classloader loads class file)
● Instantiation (Object of the Generated Servlet is created).
● Initialization ( the container invokes jspInit() method).
● Request processing ( the container invokes _jspService() method).
● Destroy ( the container invokes jspDestroy() me

38
As depicted in the above diagram, JSP page is translated into Servlet by the help of JSP translator. The
JSP translator is a part of the web server which is responsible for translating the JSP page into Servlet.
After that, Servlet page is compiled by the compiler and gets converted into the class file. Moreover, all
the processes that happen in Servlet are performed on JSP later like initialization, committing response
to the browser and destroy.

How to interact with a Database in JSP

In this article, I am going to discuss How to interact with a Database in JSP Application. Please read our
previous article, where we discussed JSP Standard Tag Library (JSTL) with Examples. As part of this
article, we are going to discuss the following pointers.

JSP Database Access

In JSP, we are using databases for storing huge types of data. We can easily connect with databases to
create and manage records. JSP has a number of actions for database access to improve the simple
database-driven JAP applications. These actions provide the following features:

1. Better performance and scalability.


2. Supports SQL queries like INSERT, UPDATE, DELETE and UPDATE.
3. Handles most common data type conversions.
4. Supports a combination of databases.

Aim: Create database of student subject-wise data and retrieve all data using JSP and generate xml
structure along with DTD and XML Schema definition.

39
Code:

40
41
42
Output:

Post Practical Questions:


1. Which page directive should be used in JSP to generate a PDF page?
A) contentType
B) generatePdf
C) typePDF
D) contentPDF

2. Which tag should be used to pass information from JSP to included JSP?
A) Using <%jsp:page> tag
B) Using <%jsp:param> tag
C) Using <%jsp:import> tag
D) Using <%jsp:useBean> tag

3. Application is instance of which class?


A) javax.servlet.Application
B) javax.servlet.HttpContext
C) javax.servlet.Context
D) javax.servlet.ServletContext

5. Where is metadata stored in MySQL?


A) In the MySQL database metadata
B) In the MySQL database metasql
C) In the MySQL database mysql
D) None of the mentioned

6. What MySQL property is used to create a surrogate key in MySQL?

43
A) UNIQUE
B) SEQUENCE
C) AUTO_INCREMENT
D) None of the mentioned

7. The doGet() method in the example extracts values of the parameter’s type and number by using
__________
A) request.getParameter()
B) request.setParameter()
C) responce.getParameter()
D) responce.getAttribute()

Conclusion:

PRACTICAL - 8

Description:

Java Server Faces (JSF) is a Java-based web application framework intended to simplify development
integration of web-based user interfaces. JavaServer Faces is a standardized display technology, which
was formalized in a specification through the Java Community Process.

JSF Life Cycle

JSF application life cycle consists of six phases which are as follows

● Restore view phase


● Apply request values phase; process events
● Process validations phase; process events
● Update model values phase; process events
● Invoke application phase; process events
● Render response phase

44
Aim:Design a web page that takes the Username from user and if it is a valid username prints
“Welcome Username”. Use JSF to implement.

Code:

45
46
Output:

Post Practical Questions:


1. What is the full form of JSF?
A) JavaScript Framework B) JavaServer Faces
C) JavaServer Facility D) None of the above

2. Which of the following isn't a jsp directive?


A) page B) include
C) scriptlet D) useBean

47
3. .......... isn't a directive.
A) page B) export
C) include D)useBean

4. What is the valid scopes in JSP?


A) request, page, session, application
B) response, page, session, application
C) request, page, context, application
D) request, page, session, global

5. DB connections aren't written directly in JSPs, because -


A) Not a standard J2EE architecture
B) Load Balancing is not possible
C) Response is slow
D) All of the above

Conclusion:

PRACTICAL - 9

Description:

Hibernate is an Object-Relational Mapping (ORM) solution for JAVA. It is an open source persistent
framework created by Gavin King in 2001. It is a powerful, high performance Object-Relational Persistence and
Query service for any Java Application. Hibernate maps Java classes to database tables and from Java data
types to SQL data types and relieves the developer from 95% of common data persistence related programming
tasks.

Hibernate sits between traditional Java objects and database server to handle all the works in persisting those
objects based on the appropriate O/R mechanisms and patterns.

48
Supported Databases
Hibernate supports almost all the major RDBMS. Following is a list of few of the
database engines supported by Hibernate −
● HSQL Database Engine
● DB2/NT
● MySQL
● PostgreSQL
● FrontBase
● Oracle
● Microsoft SQL Server Database
● Sybase SQL Server
● Informix Dynamic Server

Aim: Write Hibernate application to store customer records and retrieve the customer record
including name, contact number, address.

Code:

49
50
51
52
53
Output:

Post Practical Questions:


1. Which of the following is true about ORM?
A) ORM stands for Object-Relational Mapping.
B) ORM is a programming technique for converting data between relational databases.
C) Both of the above.
D) None of the above.

2. Session.createSQLQuery creates a new instance of Query for the given HQL query string.
A)true B) false

3. In which file database table configuration is stored?


A) .dbm B) .hbm
C) .ora D) .sql

4. Which of the following is not an advantage of using Hibernate Query Language?


A) Database independent

54
B) Easy to write query
C) No need to learn SQL
D) Difficult to implement

5. Which method is used to get a persistent instance from the datastore?

A) Session.read() B) Session.get()
C) Session.retrieve() D) Session.fetch()

Conclusion:

PRACTICAL - 10

Description:

Spring MVC Framework follows the Model-View-Controller design pattern. It is used to develop web
applications. It works around DispatcherServlet. DispatcherServlet handles all the HTTP requests and
responses. It dispatches the requests to handlers. It uses @Controller and @RequestMapping as default request
handlers. The @Controller annotation defines that a particular class is a controller. @RequestMapping
annotation maps web requests to Spring Controller methods. The terms model, view, and controller are as
follows:
Model: The Model encapsulates the application data.
View: View renders the model data and also generates HTML output that the client’s browser can interpret.
Controller: The Controller processes the user requests and passes them to the view for rendering.

Spring MVC Framework works as follows:


1. All the incoming requests are intercepted by the DispatcherServlet that works as the front
controller.
2. The DispatcherServlet then gets an entry of handler mapping from the XML file and forwards
the request to the controller.
3. The object of ModelAndView is returned by the controller.

55
4. The DispatcherServlet checks the entry of the view resolver in the XML file and invokes the
appropriate view component.
Advantages of Spring MVC Framework

● The container is used for the development and deployment of applications and uses a lightweight
servlet.
● It enables rapid and parallel development.

Disadvantages of Spring MVC Framework

● It has high complexity to develop the applications using this pattern.


● It is not suitable for small applications which affect the application’s performance and
design.

Aim:Write an application to keep record and retrieve record of student. The record includes student
id, enrolment number, semester, SPI. Use MVC architecture.

Code:

56
57
58
59
60
61
Output:

Post Practical Questions:


1. Beans can be created by which of the following properties?
A) Scope B) Property
C) Class D) It’s own constructor

2. A bean can have more than one name using multiple id attributes?

62
A)true B) false

3. Beans can be created by which of the following properties?


A) Static factory-method
B) Instance Factory-Method
C) All of the mentioned
D) None of the mentioned

Conclusion:

63

You might also like