Professional Documents
Culture Documents
Practical No: 1: 1904313902 Avinash Chandravansi 1
Practical No: 1: 1904313902 Avinash Chandravansi 1
Question:
Write a program to create a class named shape. In this class we have three sub
classes circle,triangle and square each class has two member function named draw
() and erase (). Create these using polymorphism concepts.
Code:
class shape
{void draw(){
System.out.println("Shape is drawn");
}
void erase(){
System.out.println("Shape is erased");
}
}
class circle extends shape
{
void draw()
{
System.out.println("Circle is drawn");
}
void erase()
{
System.out.println("Circle is erased");
}
} class triangle extends shape
{
void draw()
{
System.out.println("Triangle is drawn");
}
void erase()
{
System.out.println("Triangle is erased");
}
}
class square extends shape
{
Output :
Write a java program to create an abstract class named Shape that contains two
integers and an empty method named printArea(). Provide three classes named
Rectangle, Triangle and Circle such that each one of the classes extends the class
Shape. Each one of the classes contain only the method printArea( ) that prints the
area of the given shape.
Code:
abstract class shape
{
int x=10;int y=20;
abstract void printArea();
}
class Rectangle extends shape
{
void printArea(){
System.out.println("Area of rectangle is :"+(x*y));
}
}
class Triangle extends shape
{
void printArea(){
System.out.println("Area of Triangle is :"+(0.5*x*y));
}
}
class Circle extends shape
{
void printArea(){
System.out.println("Area of Circle is :"+(3.14*x*x));
}
}
class practical2
{
public static void main(String[] args)
{
Rectangle ob1 = new Rectangle();
Output:
Write a program to create interface named test. In this interface the member
function is square. Implement this interface in arithmetic class. Create one new
class called ToTestInt in this class use the object of arithmetic class.
Code:
interface test
{
void square();
}
class arithmetic implements test
{
int no;
arithmetic(int num) //using parameterized constructor
{
no = num;
}
public void square(){
System.out.println("The square root of "+no+ " is : "+Math.sqrt(no));
}
}
class ToTestInt
{
void ans(int value)
{
arithmetic ob = new arithmetic(value);
ob.square();
}
}
class practical3
{
public static void main(String[] args)
{
ToTestInt obj = new ToTestInt();
obj.ans(Integer.parseInt(args[0]));
}
Write a program to create a package named mypack (to calculate area) and import
it in circle class.
Code:
Circle.java
package mypack;
Practical4.java
import mypack.circle;
class practical4
{
public static void main(String [] args)
{
circle ob = new circle();
ob.displayarea(Integer.parseInt(args[0]));
}
}
Output:
import java.util.Scanner;
class practical5
{
static void single()
{
Scanner ob = new Scanner(System. in);
System.out.println("Enter the length of array");
int len = ob.nextInt();
int arr[] = new int[len];
System.out.println("Enter the array elements");
for(int i=0;i<len;i++)
{
arr[i]=ob.nextInt();
}
System.out.println("Final array is :");
for(int i=0;i<len;i++)
{
System.out.print(arr[i]+" ");
}
}
static void twodim()
{
Scanner ob = new Scanner(System. in);
arr[i][j]= ob.nextInt();
}
}
System.out.println("The output array is :");
for(int i=0;i<row;i++ )
{
for(int j=0;j<column;j++)
{
System.out.print("["+arr[i][j]+"]");
}
System.out.println();
}
System.out.println("The Numbers of elements in this array are : "+(row*column));
}
arr[i][j][k]= ob.nextInt();
}
}
}
for(int i=0;i<tab;i++ )
{
for(int j=0;j<row;j++)
{
for(int k=0;k<column;k++ )
{
System.out.print("[" +arr[i][j][k]+"]");
}
System.out.println();
}
}
int n;
do{
System.out.println("#########################################");
System.out.println("Enter your choice : \n1. To use Single Dimensional array \n2. To use
Two Dimensional array. \n3. To use Multi-Dimensional array. \n0. To exit. ");
case 3 :
multidim();
break;
default :
n=0;
break;
}
}
while(n!=0);
}
}
Output:
· Single inheritance
· Multi-level inheritance
· Hierarchical inheritance
· Multiple inheritance
Code:
Single inheritance
class base
{
void display(int x) //method to display value
{
System.out.println("The output value is :"+x);
}
}
class singleinherit
{
public static void main(String[] args)
{
int z = 12; //Finding square of this number
child ob = new child();
ob.square(z);
}
}
Multi-level inheritance
class a
{
void method1()
{
System.out.println("This is class A");
}
}
class b extends a
{
void method2()
{
System.out.println("This is class B");
}
}
class c extends b
{
void method3()
{
method1(); //method of class A called
method2(); //method of class B called
System.out.println("This is class C");
}
}
class multilevel
{
public static void main(String[] args)
{
c ob = new c();
ob.method3();
}
}
Hierarchical inheritance
class X
{
void method1()
{
System.out.println("Method1() from class X");
}
void method2()
{
System.out.println("Method2() from class X");
}
}
class Y extends X
{
void callb()
{
method1();
}
}
class Z extends X
{
void callc()
{
method2();
}
}
class hierinherit
{
public static void main(String[] args)
{
Y ob1 = new Y();
}
}
Output:
Multiple inheritance
interface interface1
{
String msg1 = "I Love";
}
interface interface2 extends interface1
{
String msg2 = "GNU/" ;
}
class class3 implements interface2
{
void display()
{
System.out.println(msg1+" "+msg2+"Linux");
}
}
class multiple
{
public static void main(String[] args)
{
class3 ob = new class3();
ob.display();
}
}
Output :
Code:
<html>
<head>
<title>Practical 7</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=yes" />
<style>
.navbar a:hover,
.dropdown:hover .dropbtn .dropdown-content a:hover {
background-color: #d81003;
}
.navbar a {
float: left;
font-size: 18px;
color: white;
text-align: center;
padding: 14px 40px;
text-decoration: none;
font-weight: 300;
}
#outer {
background-color: #d81003;
height: 50px;
}
.navbar {
overflow: hidden;
background-color: #0d2d62;
font-family: Arial;
font-weight: 300;
}
.dropdown {
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 10px 16px;
background-color: #0d2d62;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #0d2d62;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
.dropdown-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
*{
box-sizing: border-box;
}
.timeline {
position: relative;
max-width: 1200px;
margin: 0 auto;
}
.timeline::after {
content: '';
position: absolute;
width: 6px;
background-color: #d81003;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
.container {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
.container::after {
content: '';
position: absolute;
width: 25px;
height: 25px;
right: -17px;
background-color: white;
border: 4px solid #d81003;
top: 15px;
border-radius: 50%;
z-index: 1;
}
.left {
left: 0;
}
.left::before {
content: " ";
height: 0;
position: absolute;
top: 22px;
width: 0;
z-index: 1;
right: 30px;
border: medium solid white;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #0d2d62;
}
.right::before {
.right::after {
left: -16px;
}
.content {
padding: 20px 30px;
background-color: #0d2d62;
position: relative;
border-radius: 6px;
color: white;
}
</style>
<body style="background-color:grey">
<div id="outer" style="height:auto;width:1300px;border:1px solid black;margin:0px
auto;border-radius: 10px;">
<div id="header"
style="border-radius:1px solid black;height: 150px;width: 100%;background-
color:white;border-radius: 10px 10px 0 0 ;">
<div id="logo" style="float:left;height:100%;width:150px;background-image:
url('logo.png');border-radius: 10px;">
</div>
<div id="title" style="height:120px;width:900px;float:left;text-align:center;margin-
top:5px;margin:0px auto">
<br>
<span style="font-size:33px;font-weight:800;text-align:center;color:#2b2a2a;font-
family:'Agency FB'">बु न्दे लखण्ड
अभियान्त्रिकी एवं प्रौद्योगिकी सं स्थान,झाँसी </span><br />
<span style="font-size:34px;font-weight:800;text-align:center;color:#2b2a2a;font-
family:'Agency FB'">Bundelkhand
Institute of Engineering and Technology, Jhansi</span>
</div>
<div id="help"
style="background-color:#0d2d62;margin:0px
auto;height:70px;width:auto;float:left;margin-top:16px;text-align:center;border-radius:20px;">
<span style="color:white;font-weight:500;font-size:20px">
☎ Helpline Number
</span>
<span style="color:white;font-weight:300"></br> 0510-2980211 </br>
For General Queries
</span>
</div>
</div>
</div>
</div>
</div>
<div id="mytitle"
style="opacity:0.9; height:200px;width:500px;background-color:black;margin-
left:730px;opacity: 0.5;border-radius: 10px;text-align: center; ">
<br>
<span style="color:white;text-align: center;font-size: 30px;font-weight: 600;"> Avinash
Chandravansi</span>
<hr>
<br>
<span style="color:white;font-size:18px ; font-weight: 200;">Former System
Administrator at Wipro Ltd. </span>
<br>
<span style="color:white;font-size:18px;font-weight: 200 ;"> and a Cyber Security
Enthusiast </span>
<br>
<span style="color:white;font-size:18px;font-weight: 200 ;"> NDG Linux - Associate
Level by CISCO Network
</div>
<center>
<h1>My Journey So far...</h1>
</center>
<div class="timeline">
<div class="container left" style="back">
<div class="content" style="background-color:#0d2d62;color:white">
<h1>2014 - High School</h1>
<h3>Completed High School from Sacred Heart Convent High School, Khajuraho(M.P)
affiliated to I.C.S.E</h3>
</div>
</div>
<div class="container right">
<div class="content">
<h1>2018 - Diploma in I.T</h1>
<h3> Completed Diploma in Information Technology from Hewett Polytechnic
affiliated to BTEUP. </h3>
</div>
</div>
<div class="container left" style="back">
<div class="content" style="background-color:#0d2d62;color:white">
<h1>2018 - Joined Wipro Ltd.</h1>
<h3>Joined Wipro Limited as System Administrator.</h3>
</div>
</div>
<div class="container right">
<div class="content">
<h1>2019 - Left Wipro Ltd.</h1>
<h3> Left Wipro Limited after completing 1 year. </h3>
</div>
</div>
</div>
</div>
<br>
<div id="footer" style="background-color:#d81003;width:100%;height:50px;margin-top:
-25px;">
<div style="background-color:#0d2d62;width:100%;height:45px;">
<center>
<p style="color:white; font-size:20px;font-weight: 300;line-height: 45px;"> ©
Avinash
Chandravansi Technology used: HTML
and CSS </p>
</center>
</div>
</div>
</div>
</div>
</body>
</html>
Output :
Write programs using Java script for Web Page to display browsers information.
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Calculator extends Applet implements ActionListener
{
TextField inp;
setBackground(Color.white);
setLayout(null);
int i;
inp.setBounds(150,100,270,50);
this.add(inp);
for(i=0;i<10;i++)
button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);
this.add(button[i]);
button[i].addActionListener(this);
dec.setBounds(200,300,50,50);
this.add(dec);
dec.addActionListener(this);
clr.setBounds(250,300,50,50);
this.add(clr);
clr.addActionListener(this);
operator[0]=new Button("/");
operator[1]=new Button("*");
operator[2]=new Button("-");
operator[3]=new Button("+");
operator[4]=new Button("=");
for(i=0;i<4;i++)
operator[i].setBounds(300,150+(i*50),50,50);
this.add(operator[i]);
operator[i].addActionListener(this);
operator[4].setBounds(350,300,70,50);
operator[4].addActionListener(this);
String num1="";
String op="";
String num2="";
char ch = button.charAt(0);
if (!op.equals(""))
else
inp.setText(num1+op+num2);
else if(ch=='C')
inp.setText("");
double temp;
double n1=Double.parseDouble(num1);
double n2=Double.parseDouble(num2);
else
if (op.equals("+"))
temp = n1 + n2;
else if (op.equals("-"))
temp = n1 - n2;
else if (op.equals("/"))
temp = n1/n2;
else
temp = n1*n2;
inp.setText(num1+op+num2+" = "+temp);
op = num2 = "";
}
}
else
{
num1 = op = num2 = "";
inp.setText("");
else
if (op.equals("") || num2.equals(""))
op = button;
else
double temp;
double n1=Double.parseDouble(num1);
double n2=Double.parseDouble(num2);
temp = n1 + n2;
else if (op.equals("-"))
num1 = Double.toString(temp);
op = button;
num2 = ""; }
}
inp.setText(num1+op+num2);
}
}
}
Output:
Practical No: 10
Writing program in XML for creation of DTD, which specifies set of rules. Create
a style sheet in CSS/ XSL & display the document in internet explorer.
Code:
dtd.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="style.css"?>
<!DOCTYPE student [
<!ELEMENT student (sno,name,rollno,branch,year)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT rollno (#PCDATA)>
<!ELEMENT branch (#PCDATA)>
<!ELEMENT year (#PCDATA)>
]>
<student>
<sno></sno>
<name>Avinash Chandravansi</name>
<email>avinash.chandravansi@outlook.com</email>
<rollno>1904313902</rollno>
<branch>Information Technology</branch>
<year>3rd year</year>
</student>
style.css
student {
font-size: 20px;
margin: 0px auto;
text-align: center;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
Output :
Practical No: 11
Install TOMCAT web server and APACHE. Access the above developed static
web pages for books web site, using these servers by putting the web pages
developed.
Ouput :
Code:
index.html
<html>
<head>
<title>Practical 12</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background-color:#202020;color:white">
<center>
<u> <h1>Web Technology - Practical 12 </h1></u>
queryrunner.java
import java.io.*;
import java.sql.DriverManager;
import javax.servlet.*;
import java.sql.*;
public class queryrunner extends HttpServlet {
private static final long serialVersionUID = 1L;
Ouput :
Assume four users user1, user2, user3 and user4 having the passwords pwd1,
pwd2, pwd3and pwd4 respectively. Write a servlet for doing the following.
· Create a Cookie and add these four user id’s and passwords to this Cookie.
· Read the user id and passwords entered in the Login form and authenticate
with the values available in the cookies.
Code :
Ouput :