0% found this document useful (0 votes)
9 views

Java Journal

The document outlines a series of Java programming experiments focusing on various concepts such as interfaces, exception handling, servlets, JSP, cookies, and database connectivity using JDBC. Each experiment includes objectives, theoretical background, and a structure for implementation, along with assessment criteria. The experiments aim to enhance understanding of Java application development and web technologies.

Uploaded by

white Devil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java Journal

The document outlines a series of Java programming experiments focusing on various concepts such as interfaces, exception handling, servlets, JSP, cookies, and database connectivity using JDBC. Each experiment includes objectives, theoretical background, and a structure for implementation, along with assessment criteria. The experiments aim to enhance understanding of Java application development and web technologies.

Uploaded by

white Devil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Experiment No.

: 01 Date:
Experiment Title: Write a Java program to implement fixed and dynamic stack using interface.
Objectives: To demonstrate the benefits/ applications of using interface in Java program.
Software’s used:

About Experiment (Theory max. 500 words):

The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the
Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java. Using
the keyword interface, you can fully abstract a class’ interface from its implementation. That is, using
interface, you can specify what a class must do, but not how it does it. Interfaces are syntactically similar
to classes, but they lack instance variables, and their methods are declared without any body.
To implement an interface, a class must create the complete set of methods defined by the
interface. Interfaces are designed to support dynamic method resolution at run time. Normally, in order
for a method to be called from one class to another, both classes need to be present at compile time so the
Java compiler can check to ensure that the method signatures are compatible.

Syntax
access interface name
{
return-type method-name1(parameter-list);
return-type method-name2(parameter-list);
type final-varname1 = value;
type final-varname2 = value;
return-type method-nameN(parameter-list);
type final-varnameN = value;
}
The general form of a class that includes the implements clause looks like this:
class classname [extends superclass] [implements interface [,interface...]]
{
// class-body
}

In the given experiment Interface is created and two classes namely fixed stack and dynamic stack are
going to implement the methods of interface.
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO1

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 02 Date:
Experiment Title: Write a Java program to demonstrate Exception handling for any 3 types of
exceptions.
Objectives: To demonstrate the handling of runtime errors, also to understand different types of
exceptions and keywords to handle the exceptions so that applications work with more reliable.
Software’s used:

About Experiment (Theory max. 500 words):

An exception is an abnormal condition that arises in a code sequence at run time. In other words, an
exception is a runtime error.
Java exception handling is managed via five keywords: try, catch, throw, throws, and finally.
All exception types are subclasses of the built-in class Throw able. Thus, Throw able is at the top of the
exception class hierarchy. Immediately below Throw able are two subclasses that partition exceptions
into two distinct branches. One branch is headed by Exception. This class is used for exceptional
conditions that user programs should catch. This is also the class that you will subclass to create your own
custom exception types. There is an important subclass of Exception, called Runtime Exception.
Exceptions of this type are automatically defined for the programs that you write and include things such
as division by zero and invalid array indexing.

This is the general form of an exception-handling block:


try
{
// block of code to monitor for errors
}
catch
(ExceptionType1 exOb)
{
// exception handler for ExceptionType1
}
catch (ExceptionType2 exOb)
{
// exception handler for ExceptionType2
} // ...
finally
{
// block of code to be executed after try block ends
}
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO2

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 03 (A) Date:
Experiment Title: Write a Java Servlet program to implement a dynamic HTML using Servlet (user
name and Password should be accepted using HTML and displayed using a Servlet). (Client request).

Objectives: To demonstrate the concept of client and server model using servlet and also to read the
form data in different ways which is been sent by the client.
Software’s used:

About Experiment (Theory max. 500 words):

Servlets are programs that run on a Web or application server and act as a middle layer between a requests
coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
Job/Role of Servlets.
 Read the explicit data sent by the client
 Read the explicit data sent by the client
 Generate the results.
 Send the explicit data (i.e., the document) to the client.
 Send the implicit HTTP response data.

 Basic Structure of Servlet

