WT Lab
WT Lab
OBJECTIVE: Write a Java program for creating one base class for student personal details and inherit
those details into the sub class of student Educational details to display complete student information.
THEORY: Inheritance in Java is a mechanism in which one object acquires all the properties and
behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system). The
idea behind inheritance in Java is that you can create new classes that are built upon existing classes.
When you inherit from an existing class, you can reuse methods and fields of the parent class.
Moreover, you can add new methods and fields in your current class also.
CODE:
class Personal {
name=a;
fname=b;
add=c;
phno=d;
}
void display() {
System.out.println("Name is "+name);
System.out.println("Address "+add);
} }
int roll,age;
char section;
age=f;
section=g;
branch=h;
void display2() {
super.display();
System.out.println("Roll Number="+roll);
System.out.println("AGE="+age);
System.out.println("SECTION="+section);
System.out.println("Branch is "+branch);
} }
class Hello {
e.display2();
} }
OUTPUT:
EXPERIMENT 2:
OBJECTIVE: Write a Java program to create multiple threads for different calculator operations.
THEORY: Arithmetic Operators involve the mathematical operators that can be used to perform various
simple or advanced arithmetic operations on the primitive data types referred to as the operands. These
operators consist of various unary and binary operators that can be applied on a single or two operands.
OPERATOR OPERATION
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
CODE:
import java.lang.*;
import java.util.*;
int i,j;
A1(int x,int y) {
i=x;
j=y;
System.out.println("SUM "+(i+j));
System.out.println( "DIFFERENCE "+(i-j));
System.out.println("RATIO "+(i/j));
System.out.println("POWER "+Math.pow(i,j));
System.out.println("END OF A");
}
class B1 extends Thread {
int i;
B1(int x) {
i=x;
System.out.println("SINE OF "+i+""+Math.sin(i));
System.out.println("COSINE OF "+i+""+Math.cos(i));
}
}
class Operate {
public static void main(String args[]) {
int x=s.nextInt();
int y=s.nextInt();
System.out.println("ENTER A VALUE FOR TRIGNOMETRIC OPERATIONS");
int z=s.nextInt();
A1 a=new A1(x,y);
B1 b=new B1(z);
a.start();
b.start();
}
OUTPUT:
EXPERIMENT 3:
OBJECTIVE: Write a Java program for handling mouse events.
THEORY: An event which indicates that a mouse action occurred in a component. A mouse action is
considered to occur in a particular component if and only if the mouse cursor is over the unobscured
part of the component's bounds when the action happens. Component bounds can be obscurred by the
visible component's children or by a menu or by a top-level window. This event is used both for mouse
events (click, enter, exit) and mouse motion events (moves and drags).
This low-level event is generated by a component object for:
• Mouse Events
CODE:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
addMouseMotionListener(this);
}
// save coordinates
mouseX = 0;
mouseY = 10;
repaint();
}
// save coordinates
mouseX = 0;
mouseY = 10;
repaint();
}
// Handle mouse exited.
// save coordinates
mouseX = 0;
mouseY = 10;
repaint();
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
// save coordinates
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
// Handle mouse dragged.
// save coordinates
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
repaint();
// show status
}
// Display msg in applet window at current X,Y location.
public void paint(Graphics g) {
OUTPUT:
EXPERIMENT 4:
OBJECTIVE: Write a Java program that works as a simple Calculator.
THEORY: Arithmetic Operators involve the mathematical operators that can be used to perform various
simple or advanced arithmetic operations on the primitive data types referred to as the operands. These
operators consist of various unary and binary operators that can be applied on a single or two operands.
OPERATOR OPERATION
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
CODE:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.lang.*;
TextField t;
GridLayout g;
Panel p;
BorderLayout b1;
Button b[]=new Button[17];
String s[]={"0","1","2","3","4","5","6","7","8","9","/","%","*","+","-","=","ac"};
int x=0,y=0,r;
boolean x1=true;
String s1,s2;
char c,op='x';
b1=new BorderLayout();
t=new TextField();
setLayout(b1);
add(t,BorderLayout.NORTH);
p=new Panel();
g=new GridLayout(4,4);
p.setLayout(g);
add(p,BorderLayout.CENTER);
for(int i=0;i<17;i++) {
b[i]=new Button(s[i]);
p.add(b[i]);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b[0])
dis("0");
if(e.getSource()==b[1])
dis("1");
if(e.getSource()==b[2])
dis("2");
if(e.getSource()==b[3])
dis("3");
if(e.getSource()==b[4])
dis("4");
if(e.getSource()==b[5])
dis("5");
if(e.getSource()==b[6])
dis("6");
if(e.getSource()==b[7])
dis("7");
if(e.getSource()==b[8])
dis("8");
if(e.getSource()==b[9])
dis("9");
if(e.getSource()==b[10])
calc('/');
if(e.getSource()==b[11])
calc('%');
if(e.getSource()==b[12])
calc('*');
if(e.getSource()==b[13])
calc('+');
if(e.getSource()==b[14])
calc('-');
if(e.getSource()==b[15])
calc(op);
if(e.getSource()==b[16]) {
s1=new String();
s2=new String();
x1=true;
t.setText("0");
op='x';
if(x1==true) {
s1+=n;
x=Integer.parseInt(s1);
t.setText(s1);
}
else {
s2+=n;
y=Integer.parseInt(s2);
t.setText(s2);
if(op!='x') {
switch(op) {
case '/':r=x/y;
break;
case '%':r=x%y;
break;
case '*':r=x*y;
break;
case '+':r=x+y;
break;
case '-':r=x-y;
break;
}
s1=String.valueOf(r);
s2="0";
t.setText(s1);
op=c;
else {
t.setText("");
op=c;
x1=false;
}
}
}
/*
</applet>
*/
OUTPUT:
EXPERIMENT 5:
OBJECTIVE: Write a HTML program for demonstrating Hyperlinks.
THEORY: A webpage can contain various links that take you directly to other pages and even specific
parts of a given page. These links are known as hyperlinks. Hyperlinks allow visitors to navigate between
Web sites by clicking on words, phrases, and images. Thus you can create hyperlinks using text or images
available on a webpage. A link is specified using HTML tag <a>. This tag is called anchor tag and anything
between the opening <a> tag and the closing </a> tag becomes part of the link and a user can click that
part to reach to the linked document.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
</body>
</html>
OUTPUT:
EXPERIMENT 6:
Most often, the purpose of data validation is to ensure correct user input.
Validation can be defined by many different methods, and deployed in many different ways. Server side
validation is performed by a web server, after input has been sent to the server. Client side validation is
performed by a web browser, before input is sent to a web server.
CODE:
<html>
<head>
function validate(){
return false;
else{
document.getElementById("username").disabled = true;
document.getElementById("password").disabled = true;
document.getElementById("submit").disabled = true;
return false;
}
<script src="js/login.js"></script>
</head>
<body>
<div class="container">
<div class="main">
<h2>Javascript Login Form Validation</h2>
</form>
<span><b class="note">Note : </b>For this demo use following username and password. <br/><b
class="valid">User Name : Formget<br/>Password : formget#123</b></span>
</div></div>
</body>
</html>
OUTPUT:
EXPERIMENT 7:
OBJECTIVE: Write a javascript program for validating REGISTRATION FORM.
THEORY: Data validation is the process of ensuring that user input is clean, correct, and useful.Typical
validation tasks are:
Most often, the purpose of data validation is to ensure correct user input.
Validation can be defined by many different methods, and deployed in many different ways. Server side
validation is performed by a web server, after input has been sent to the server. Client side validation is
performed by a web browser, before input is sent to a web server.
CODE:
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<meta name="keywords" content="example, JavaScript Form Validation, Sample registration form" />
<body onload="document.registration.userid.focus();">
<h1>Registration Form</h1>
Use tab keys to move from one input field to the next.
<li><label for="passid">Password:</label></li>
<li><label for="username">Name:</label></li>
<li><input type="text" name="username" size="50" /></li>
<li><label for="address">Address:</label></li>
<li><select name="country">
<option value="AF">Australia</option>
<option value="AL">Canada</option>
<option value="DZ">India</option>
<option value="AS">Russia</option>
<option value="AD">USA</option>
</select></li>
<li><label for="email">Email:</label></li>
<li><input type="text" name="email" size="50" /></li>
<li><label id="gender">Sex:</label></li>
<li><label>Language:</label></li>
<li><input type="checkbox" name="en" value="en" checked /><span>English</span></li>
<li><label for="desc">About:</label></li>
</ul>
</form>
function formValidation() {
if(userid_validation(uid,5,12)) {
if(passid_validation(passid,7,12)) {
if(allLetter(uname)) {
if(alphanumeric(uadd)) {
if(countryselect(ucountry)) {
if(allnumeric(uzip)) {
if(ValidateEmail(uemail)) {
if(validsex(umsex,ufsex)) {
}}}}}}}}
return false;
function userid_validation(uid,mx,my) {
var uid_len = uid.value.length;
uid.focus();
return false;
return true;
function passid_validation(passid,mx,my) {
var passid_len = passid.value.length;
if (passid_len == 0 ||passid_len >= my || passid_len < mx) {
return false;
return true;
function allLetter(uname) {
if(uname.value.match(letters)) {
return true;
}
else {
return false;
function alphanumeric(uadd)
{ var letters = /^[0-9a-zA-Z]+$/;
if(uadd.value.match(letters))
{ return true; }
else {
uadd.focus();
return false;
}}
</body> </html>
OUTPUT:
EXPERIMENT 8:
OBJECTIVE: Write a program to display contents of XML file in a table using Extensible Style Sheets.
• XSLT is used to transform XML document from one form to another form.
• The result of applying XSLT to XML document could be an another XML document, HTML, text or
any another document from technology perspective.
• The XSL code is written within the XML document with the extension of (.xsl).
CODE:
<books>
<publisher>Publisher -: Wiley</publisher>
<edition>Edition -: 3</edition>
<book>
<author>Author -: Ditel</author>
<publisher>Publisher -: Pearson</publisher>
<edition>Edition -: 3</edition>
<price>Price -: 400</price>
</book>
<book>
<edition>Edition -: 5</edition>
<price>Price -: 700</price>
</book>
<book>
<author>Author -: Navath</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 600</price>
</book>
<book>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 8</edition>
<price>Price -: 300</price>
</book>
</books>
books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
display : block;
title {
font-size : 25px;
font-weight : bold;
}
OUTPUT:
EXPERIMENT 9:
• Servlet is an API that provides many interfaces and classes including documentation.
• Servlet is a class that extends the capabilities of the servers and responds to the incoming
requests. It can respond to any requests.
• Servlet is a web component that is deployed on the server to create a dynamic web page.
CODE:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession(true);
Date createTime
= new Date(session.getCreationTime());
Date lastAccessTime
= new Date(session.getLastAccessedTime());
else {
visitCount = (Integer)session.getAttribute(
visitCountKey);
visitCount = visitCount + 1;
userID
= (String)session.getAttribute(userIDKey);
}
session.setAttribute(visitCountKey, visitCount);
response.setContentType("text/html");
+ "transitional//en\">\n";
out.println(
docType + "<html>\n"
+ "<head><title>" + title + "</title></head>\n"
"<tr>\n"
+ " <td>id</td>\n"
+ "</tr>\n"
"<tr>\n"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Time of Last Access</td>\n"
"<tr>\n"
"<tr>\n"
+ "</tr>\n"
+ "</table>\n"
+ "</body>"
+ "</html>"); }}
OUTPUT:
EXPERIMENT 10:
OBJECTIVE: Write a JSP that reads parameters from user login page.
THEORY: JSP technology is used to create web application just like Servlet technology. It can be thought
of as an extension to Servlet because it provides more functionality than servlet such as expression
language, JSTL, etc.
A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than Servlet because
we can separate designing and development. It provides some additional features such as Expression
Language, Custom Tags, etc.
CODE:
login.html
<html>
<head>
<script type="text/javascript">
function ccheck() {
uid=document.f1.uid.value;
cpass=document.f1.cpass.value;
if(uid=="" || uid==null) {
return false;
if(cpass=="" || cpass==null) {
document.f1.cpass.focus();
return false;
}
return true;
}
</script>
</head>
<body onload="document.f1.uid.focus()">
<table>
<tr>
<td><b>User ID</b></td>
<td><input name="uid" type="text"/></td>
</tr>
<tr>
<td><b>Password</b></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</body>
</html>
doLogin.jsp
<%@ page import="java.sql.*" %>
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn1","system","pintu");
Statement stmt=con.createStatement();
ResultSet rs;
cid=request.getParameter("uid");
pass=request.getParameter("cpass");
//System.out.println("cid="+cid+" pass="+pass);
rs=stmt.executeQuery("select * from login where userid='"+cid+"' and password='"+pass+"' ");
if(rs.next()) {
session.setAttribute("scid",cid);
con.close();
response.sendRedirect("welcome.jsp");
else {
%>
<html>
<body>
<%
%>
</body>
</html>
welcome.jsp
<head>
</head>
<body>
<%
scid=(String)session.getAttribute("scid");
%>
<div id="welcome">
<h2><span>Welcome:::<strong><font color='Red'><%= scid %></font></strong></span></h2>
</div>
</body>
</html>
OUTPUT: