Advanced Java Programming (1) 04-05-2019 Mail 6-5-19 PDF
Advanced Java Programming (1) 04-05-2019 Mail 6-5-19 PDF
Seal of
Institution
.
Advanced Java Programming (22517)
Preface
The primary focus of any engineering laboratory/field work in the technical education
system is to develop the much-needed industry relevant competencies and skills. With this in
view, MSBTE embarked on this innovative ‘I’ Scheme curricula for engineering Diploma
programmes with outcome-based education as the focus and accordingly, relatively large
amount of time is allotted for the practical work. This displays the great importance of
laboratory work making each teacher, instructor and student to realize that every minute of
the laboratory time need to be effectively utilized to develop these outcomes, rather than
doing other mundane activities. Therefore, for the successful implementation of this
outcome-based curriculum, every practical has been designed to serve as a ‘vehicle’ to
develop this industry identified competency in every student. The practical skills are difficult
to develop through ‘chalk and duster’ activity in the classroom situation. Accordingly, the ‘I’
scheme laboratory manual development team designed the practicals to focus on outcomes,
rather than the traditional age-old practice of conducting practical’s to ‘verify the theory’
(which may become a byproduct along the way).
This laboratory manual is designed to help all stakeholders, especially the students,
teachers and instructors to develop in the student the pre-determined outcomes. It is expected
from each student that at least a day in advance, they have to thoroughly read the concerned
practical procedure that they will do the next day and understand minimum theoretical
background associated with the practical. Every practical in this manual begins by identifying
the competency, industry relevant skills, course outcomes and practical outcomes which
serve as a key focal point for doing the practical. Students will then become aware about the
skills they will achieve through procedure shown there and necessary precautions to be taken,
which will help them to apply in solving real-world problems in their professional life.
This manual also provides guidelines to teachers and instructors to effectively facilitate
student-centered lab activities through each practical exercise by arranging and managing
necessary resources in order that the students follow the procedures and precautions
systematically ensuring the achievement of outcomes in the students.
Although all care has been taken to check for mistakes in this laboratory manual, yet it is
impossible to claim perfection especially as this is the first edition. Any such errors and
suggestions for improvement can be brought to our notice and are highly welcome.
Following programme outcomes are expected to be achieved significantly out of the ten
programme outcomes and Information Technology programme specific outcomes through the
practical’s of the course on Advanced Java Programming.
PO 3. Experiments and practice: Plan to perform experiments, practices and to use the
results to solve Computer Engineering related problems.
PO 5. The engineer and society: Assess societal, health, safety and legal issues and the
consequent responsibilities relevant to practice in the field of Computer Engineering.
PO 8. Individual and team work: Function effectively as a leader and team member in
diverse/ multidisciplinary teams.
PO 10. Life-long learning: Engage in independent and life-long learning along with the
technological changes in the IT and allied industry.
The following industry relevant skills of the competency “Apply advanced Java
Programming Concepts” are expected to be developed in you by performing practical’s of
this laboratory manual.
1. Create GUI Applications.
2. Handle events using event delegation model.
3. Write and execute programs for web based as well as window-based applications.
4. Write and execute programs for networking.
5. Write and execute programs to store the data in database to perform CRUD
operations.
6. Write and execute programs for client server using Servlets.
Student shall read the points given below for understanding the theoretical concepts and
practical applications.
1. Students shall listen carefully the lecture given by teacher about importance of
subject, learning structure, course outcomes.
2. Students shall organize the work in the group of two or three members and make a
record of all observations.
3. Students shall understand the purpose of experiment and its practical implementation.
4. Students shall write the answers of the questions during practical.
5. Student should feel free to discuss any difficulty faced during the conduct of practical.
6. Students shall develop web based and window-based applications as expected by the
industries.
7. Student shall attempt to develop related hands on skills and gain confidence.
8. Students shall refer technical magazines; websites related to the scope of the subjects
and update their knowledge and skills.
9. Students shall develop self-learning techniques.
10. Students should develop habit to submit the write-ups on the scheduled dates and
time.
Content Page
List of Practical’s and Progressive Assessment Sheet
Date of Dated
Sr. Page Date of Assessment Remarks
Title of the practical submissi sign. of
No. No. performance Marks (50) (if any)
on teacher
Write a program to
demonstrate the use of
AWT components like
1. Label, Textfield, 1
TextArea, Button,
Checkbox, RadioButton
etc.
Write a program to design
a form using the
2. 6
components List and
Choice.
Write a program to design
3. simple calculator with the 12
use of GridLayout
Write a program to create
a two-level card deck that
4. allows the user to select 19
component of Panel using
CardLayout
Write a program using
AWT to create a menu bar
where menu bar contains
5. menu items such as File, 25
Edit, View and create a
submenu under the File
menu: New and Open.
Write a program using
swing to display a
ScrollPane and
6. 31
JcomboBox in an Japplet
with the items – English,
Marathi, Hindi, Sanskrit.
Write a program to create
7. 37
a Jtree.
Write a program to create
8. 42
a JTable.
Write a program to
demonstrate the use of
19. 102
PreparedStatement and
ResultSet interface.
Write a program to update
20. and delete a record from a 110
database table.
Write a program to
demonstrate the use of
21. 116
HttpServlet as a
parameterized servlet
Write a Servlet program
to send username and
22. password using HTML 123
forms and authenticate the
user
Write a program to create
23. Session using HttpSession 130
class.
Write a program to
24. implement Session 137
tracking using Cookies.
Total Marks
Using applet window, design following AWT components using add() method of
components class. Following are some AWT components
To Create TextArea
TextArea ta=new TextArea(String str,int nooflines)
To create RadioButton(CheckBoxGroup):
CheckBox cb1, cb2;
CheckBoxGroup cbg;
Cb1=new CheckBox(“Male”,cbg,true);
Cb2=new CheckBox(“Female”,cbg,false);
Sr. Remarks
Name of Resource Broad Specification Quantity
No. (If any)
Computer (i3-i5
1 Computer System
preferable RAM > 2GB
As per
For All
2 Operating System Windows/Linux Batch
Experiments
Size
Development
3 JDK 1.5 Onwards
Software
Note: Below given are few sample questions for reference. Teacher must design
more such questions so as to ensure the achievement of identified CO.
1. State the difference between CheckBox and RadioButton
2. Write the use of setEnabled() method.
3. Draw the life cycle of an Applet.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise:
1. Develop a program using Label to display message “Welcome to Java”
2. Develop a program to select multiple languages known to user. (e. g Marathi,
Hindi, English, Sanskrit).
3. Write a program to create three Buttons with Caption OK, RESET and CANCEL.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Dated signature of
Marks Obtained
Teacher
List: Creates a list from which the user can choose list items.
Constructors:
List () // allows only one item to be selected
List (int numRows) // no of entries will always be visible
List (int numRows, Boolean multiple Select)// if it is true then user select
multiple items. If it is false then only one item may be selected
Choice
The Choice class is used to create a pop-up list of items from which the user
may choose. When the user clicks on it, the whole list of choices pops up and
new selection can be made. Choice defines the default constructor, which
creates an empty list. To add a selection to the list, call add ().
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
2
Figure 1
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Figure 2
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 9
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise:
1. Develop an applet/ application using List components to add names of 10 different
cities.
2. Develop applet / application to select multiple names of news papers
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
Layout Types
Understand the default layout for different containers such as Applet, Frame, Panel.
Grid Layout is used to make a bunch of components equal in size and displays them in the
requested number of rows and columns. One component is displayed in each rectangle.
The list of Constructor for GridLayout are:
1. GridLayout(): creates a grid layout with one column per component in a row.
2. GridLayout(int rows, int columns): creates a grid layout with the given rows and
columns but no gaps between the components.
3. GridLayout(int rows, int columns, int hgap, int vgap): creates a grid layout with
the given rows and columns along with given horizontal and vertical gaps if we
give setLayout(null) the default layout is disabled.then we have to use setBounds
method to layout the components.
Nil
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program to generate following output
Figure 3
Figure 4
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
2. public void previous (Container parent): is used to flip to the previous card of
the given container.
3. public void first (Container parent): is used to flip to the first card of the given
container.
4. public void last (Container parent): is used to flip to the last card of the given
container.
5. public void show (Container parent, String name): is used to flip to the
specified card with the given name.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write Java program to display following output.
Figure 5
Figure 6
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
To create a menu bar, first create an instance of Menu Bar. This class only defines the
default constructor. Next, create instances of Menu that will define the selections
displayed on the bar.
Menu( ) // creates an empty menu.
Menu(String optionName) // name of the menu selection
Menu(String optionName, boolean removable) // If removable is true, the
menu can be removed and allowed to float free. Otherwise, it will remain
attached to the menu bar.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
1. Write a program which creates Menu of different colors and disable menu item for
Black color.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Find errors in following program and display output as shown below.
import java.awt.*;
import java.awt.event.*;
public class MenuDemo1 extends Frame
{
MenuBar mb;
MenuItem m1,m2,m3,m4;
Menu mn;
MenuShortcut ms;
MenuDemo1()
{
setTitle("MenuBar Demo");
setSize(500,500);
setLayout(null);
ms=new MenuShortcut(KeyEvent.VK_X);
mn=new Menu("File");
mb=new MenuBar();
m1=new MenuItem("New...");
m2=new MenuItem("Open...");
m3=new MenuItem("Save As...");
m4=new MenuItem("Exit",ms);
Maharashtra state Board of Technical Education 28
Advanced Java Programming (22517)
mn.add(m1);
mn.add(m2);
mn.add(m3);
mn.addSeparator();
mn.add(m4);
mb.add(mn);
}
public static void main(String[] args)
{
MenuDemo1 md=new MenuDemo1();
md.setVisible(true);
}
}
Figure 7
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
The Swing Components are very useful to design interactive application and it
provide rich look and feel to the components. Swing components are light weight and
platform independent. Swing supplies additional controls such as TabbedPane,
ScrollPane, Trees and Tables. JFrame and JApplets are used to design windows and
web applications.
Constructors of JComboBox
1. JComboBox()
2. JComboBox(Vector v)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
Figure 8
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program to develop a frame to select the different states of India using
JComboBox
2. Develop a program to demonstrate the use of ScrollPane in Swings
(Space for answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 35
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process
Product Related(15) Total(50)
Related(35)
I. Practical Significance:
Tree is used to represent the hierarchical view of the data. The tree control shows the
data in tree like structure such as root and its leaves.
JTree(Hashtable ht) : The first form creates a tree in which each element of the hash
table ht is a child node.
TreeNode interface :It declares methods that obtain information about a tree node.
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
Figure 9
XI. Result (Output of Code):
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
Write a Jtree program to show root directory and its subFolders of your System.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 40
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
A table is a component that displays rows and columns of data. Students will be able
to use JTable class in Java which extends JComponent. The cursor can be dragged on
column boundaries to resize column.
2. Create a JScrollPane object. (The arguments to the constructor specify the table
and the policies for vertical and horizontal scroll bars.)
3. Add the table to the scroll pane.
4. Add the scroll pane to the content pane of the applet.
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
Figure 10
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a Java program to create a table of Name of Student, Percentage and Grade
of 10 students using JTable.
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 45
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 46
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
The JProgressBar class is used to display the progress of the task. Students will be
able to use JProgressBar to see the progress of the any task.
JProgressBar (int min, int max): It is used to create a horizontal progress bar with the
specified minimum and maximum value.
JProgressBar(int orient) : It is used to create a progress bar with the specified
orientation, it can be either Vertical or Horizontal by using
SwingConstants.VERTICAL and SwingConstants.HORIZONTAL constants.
JProgressBar(int orient, int min, int max) : It is used to create a progress bar with the
specified orientation, minimum and maximum value.
void setValue(int value) : It is used to set the current value on the progress bar.
Nil
IX. Resources used (Additional)
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
Figure 11
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop a program to demonstrate the use of JProgressBar.
2. Write a Program using JProgressBar to show the progress of Progressbar when
user clicks on JButton.
(Space for answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
A KeyEvent is generated when keyboard input occurs. When key is pressed, released
or typed, key event is generated. Students will be able to understand the method to
register an object and handle various key of Keyboards.
When key is pressed or released, first two events are generated. When character is
pressed, the last event occurs. All Keys do not generate character. E.g. Shift Key
The class which processes the KeyEvent should implement KeyListener interface.
The object of that class must be registered with a component. The object can be
registered using the addKeyListener () method.
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Elaborate the terms Event, Source and Listener.
2. List various methods of ActionListener interface.
3. Develop a program to accept two numbers and display product of two numbers
when user pressed “Multiply” button.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
The MouseListener and MouseMotionListener interface are used to implement the
different types of events that are created when the mouse is clicked, dragged, dropped,
released, entered and exited in a component.
These two interfaces lets the user to handle the events and perform some action in that
event.
In the similar way we can handle the events when mouse is moved or dragged. The
MouseMotion Interface defines the following methods.
1. void mouseDragged(MouseEvent me)
2. void mouseMoved(MouseEvent me)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program to change the background color of Applet when user performs
events using Mouse
2. Write a program to count the number of clicks performed by the user in a Frame
window
3. Write a program to demonstrate the use of mouseDragged and mouseMoved
method of MouseMotionListener
(Space for answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 61
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
A password is used to authenticate the user to gain the access to website application
or device. The TextField control is used to accept the input from user. An interface is
used to implement the methods as per the users requirements and achieve the concept
of multiple inheritance in java.
JPasswordField:
The JPasswordField allows the user to enter the input text in the form of password
characters. It inherits the JTextField class.
The JTextField: It allows the user to input the single line of text in JTextField component.
Only single line of text can be entered in the JTextField component of Swing control.
Constructor Description
JTextField Creates a new TextField initialized with the specified text and
(String text, columns.
int columns)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program using JPasswordField and JTextField to demonstrate the use of user
authentication
2. Write a program using JTextField to perform the addition of two numbers.
3. Write a program using JPasswordField to accept password from user and if the length is
less than 6 characters then error message should be displayed “Password length must be
>6 characters”
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 66
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 67
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
In listener interfaces implementation it is mandatory to implement all the methods
defined by the particular interface. To overcome this problem and to implement only
required methods java programming supports the concept of Adapter class. It lets the
user to implement only required methods.
This practical focuses on different types of Adapter classes and their practical
implementation.
Programmer need to give either empty implementation of the methods defined by the
WindowListener. To overcome this problem and to allow the user to implement only
required methods java provides a facility that is Adapter classes. Some of the Adapter
classes provided by the java language are listed below.
1. ComponentAdapter
2. ContainerAdapter
3. FocusAdapter
4. KeyAdapter
5. MouseAdapter
6. MouseMotionAdapter
7. WindowAdapter
These adapter classes allows the user to implement only required methods.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
import java.awt.*;
import java.awt.event.*;
public class WindowDemo
{
Frame f;
WindowDemo()
{
f=new Frame("Window Adapter");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
f.dispose();
}
};
f.setSize(400,400);
f.setLayout(null);
f.setVisible(false);
}
public static void main(String[] args)
{
new WindowDemo();
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program to demonstrate the use of WindowAdapter class
2. Write a program to demonstrate the use of anonymous inner class
3. Write a program using MouseMotionAdapter class to implement only one method
mouseDragged().
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 72
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 73
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com/java-adapter-classes
2. The complete reference Java 2 by Herbert schildt
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
import java.io.*;
import java.net.*;
public class InetDemo
{
public static void main(String[] args)
{
try
{
InetAddress ip=InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e){System.out.println(e);}
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop a program using InetAddress class to retrieve IP address of computer
when hostname is entered by the user.
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com/InetAddress-class
2. https://www.onlyjavatech.com/inetaddress-class-in-java
3. The complete reference Java 2 by Herbert Schildt
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
The Uniform resource locator in java allows the user to access the particular file or
resource which might be stored on any local or remote machine. The URL specifies
the complete path by which user can access file. It contains protocol address, port
number and location of the particular resource.
The URL and URLConnection classes are good enough for simple programs that want
to connect to HTTP servers to fetch content.
List of URL Class Methods and Constructors:
1. public URL (String protocol, String host, int port, String file) throws
MalformedURLException
2. public URL (String protocol, String host, String file) throws
MalformedURLException
3. public URL(String url) throws MalformedURLException
4. public URL(URL context, String url) throws MalformedURLException
Methods:
1. public String getPath()
2. public String getAuthority()
3. public String getHost()
4. public String getFile()
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program using URL class to retrieve the host, protocol, port and file of
URL http://www.msbte.org.in
2. Write a program using URL and URLConnection class to retrieve the date,
content type, content length information of any entered URL
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 83
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
Java provides the socket programming approach for communication between the
client and server. A user can write the code for both client and server as well for UDP
& TCP datagram packets. By using java’s network communication feature we can
create interactive application to communicate within a network.
The java.net.Socket class is used to communicate between client and server.The client
can obtain object by creating its instance whereas the server obtains a Socket object
from the return value of the accept() method.
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program using Socket and ServerSocket to create Chat Application
2. Write a program to develop prime number Server (Client will send any number to
server, Sever will send the response the number is prime or not)
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)
I. Practical Significance:
The User Datagram Protocol (UDP) is connectionless, and unreliable protocol by
which the user can send short messages called datagrams. The java provides
DatagramSocket and DatagramPacket class to implement the concept of user
datagram protocol. By using these classes we can transfer the data asynchronous
manner.
The Java DatagramSocket class is used to send and receive the datagrams it is
connection less socket. That is there is no guarantee of message delivery.
It has following constructors
1. DatagramSocket()
2. DatagramSocket(int port)
3. DatagramSocket(int port, InetAddress address)
The Java DatagramPacket is class that can be used to send the packets. If you send
multiple packet, it may arrive in any order. Additionally, packet delivery is not
guaranteed.
It has following constructors
1. DatagramPacket(byte[] barr, int length)
2. DatagramPacket(byte[] barr, int length, InetAddress address, int port)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1
import java.net.*;
public class DGramSender
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds = new DatagramSocket();
String str = "Java is Easy!!!!!";
InetAddress ip = InetAddress.getByName("127.0.0.1");
DatagramPacket dp = new DatagramPacket(str.getBytes(), str.length(),
ip, 3000);
ds.send(dp);
ds.close();
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Write a program using DatagramPacket and DatagramSocket to create chat
application
2. Write a program using DatagramPacket and DataGramSocket to copy the contents
of one file into other
3. Write a program using DatagramPacket and DatagramSocket to transfer the file
from one location to another.
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com/DatagramSocket-and-DatagramPacket
2. The complete reference Java 2 by Herbert Schildt
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process
Product Related(15) Total(50)
Related(35)
Practical No. 18: Write a program to insert and retrieve data from
database using JDBC.
I. Practical Significance:
ODBC isn't appropriate for direct use from the Java programming language because it
uses a C interface. The JDBC API was modeled after ODBC, but, because JDBC is a
Java API, it offers a natural Java interface for working with SQL. JDBC is needed to
provide a "pure Java" solution for application development.
Figure 12
Some of the current JDK add more features to JDBC that is embedded SQL which
makes direct mapping of relational databases to java classes. Embedded SQL enables
mixing of java into a SQL statement These statements are translated into JDBC calls
using SQL processor. In this type of direct mapping, each row of the table becomes
an instance of class and each column value corresponds to an attribute of that
instance.
JDBC DRIVERS:-
1. JDBC-ODBC Bridge: -.
2. Native-API: - partly java Driver: -
3. JDBC-Network pure java driver:
4. Native_protocol (100%) pure Java drivers: -
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1 MS-Access MS-Office 2010
import java.sql*;
class JdbcDemo
public static void main (String args[])
{
try
{
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
System.out. println(" Driver loaded");
String url= "jdbc:odbc:MSBTE";
Connection cn= DriverManager.getConnection(url);
System.out.println("Connection to the database created");
Statement st= cn.createStatement();
String str= "select* from student";
ResultSet rs=st.executeQuery(str);
String text=" ";
System.out.println("Roll Number \t Name");
while(rs.next())
{
text= text+rs.getInt(1)+"\t"+rs.getString(2)+"\n";
}
System.out.print(text);
St.close();
cn.close();
}
catch (SQLExccpt.ion s)
{System.out.println("sql error");}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop a program to create employee table in database having two columns
“emp_id” and “emp_name”.
2. Develop a program to display the name and roll_no of students from “student
table” having percentage > 70.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. ftp://ftp.icm.edu.pl/packages/javasoft-docs/jdk1.1/jdbc.pdf
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process
Product Related(15) Total(50)
Related(35)
have to use String Concatenation to create the query. If there are multiple parameters
to set, writing Query using String concatenation looks very ugly and error prone.
PreparedStatement returns FORWARD_ONLY ResultSet, so we can only move in
forward direction. Unlike Java Arrays or List, the indexing of PreparedStatement
variables starts with 1.
One of the limitation of PreparedStatement is that we can’t use it for SQL queries
with IN clause because PreparedStatement doesn’t allow us to bind multiple values
for single placeholder (?).
ResultSet Interface
The SQL statements that read data from a database query, return the data in a result
set. The SELECT statement is the standard way to select rows from a database and
view them in a result set. The java.sql.ResultSet interface represents the result set of a
database query.
A ResultSet object maintains a cursor that points to the current row in the result set.
The term "result set" refers to the row and column data contained in a ResultSet
object.
The methods of the ResultSet interface can be broken down into three categories −
Navigational methods: Used to move the cursor around.
Get methods: Used to view the data in the columns of the current row being
pointed by the cursor.
Update methods: Used to update the data in the columns of the current row. The
updates can then be updated in the underlying database as well.
is movable based on the properties of the ResultSet. These properties are designated
when the corresponding Statement The cursor that generates the ResultSet is created.
JDBC provides the following connection methods to create statements with desired
ResultSet −
createStatement(int RSType, int RSConcurrency);
prepareStatement(String SQL, int RSType, int RSConcurrency);
prepareCall(String sql, int RSType, int RSConcurrency);
The methods of the ResultSet interface can be broken down into three categories −
Navigational methods: Used to move the cursor around.
Get methods: Used to view the data in the columns of the current row being
pointed by the cursor.
Update methods: Used to update the data in the columns of the current row. The
updates can then be updated in the underlying database as well.
JDBC provides the following connection methods to create statements with desired
ResultSet −
createStatement(int RSType, int RSConcurrency);
prepareStatement(String SQL, int RSType, int RSConcurrency);
prepareCall(String sql, int RSType, int RSConcurrency);
The first argument indicates the type of a ResultSet object and the second argument is
one of two ResultSet constants for specifying whether a result set is read-only or
updatable.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
1 MySql Server 5.5
2 JDK 1.6
1. Write a Program to update row of student table from MSBTE database using
Mysql 5.5 a database server.
2. Write the output of following JDBC code. Use Mysql server 5.5 as database
server
import java.sql
public class PreparedStmtEx
{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:33
06/YourDBname","DBuserna me","DBpassword");
//keep “” empty if not given during installation
PreparedStatement stmt=con.prepareStatement("insert into
student values(?,?,?)");
stmt.setInt(1,101);
//1 specifies the first parameter(1st ? symbol) in the query
stmt.setString(2,"Abhishek");
//2 specifies the second parameter(2nd ? symbol) in the query
stmt.setString(3,"Yadav");
//3 specifies the third parameter(3rd ? symbol) in the query
int i=stmt.executeUpdate();
System.out.println(i+" records inserted");
con.close();
}
catch(Exception e)
{
System.out.println(e);}
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop JDBC program to retrieve data using ResultSet
2. Develop a program to update a record in database table
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
Maharashtra state Board of Technical Education 108
Advanced Java Programming (22517)
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. JDBC Developer's Resource by Art Taylor JDBC Developer's Resource by Art
Taylor
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)
SET statement is used to set new values to the particular column and
the WHERE clause is used to select the rows for which the columns are needed to be
updated. If we have not used the WHERE clause then
DELETE Syntax
DELETE FROM table_name WHERE condition;
the columns in all the rows will be updated.
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
Mysql Database
1 5.5
server
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class UpdateQuery
{
public static void main(String [] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:33
06/Ddemodatabase","root","root");
PreparedStatement st = con
.prepareStatement("update student set roll_no=3 where
name='Abhishek'");
st.executeUpdate();
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 113
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop a program to update name of a student from Jack to John.
2. Develop a program to delete all record for a product whose "price is greater than
500" and Id is "P1234".
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert Schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process
Product Related(15) Total(50)
Related(35)
I. Practical Significance:
Servlets are the Java programs that run on the Java-enabled web server or application
server. They are used to handle the request obtained from the web server, process the
request, produce the response, and then send response back to the web server.
3. Start Tomcat.
To start Tomcat, select Start Tomcat in the Start | Programs menu, or run
startup.bat
from the C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
Web Server Apache Tomcat 8.0 with
1
Software JRE.
Figure 12
2. Write the output of following code considering below HTML is front end and
servlet as back end
<html>
<body>
<center>
<form name="Form1" method="post"
action="http://localhost:8080/examples/servlet/PostParametersServlet">
<table>
<tr>
<td><B>Employee</td>
<td><input type=textbox name="e" size="25" value=""></td>
</tr>
<tr>
<td><B>Phone</td>
<td><input type=textbox name="p" size="25" value=""></td>
</tr>
</table>
<input type=submit value="Submit">
</body>
</html>
import java.io.*;
import java.util.*;
import javax.servlet.*;
PrintWriter pw = response.getWriter();
// Get enumeration of parameter names.
Enumeration e = request.getParameterNames();
// Display parameter names and values.
while(e.hasMoreElements())
{
String pname = (String)e.nextElement();
pw.print(pname + " = ");
String pvalue = request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop servlet program to print Hello MSBTE in browser window.
2. Develop a program to receive the parameter through HTML forms and send back
received parameter to browser.
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert Schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process
Product Related(15) Total(50)
Related(35)
Nil
Sr. Name of
Broad Specification Quantity Remarks (If any)
No. Resource
Web Server Apache Tomcat 8.0
1
Software with JRE.
1. Write a Program to send the username to server and server will send the length of
username to client.
2. Write the output of following code cosidering below HTML is front end and
servlet as back end
loginpage.html
<html>
<body>
<form action="
http://localhost:8080/examples/servlets/servlet/AthonticationServlet”
method=”POST”>
User Name:<input type="text" name="username"><br>
Password:<input type="password" name="password" ><br>
<input type="submit">
</form>
</body>
</html>
//AthonticationServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop servlet program to retrieve data from List and Radio Button using HTML
Forms.
2. Develop a program to receive student subject marks through HTML forms
TextField and send the response as passed or Failed in Examination...
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 127
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 128
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process
Product Related(15) Total(50)
Related(35)
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
Web Server Apache Tomcat 8.0
1
Software with JRE.
<html>
<body>
<form action="
http://localhost:8080/examples/servlet/SessionServlet">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
</body>
</html>
//SessionServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
HttpSession session=request.getSession();
session.setAttribute("uname",n);
out.print("<a href='servlet2'>visit</a>");
out.close();
}
catch (Exception e) {System.out.println(e);}
}
}
(Space for Answer)
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop servlet program to display various details about session using
HttpSession methods.
2. Develop a program to display last accessed time of session. And Expire the
session with specified time
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 134
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 135
Advanced Java Programming (22517)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process
Product Related(15) Total(50)
Related(35)
Cookies
A webserver can assign a unique session ID as a cookie to each web client and for
subsequent requests from the client they can be recognized using the received cookie.
This may not be an effective way because many time browser does not support a
cookie, so I would not recommend to use this procedure to maintain the sessions.
URL Rewriting
You can append some extra data on the end of each URL that identifies the session,
and the server can associate that session identifier with data it has stored about that
session.
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 sign-out.
Nil
Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
Web Server Apache Tomcat 8.0 with
1
Software JRE.
index.html
<form action=" http://localhost:8080/examples/servlet /servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
//FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
try
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}
catch(Exception e){System.out.println(e);}
}
}
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Maharashtra state Board of Technical Education 140
Advanced Java Programming (22517)
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIII. Exercise
1. Develop a program to collect user information using cookie.
2. Develop program to get the browser Information.
(Space for Answer)
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert schildt
4. https://tomcat.apache.org/download-80.cgi
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(15)