import java.io. *;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletTemplate extends HttpServlet
{public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{// Use "request" to read incoming HTTP headers //
PrintWriter out = response.getWriter();
// Use "out" to send content to browser.}}
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 03 (B) Date:
Experiment Title: Write a Java JSP program to implement verification of a particular user login and
display a Welcome page.
Objectives: To demonstrate the use of scripting tags in JSP.
Software’s used:

About Experiment (Theory max. 500 words):

Java Sever Pages are used to validate the user credentials. 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.
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 4 Date:
Experiment Title: Write a Java JSP program which uses JSP: include and JSP: forward action to display
a Webpage.

Objectives: To demonstrate the action tags for handling the client request using multiple pages in an
application.
Software’s used:

About Experiment (Theory max. 500 words):

JSP Action Tags: There are many JSP action tags or 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:forward: forwards the request and response to another resource.

Syntax of jsp:forward action tag with parameter

1. <jsp:forward page="relativeURL | <%= expression %>">


2. <jsp:param name="parametername" value="parametervalue | <%=expression%>" />
3. </jsp:forward>

 jsp:include: The jsp:include action tag is used to include the content of another resource it may
be jsp, html or servlet.

Syntax of jsp:include action tag with parameter

1. <jsp:include page="relativeURL | <%= expression %>">


2. <jsp:param name="parametername" value="parametervalue | <%=expression%>" />
3. </jsp:include>
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 5 Date:
Experiment Title: Write a JSP program to implement all the attributes of page directive tag.
Objectives: To demonstrate the attributes of page directive tags in application development.
Software’s used:

About Experiment (Theory max. 500 words):

A JSP directive affects the overall structure of the servlet that results from the JSP page
In JSP, there are three main types of directives: page, include, and taglib. A page directive can be placed
anywhere within the document;

The second directive, include, lets you insert a file into the JSP page at the time the JSP file is translated
into a servlet An include directive should be placed in the document at the point at which you want the
file to be inserted; The third directive, taglib, defines custom markup tags;

Attributes of page directive tag:

 Info
 Language
 Session
 Error page
 Is error page
 Content type
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 6 Date:
Experiment Title: Write a Java JSP program to get student information through a HTML and create a
JAVA Bean class, populate Bean and display the same information through another JSP.
Objectives: To demonstrate Java application development using core Java beans.
Software’s used:

About Experiment (Theory max. 500 words):

JavaBean

A JavaBean is a Java class that should follow the following conventions:

o It should have a no-argument constructor.


o It should be Serializable.
o It should provide methods to set and get the values of the properties, known as getter and setter
methods.

JavaBean Properties:

A JavaBean property is a named feature that can be accessed by the user of the object. The feature can be
of any Java data type, containing the classes that you define.

A JavaBean property may be read, write, read-only, or write-only. JavaBean features are accessed through
two methods in the JavaBean's implementation class:

1. getPropertyName ()

For example, if the property name is firstName, the method name would be getFirstName() to read that
property. This method is called the accessor.

2. setPropertyName ()

For example, if the property name is firstName, the method name would be setFirstName() to write that
property. This method is called the mutator.

Syntax:

<jsp:useBean id="stud" class="mypack.Student" scope="page">

</jsp:useBean>

useBean tag which is a built in tag from JSP to read, write and to populate the Bean class which
encapsulates many objects in only one single object.
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 7 Date:
Experiment Title: Write a Java program to remember user preferences using cookies.
Objectives: To demonstrate the usage of cookies.

Software’s used:

About Experiment (Theory max. 500 words):

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.

Types of Cookie: There are 2 types of cookies in servlets.


1. Non-persistent cookie: It is valid for single session only. It is removed each time when user closes
the browser.
2. 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 sign-out.

Cookie class

javax.servlet.http.Cookie class provides the functionality of using cookies. It provides a lot of useful
methods for cookies.

Constructor of Cookie class

Constructor Description

Cookie() constructs a cookie.

Cookie(String name, String value) constructs a cookie with a specified name and value.
Useful Methods of Cookie class

There are given some commonly used methods of the Cookie class.

Method Description

public void setMaxAge(int expiry) Sets the maximum age of the cookie in seconds.

public String getName() Returns the name of the cookie. The name cannot be changed
after creation.

public String getValue() Returns the value of the cookie.

public void setName(String name) changes the name of the cookie.

public void setValue(String value) changes the value of the cookie.


Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO3

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature


Experiment No.: 8 Date:
Experiment Title: Write a Java program to insert data into Student DATA BASE and retrieve info based
on particular queries (For example update, delete, search etc…).
Objectives: To demonstrate the usage of databases (Storing, retrieving and performing operations on
database).

Software’s used:

About Experiment (Theory max. 500 words):

JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the query
with the database. It is a part of Java SE (Java Standard Edition). JDBC API uses JDBC drivers to
connect with the database. There are four types of JDBC drivers:
o JDBC-ODBC Bridge Driver,
o Native Driver,
o Network Protocol Driver, and
o Thin Driver

1) Create Core Java Application and Simple Java Class.

Steps to add JDBC Connector


1) Right click on Project created Go to Properties LibrariesClick on Add/JAR/Folder.
2) In opened Window Go to C-Drive Program Files NetBeans Folder IDE
modulesext select mysql connector click on Open OK.
For easy access (Copy and paste the connector on Desktop).

Steps to Create Database Using MySQL in NetBeans


1) Go to Services window on the NetBeans Select Databases Right Click on MySQL Server at
localhost: 3306(Currently would be in disconnected state).
2) Right click on the same and say  Connect by entering the valid username and password
which were set during the installation.
3) Once connection is established then click on Create Database and mention the proper database
name.
Algorithm/Procedure:

Result:

Learning Conclusion:

Course Outcome Attained: CO4

Marks Alloted:
Activity Marks
1. Conduction & Execution (Max Marks: 5)
2. Viva for the Experiment (Max Marks: 5)
3. Lab record Writeup (Max Marks: 5)
Total

Date: Faculty Signature

You might also like