Professional Documents
Culture Documents
Mandal’s
DEGREE COLLEGE OF PHYSICAL EDUCATION, AMRAVATI (M. S.)
CERTIFICATE
This is to certify that,Shri./Kumari.Pranay Sahare
Practical
Name of Practical Date Remark
No.
WAP in JDBC to create table with name student that
1 contains the fields(Sid int, Snamevarchar(20),Marks int). 28/08/2020
WAP in JDBC to display student information from student
2 12/09/2020
table.
WAP for AWT where we are inheriting Frame class and
3 25/09/2020
showing Button component on the Frame.
4 WAP for AWT panel. 09/10/2020
5 WAP for AWT to demonstrates working with Label. 31/10/2020
WAP for AWT to calculate factorial of a number using
6 06/11/2020
controls and events.
WAP for AWT to display whether the given number is
7 28/11/2020
prime or not using controls and events.
WAP for AWT to design mathematical model using controls
8 04/12/2020
and events
WAP for AWT to design Login window using Controls like
9 12/12/2020
Button, Label &TextField
WAP to create a Frame with two Buttons having name
10 “Welcome” & “HVPM” with respective CommandButton1 18/12/2020
and CommandButton2.
11 WAP for Servlet to print simple message. 26/12/2020
WAP for Servlet which accept student name, marks &
12 02/01/2021
display Result of a student.
WAP for Servlet that receives username & password from
13 html ,check its validity from login table & display 09/01/2021
appropriate message.
14 WAP for JSP to display current date of system. 15/01/2021
15 WAP for JSP to demonstrate the try and catch block. 22/01/2021
WAP for Swing to display tree structure of hvpm college
16 with department of BCA, BSc, BBA, MCA and MSc with 30/01/2021
respect to corresponding years.
17 WAP for Swing to create a Login Screen. 05/02/2021
WAP for Swing to display IP address of corresponding
18 06/02/2021
website that we enter.
WAP for Swing to create checkbox for BCA-III (Sem-I)
19 12/02/2021
Subjects.
WAP for Swing to demonstrate typical editable table these
20 table describing employee details containing EMP_ID, 13/02/2021
Name, Salary, Dept, DOB, DOJ, Location.
Practical No.1
/**JDBCprogramtocreatetablewithnamestudentthatcontainsthefieldsSidint,Snamevarchar(20),Marks int*/
packagectable;
import java.sql.*;
public class Ctable
{
public static void main(String[] args)
{
try
{
System.out.println("Welcome to JDBC");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/college","root","root");
System.out.println("you are connected to Database");
Statement st=con.createStatement();
System.out.println("Table is Ready");
con.close();
}
catch(Exception e)
}
}
***** OUTPUT *****
Practical No.2
importjava.sql.*;
public class Pract3 {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/college","root","root");
Statement st=con.createStatement();
while(rs.next()){
int Sid=rs.getInt(1);
String Sname=rs.getString(2);
int Marks=rs.getInt(3);
System.out.println(" ");
System.out.println("Student Information");
System.out.println("StudentName:"+Sname);
System.out.println("Student ID:"+Sid);
System.out.println("Marks:"+Marks);
}}
catch(Exception e){}
}
}
***** OUTPUT *****
Practical No.3
Aim:-To write a program for AWT to inherit frame class and show button on frame
/**To write a program to show inheritance using frame class and show button on frame*/
import java.awt.*;
classFirst extends Frame
{
First()
{
Button b=new Button("click me");
b.setBounds(30,100,80,30);
add(b);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public static void main(String args[]){
First f=new First();
}
}
Output:-
import java.awt.*;
public class PanelExample
{
PanelExample()
{
Frame f=new Frame("Panel Example");
Panel panel=new Panel();
panel.setBounds(40,80,200,200);
panel.setBackground(Color.yellow);
Button b_1=new Button("Button_1");
b_1.setBounds(50,100,80,30);
b_1.setBackground(Color.red);
Button b_2=new Button("Button_2");
b_2.setBounds(100,100,80,30);
b_2.setBackground(Color.blue);
panel.add(b_1);
panel.add(b_2);
f.add(panel);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
newPanelExample();
}
}
Output:-
E:\advance java\javac panelexample.java
E:\advance java\java panelexample
Practical No.5
importjava.awt.*;
class LabelExample{
public static void main(String args[]){
Frame f= new Frame("Label Example");
Label l1,l2;
l1=new Label("First Label.");
l1.setBackground(Color.BLUE);
l1.setBounds(50,100, 100,30);
l2=new Label("Second Label.");
l2.setBackground(Color.RED);
l2.setBounds(50,150, 100,30);
f.add(l1); f.add(l2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Output:-
E:\advance java\label_java.java
E:\advance java\label_java
Practical No.6
Output:-
Enter Number:
Factorialis: 120a
Practical No.7
/**Program for java AWT to check if no is prime or not using controls and events*/
import java.awt.*;
importjava.awt.event.*;
classPrime extends Frame implements ActionListener
{
TextFieldtf1,tf2;
public Prime()
{
setLayout(new FlowLayout());
Label lb1=new Label("Enter Number:");
Label lb2=new Label("Check if no isprime:");
tf1=newTextField(15);
tf2=newTextField(15);
Button btn1=new Button("Calculate");
add(lb1);
add(tf1);
add(lb2);
add(tf2);
add(btn1);
btn1.addActionListener(this);
}
public static void main(String arg[])
{
Prime fr=new Prime();
fr.setSize(150,300);
fr.setTitle("Calculate Factorial");
fr.setVisible(true);
}
publicvoid actionPerformed(ActionEventae)
{
intn;
n= Integer.parseInt(tf1.getText());
booleanflag = false;
for(inti = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
flag= true;
break;
}
}
if(!flag)
{
tf2.setText(" is a prime number.");
}
else
tf2.setText("is not a prime number");
}
}
Output:-
/**Program using java AWT to crate a mathematical model using events and controls*/
import java.awt.*;
importjavax.swing.*;
import java.awt.event.*;
class SimpleCalculate
{ public static void main(String[]args)
{
JFramef=newJFrame();
f.setLayout(null);
JLabellab1=new JLabel("Enter Number 1: ");
JLabellab2=new JLabel("Enter Number 2: ");
JLabellab3=new JLabel("Result: ");
finalJTextFieldtext1=new JTextField(20);
final JTextFieldtext2=new JTextField(20);
final JTextFieldtext3=new JTextField(20);
JButtonb1=new JButton("Add");
JButtonb2=new JButton("Subtract");
JButtonb3=new JButton("Multiply");
JButtonb4=new JButton("Division");
lab1.setBounds(20,20,100,20);
text1.setBounds(140,20,100,20);
lab2.setBounds(20,50,100,20);
text2.setBounds(140,50,100,20);
lab3.setBounds(20,80,100,20);
text3.setBounds(140,80,100,20);
b1.setBounds(260,80,80,20);
b2.setBounds(360,80,80,20);
b3.setBounds(460,80,80,20);
b4.setBounds(560,80,80,20);
b1.addActionListener(newActionListener(){
publicvoid actionPerformed(ActionEventae){
intn1=Integer.parseInt(text1.getText());
intn2=Integer.parseInt(text2.getText());
intcal=n1+n2;
text3.setText(Integer.toString(cal));
}
});
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEventae){
intn1=Integer.parseInt(text1.getText());
intn2=Integer.parseInt(text2.getText());
intcal=0;
if(n1>n2){
cal=n1-n2;
}
else if(n2>n1){
cal=n2-n1;
}
text3.setText(Integer.toString(cal));
}
});
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEventae){
intn1=Integer.parseInt(text1.getText());
intn2=Integer.parseInt(text2.getText());
intcal=n1*n2;
text3.setText(Integer.toString(cal));
}
});
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEventae){
intn1=Integer.parseInt(text1.getText());
intn2=Integer.parseInt(text2.getText());
intcal=0;
if(n1>n2){
cal=n1/n2;
}
else if(n2>n1){
cal=n2/n1;
}
text3.setText(Integer.toString(cal));
}
});
f.add(lab1);
f.add(text1);
f.add(lab2);
f.add(text2);
f.add(lab3);
f.add(text3);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);f.setVisible(true)
;f.setSize(700,250);
}
}
output:-
EnterNumber2: 20a
Enter Number 1:
EnterNumber2: 20a
EnterNumber2: 20a
EnterNumber1! 10a
EnterPlumber2: 20a
Result:
Practical No.9
/**Program in java AWT to create a login window using control and events*/
import java.awt.event.*;
importjava.awt.*;
classTest implements ActionListener{
Button b1;
TextFieldt1, t2;
Label lb1, lb2, lb3;
Frame f;
Test() {
f = new Frame("Awt Login Window");
lb1 = new Label("Enter ID :");
lb1.setBounds(5, 50, 150, 30);
f.add(lb1);
t1 = new TextField();
t1.setBounds(200, 50, 150,30);
f.add(t1);
t2 = new TextField();
t2.setBounds(200, 80, 150,30);
f.add(t2);
lb2 = new Label("Enter Password:");
lb2.setBounds(5, 80, 150, 30);
f.add(lb2);
lb3 = new Label("Result :");
lb3.setBounds(90, 140, 150,30);
f.add(lb3);
b1 = new Button("Login");
b1.setBounds(90, 200, 100, 30);
f.add(b1);
b1.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEventwe) {
System.exit(0);
}
});
f.setLayout(null);
f.setSize(600, 500);
f.setVisible(true);
}
publicvoid actionPerformed(ActionEvente) {
intc = 0;
if(e.getSource().equals(b1)) {
if(t1.getText().equals("Neha Tiwari") &&(t2.getText().equals("Neha@12345"))) {
lb3.setText(String.valueOf("Success login!"));
} else {
lb3.setText(String.valueOf("Invalid login!"));
}
}
}
public static void main(String args[]) {
Test t = new Test();
}
}
Output:-
//*Java AWT program to create two buttons with DCPE and HVPM labels*/
import java.awt.*;
classButtonExample{
public static void main(String[] args) {
Frame f=new Frame("Button Example");
Button b=new Button("DCPE");
Button b1=new Button("HVPM");
b.setBounds(50,100,80,30);
b1.setBounds(150,100,80,30);
f.add(b);
f.add(b1);f.setSize(40
0,400);f.setLayout(nu
ll);f.setVisible(true);
}
}
Output:-
E:\advance java\ javac button.java
E:\ advance java\ java button.java
Practical No.11
/*Java servlet program to accept student name, marks and display the
HTML CODE
<html>
<head><title>Result</title></head>
<body>
<center><form method="post" action="CheckMarks">
<table>
<tr><td>Enter Student Name <td>
<input type="text" name="snm"></tr>
<tr><td>Enter Marks <td>
<input type="text" name="mks"></tr>
<tr><td><input type="submit" value="Submit"></tr>
</table></form></center></body></html>
Output:-
Enter Student NameSachin
EnterMarks 56
Submit
/*Program in Java Servlet to receive username and password and check it’s validity
from a login table & display appropriate message.*/
importjava.io.IOException;
import java.io.PrintWriter;
importjavax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
String n=request.getParameter("username");
String p=request.getParameter("userpass");
if(LoginDao.validate(n, p))
{
RequestDispatcherrd=request.getRequestDispatcher("servlet2");
rd.forward(request,response);
}
else
{
out.print("Sorry username or password error");
RequestDispatcherrd=request.getRequestDispatcher("index.html");
rd.include(request,response);
}
out.close();
}
}
LoginDao.java
importjava.sql.*;
public class LoginDao
{
public static boolean validate(String name,String pass)
{
boolean status=false;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","local","test");
PreparedStatementps=con.prepareStatement(
"select * from userreg where name=? and pass=?");
ps.setString(1,name);
ps.setString(2,pass);
ResultSetrs=ps.executeQuery();
status=rs.next();
}
catch(Exception e)
{
System.out.println(e);
}
return status;
}
}
importjava.io.IOException;
import java.io.PrintWriter;
importjavax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Output:-
User Name;rahuld
Password
/Submit
<html>
<head>
</head>
<body>
<center>
</center>
<%
%>
</body>
</html>
Output:
-
Practical No.15
Errorpage.jsp
<%@ page isErrorPage="true" %>
<html>
<head>
<title>Display the Exception Message here</title>
</head>
<body>
<h2>errorpage.jsp</h2>
<i>An exception has occurred in the index.jsp Page.
Please fix the errors. Below is the error message:</i>
<b><%= exception %></b>
</body>
</html>
Output:-
Practical No.16
/*To write a swing program to display tree structure of HVPM with department of BCA,
BSc, BBA, MCA and MSc with respect to corresponding to years*/
importjavax.swing.*;
importjavax.swing.tree.DefaultMutableTreeNode;
public class TreeExample
{
JFrame f;
TreeExample()
{
f=new JFrame();
DefaultMutableTreeNodehvpm=new DefaultMutableTreeNode("HVPM DCPE,Amravati");
DefaultMutableTreeNodeug=new DefaultMutableTreeNode("UG");
DefaultMutableTreeNodepg=new DefaultMutableTreeNode("PG");
hvpm.add(ug);
hvpm.add(pg);
DefaultMutableTreeNodebca=new DefaultMutableTreeNode("BCA");
DefaultMutableTreeNodebsc=new DefaultMutableTreeNode("BSC");
DefaultMutableTreeNodebba=new DefaultMutableTreeNode("BBA");
ug.add(bca);
ug.add(bsc);
ug.add(bba);
DefaultMutableTreeNodebsci=new DefaultMutableTreeNode("BSC-I");
DefaultMutableTreeNodebscii=new DefaultMutableTreeNode("BSC-II");
DefaultMutableTreeNodebsciii=new DefaultMutableTreeNode("BSC-III");
bsc.add(bsci);
bsc.add(bscii);
bsc.add(bsciii);
DefaultMutableTreeNodebcai=new DefaultMutableTreeNode("BCA-I");
DefaultMutableTreeNodebcaii=new DefaultMutableTreeNode("BCA-II");
DefaultMutableTreeNodebcaiii=new DefaultMutableTreeNode("BCA-III");
bca.add(bcai);
bca.add(bcaii);
bca.add(bcaiii);
DefaultMutableTreeNodebbai=new DefaultMutableTreeNode("BBA-I");
DefaultMutableTreeNodebbaii=new DefaultMutableTreeNode("BBA-II");
DefaultMutableTreeNodebbaiii=new DefaultMutableTreeNode("BBA-III");
bba.add(bbai);
bba.add(bbaii);
bba.add(bbaiii);
DefaultMutableTreeNodemca=new DefaultMutableTreeNode("MCA");
DefaultMutableTreeNodemsc=new DefaultMutableTreeNode("MSc");
pg.add(mca);
pg.add(msc);
DefaultMutableTreeNodemcai=new DefaultMutableTreeNode("MCA-I");
DefaultMutableTreeNodemcaii=new DefaultMutableTreeNode("MCA-II");
DefaultMutableTreeNodemcaiii=new DefaultMutableTreeNode("MCA-III");
mca.add(mcai);
mca.add(mcaii);
mca.add(mcaiii);
DefaultMutableTreeNodemsci=new DefaultMutableTreeNode("MSc-I");
DefaultMutableTreeNodemscii=new DefaultMutableTreeNode("MSc-II");
msc.add(msci);
msc.add(mscii);
JTreejt=new JTree(hvpm);
f.add(jt);
f.setSize(500,400);
f.setVisible(true);
} public static void main(String[] args)
{
newTreeExample();
}
}
Output:-
E:/Advance Java/javac TreeExample.java
E:/Advance Java/java TreeExample
Practical No.17
/*Java Swing program for login window with username and password*/
import java.awt.*;
importjava.awt.event.*;
import javax.swing.*;
public class LoginDemo extends JFrame implements ActionListener
{
JPanel panel;
JLabeluser_label, password_label, message;
JTextFielduserName_text;
JPasswordFieldpassword_text;
JButton submit, cancel;
LoginDemo()
{
user_label = new JLabel();
user_label.setText("UserName :");
userName_text = new JTextField();
password_label = new JLabel();
password_label.setText("Password :");
password_text = new JPasswordField();
submit = new JButton("SUBMIT");
panel = new JPanel(new GridLayout(3, 1));
panel.add(user_label);
panel.add(userName_text);
panel.add(password_label);
panel.add(password_text);
message = new JLabel();
panel.add(message);
panel.add(submit);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
submit.addActionListener(this);
add(panel, BorderLayout.CENTER);
setTitle("Please Login Here !");
setSize(450,350);
setVisible(true);
}
public static void main(String[] args)
{
newLoginDemo();
}
@Override
public void actionPerformed(ActionEventae)
{
StringuserName=userName_text.getText();
String password =password_text.getText();
if (userName.trim().equals("Neha Tiwari")
&&password.trim().equals("Neha@12345")) { message.setText(" Hello " +
userName+ "");
}else
{
message.setText(" Invalid user.. ");
}
}
}
Output:-
Practical No.18
/*Swing program to find IP address of corresponding website*/
import javax.swing.*;
importjava.awt.event.*;
import java.net.*;
public class IPFinder extends JFrame implements ActionListener{
JLabel l;
JTextFieldtf;
JButton b;
IPFinder(){
super("IP Finder Tool - Javatpoint");
l=new JLabel("Enter URL:");
l.setBounds(50,70,150,20);;
tf=new JTextField();
tf.setBounds(50,100,200,20);
w”w”wspeedrun com
151
Practical No.19
import javax.swing.*;
public class CheckBox
{
CheckBox()
{
JFrame f= new JFrame("CheckBox Example");
JCheckBox checkBox1 = new JCheckBox("Advance Java");
checkBox1.setBounds(100,100,200,100);
JCheckBox checkBox2 = new JCheckBox("Linux", true);
checkBox2.setBounds(100,200, 200,100);
JCheckBoxcheckBox3=newJCheckBox("C#withADO.NET",true);
checkBox3.setBounds(100,300,200,100);
JCheckBoxcheckBox4=newJCheckBox("ADBMS",true);
checkBox4.setBounds(100,400,200,100);
f.add(checkBox1);
f.add(checkBox2);
f.add(checkBox3);
f.add(checkBox4);
f.setSize(600,600);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
newCheckBox();
}
}
Output:-
`
Practical No.20
/*Write a Swing program for employee table with attributes Emp_ID, Name, Salary, Dept.,
DOB, DOJ, Location*/
import javax.swing.*;
public class TableExample
{
JFrame f;
TableExample()
{
f=new JFrame();
Stringdata[][]={
{"11111","John Wick","7 Millions USD","Assassins","1970","1999","New York"},
{"11112","Jason Bourne","5 MillionsUSD","Black Ops
Operative","1973","2000","Classified"},
{"11113","Deckard Shaw","6 Million GBP","SAS","1969","1999","London"}};
String column[]={"ID","NAME","SALARY","Dept","DOB","DOJ","Location"};
JTablejt=new JTable(data,column);
jt.setBounds(300,400,1200,1000);
JScrollPanesp=new JScrollPane(jt);
f.add(sp);
f.setSize(1000,900);
f.setVisible(true);
}
public static void main(String[] args)
{
newTableExample();
}
}
Output:-