Web Development and Core Java Lab Manual V Semester: Dept. of Computer Science and Engineering
Web Development and Core Java Lab Manual V Semester: Dept. of Computer Science and Engineering
Web Development and Core Java Lab Manual V Semester: Dept. of Computer Science and Engineering
Lab Manual
Vth Semester
Table of Content
Particular
S.no.
Page No.
General Instructions
MDU Syllabus
3
4
5
List of Experiments
Hardware and Software requirement
Experiment-1
5
6
7
Experiment-2
Experiment-3
11
Experiment-4
16
Experiment-5
20
10
Experiment-6
23
11
Experiment-7
24
12
Experiment-8
26
13
Experiment-9
28
14
Experiment-10
32
15
Experiment-11
38
16
Experiment-12
54
DOS
Without Prior permission do not enter into the Laboratory.
Students should sign in the LOGIN REGISTER before entering into the laboratory.
Students should come with observation and record note book to the laboratory.
Students should maintain silence inside the laboratory.
After completing the laboratory exercise, make sure to shutdown the system properly.
DONTS
Students bringing the bags inside the laboratory..
Students using the computers in an improper way.
Students scribbling on the desk and mishandling the chairs.
Students using mobile phones inside the laboratory.
Students making noise inside the laboratory.
Syllabus
CSE-311 Web Development & Core JAVA
Java programs using classes & objects and various control constructs such as loops etc , and data
structures such as arrays , structures and functions.
Java programs for creating Applets for display of Images ,Texts and Animation
Programs related to interfaces & packages
Input output & Random files programs in java Java
programs using Event driven concept Programs related to
Network Programming
Development of Web site for the college or newspaper agency.
List of Experiment
1. Write a program to print Hello World in java.
2. Write a program to implement basic data types and control structure (loop, if-else etc ) in
java.
3. Write a program to implement array , polymorphism, inheritance using methods in java.
4. Write a program to implement packages and interface in java.
5. Write a program to draw an image using applet in Java.
6. Write a program to read and write data in a file using java.
7. Create a webpage using HTML to describe your department using paragraph and list.
8. Create a table in HTML to show your class time table.
9. Apply CSS(Cascade Style Sheet) to change a certain portion ,Bold ,Italic and underline
certain words in your HTML web page.
10. Create a registration form and put validation checks on values entered by the users using
java scripts.
11. Create a JSP page for the form which embedded JSP in HTML.
12. Using idea from the above experiments try to create a website for your college (RPS).
HARDWARE REQUIREMENTS:
Pentium Dual Core @ 2.70 Ghz and above with 1GB RAM,
160 GB HARD Disk,
Monitor 1024* 768 color
SOFTWARE REQUIREMENTS:
Windows / Linux operating system
JDK 1.6 (or above)
Netbeans IDE or Eclipse IDE
Oracle or MS-Access or MySQL
Experiment-1
Aim: Write a program to print Hello World in java
Source Code:
Class First {
public static void main (String arg [])
{
System.out.print (Hello World);
}
}
Output:
C:\java>javac First.java
C:\java>java First.
Hello World
Viva Questions:
1.What are command line arguments?
The values that are passed to the main method from the command line while executing the
program are called as command line arguments.
2. What are the various types of operators available in java?
Arithmetic operator, Relational operator, Logical operator, Bitwise operator, Increment
and decrement operator, Assignment operator, Conditional operator and Special operator.
3. What is a ternary operator?
The operator that takes three arguments is called as ternary operator.
The conditional operator is the only ternary operator available in java.
4. What is the use of Integer.parseInt() method?
This method is used to convert the String object into integer value.
5. What is called as a Boolean expression?
An expression that returns either true or false value is called a Boolean expression.
Experiment-2
Aim: Write a program to implement basic data types and control structure (loop, if-else etc ) in
java
Source Code:
Viva Questions:
1. What is a control structure?
Control structures are statements that are used to change the flow of the program based on some
condition.
2. What are the two types of control structures?
Decision making statements and Looping statements
3. What are decision making statements?
The statements that are used to execute only a block of code and leaving others based on the
condition.
4. .What is the use looping statement?
The looping statement is used to execute a block of repeatedly until the
condition is true.
5. What is the difference between while and do..while?
In case of while statement the block of code will not be executed atleast
once if the condition is false at the first run.
In case of do..while statement the block of code will be executed atleast
once if the condition is false at the first run.
10
Experiment-3
Aim: Write a program to implement array, polymorphism, inheritance using methods in java
Source Code:
class Array {
public static void main(String args[]){
int a[]=new int[4];//declaration and instantiation
a[0]=1;//initialization
a[1]=2;
a[2]=3;
a[3]=4;
//printing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}}
(ii). Polymorphism
Public class Car {
void run()
{
System.out.println("running");}
}
class Swift extends Bike{
void run()
{
System.out.println("running safely with 80km");
}
public static void main(String args[]){
Car c = new Swift();//upcasting
c.run();
}
}
Output: running safely with 80km
11
(iii). Inheritance
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[])
{
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
Output:
Programmer salary is:40000
Bonus of Programmer is: 10000
12
Viva Questions:
1.
What is an array?
3.
4.
5.
What is Vector?
Vector is just like an array that can store elements of different data types.
The elements of the vector can only be objects. So the primitive data type must be
converted into object data type before adding to the vector.
6.
7.
8.
The capacity of the array is fixed. The size of Vector can be changed during
Run time.
What is class?
A class is a collection of data and methods that defines an object. The variables and
methods (functions) of a class are called members of the class.
9.
What is an object?
The variable of type class is called object.
Syntax for defining a class
class className
{
//Declaration of instance variables
//Constructors
//Instance Methods
}
10. How
The members of the class can be accessed using the dot operator
Objectname .variable
Or
Objectname.methodName(Arguments)
12. What
is a constructor?
Constructors are special methods whose name is same as the class name. The
14
Constructor that does not take any argument is called default constructor.
14.
Defining more than one constructor for a class which differ in the number of arguments /
type of arguments or both is called constructor overloading.
15. What
is inheritance?
Inheritance is the process of deriving a new class from an existing class. The newly
created class is called sub class and the already existing class is called super class.
16. What
Experiment-4
Aim: Write a program to implement packages and interface in java.
Source code:
package mypack;
public class Test{
public static void main(String args[]){
System.out.println("Welcome to First package");
}
}
Save Test.java
Compile: Syntax : javac -d directory javafilename
Eg. javac d.Test.java
Run: java mypack.Test
(ii)
package my;
public class A{
void show()
{
System.out.print(Hello);
}
}
Compile using javac d A.java
16
(iii).
interface printable{
void print();
}
class A implements printable{
public void print(){System.out.println("Hello");}
public static void main(String args[]){
A obj = new A();
obj.print();
}
}
Output: Hello
Viva Questions:
17
1. What is an interface?
Interface is just like a class which contains final variables and public abstract methods.
It is used to implement multiple inheritances in java.
2. What is an abstract method?
The method which has only declaration in the super class and defined in the subclass
is known as abstract method.
4. What is package?
18
19
Experiment-5
Aim: Write a program in java to draw image using applet.
To execute the applet by appletviewer tool, create an applet that contains applet tag in comment
and compile it. After that run it by: appletviewer First.java. Now Html file is not required but it is
for testing purpose only.
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawRect(10,10,50,100);
g.drawRect(10,10,50,100);
}
}
/*
<applet code="First. class" width="300" height="300">
</applet>
*/
Output:
To execute the applet by appletviewer tool, write in command prompt:
c:\>javac First.java
c:\>appletviewer First.java
20
21
Viva Questions:
1. What is an applet?
Applet is a small interactive java programs that are used for web application.
2. What are the two packages that are needed to create an applet?
Java.awt and java.applet
3. What is an applet tag?
Applet tag is an HTML tag that is used to run the java applets.
4. What is an event?
Events is an interruption given to the running program using input devices such as
mouse, keyboard etc.
5. What package is needed to handle an event?
java.awt.event
.
6. What are the steps needed to handle the event?
1. Import java.awt.event
2. Implement the corresponding Event Listener interfaces
3. Register the Event Listeners with the event source.
4. Override the appropriate methods of the listener interfaces.
22
Experiment-6
Aim : Write a program to read and write data in a file using java
Source Code:
import java.io.*;
class Test{
public static void main(String args[]){
try{
FileOutputstream fout=new FileOutputStream("abc.txt");
String s="Anup Kumar is a good player";
byte b[]=s.getBytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("File created ...");
}catch(Exception e){System.out.println(e);}
}
}
import java.io.*;
class SimpleRead{
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("abc.txt");
int i=0;
while((i=fin.read())!=-1){
System.out.println((char)i);
}
fin.close();
}catch(Exception e){system.out.println(e);}
}
}
Output: Anup Kumar is a good player
23
Experiment-7
Aim: Create a webpage using HTML to describe your department using paragraph and list.
Source Code:
<html>
<body>
<center> <b><u>Department of Computer Science and Engineering</b></u></center>
<p>The fundamental aim of faculty is to provide academic, professional and research support for
students by designing and developing educational programmes that contribute the effective
learning and critical thinking with theoretical and practical knowledge about sustainable
developing field of Computer Science and Engineering.</p>
<p>The discipline is one of the most leading and demanding professional careers in today's
modern era. It involves designs, supports and operations of computer software / hardware
systems. Here the Computer Science programme of RPS Group of Institutions provides a
balanced blend of software and hardware learning experiences, founded on solid mathematics
and science with a definite engineering flavour, and hands on experience with the latest
equipments in our laboratories. The department also highlights diversified areas of computer
science such as programming, algorithms, hardware, software, testing, networking and
simulation ranging from elementary to upper intermediate levels. For practical orientation, highly
advanced research laboratories have been installed with the latest configured computer machines.
</p>
<p> Some of Our Faculty Members:</p>
<ol>
<li>Mr. Mahesh Kumar</li>
<li>Mr. Jitender </li>
<li>Mr. Mukesh Kumar</li>
<li>Mr. Kuldeep Yadav</li>
24
</ol>
</html>
Output:
25
Experiment-8
Aim: Create a table in HTML to show your class time table.
Source Code:
<html>
<body>
<center> <b><u>Time Table</b></u></center>
<center><table border="1">
<tr><th>Day-Time</th><th>9:00-10:00 </th><th>10:00-11:00</th><th>11:0012:00</th><th>12:30-1:30 </th><th>1:30-2:30</th><th>2:30-3:30</th></tr>
<tr><td><b>Monday</b></td><td>CAO</td><td>C-Programming</td><td></td><td>WD</td><td>DIS</td><td>-</td></tr>
<tr><td><b>Tuesday</b></td><td>-</td><td>C-Programming</td><td></td><td>CAO</td><td>-</td><td>-</td></tr>
<tr><td><b>Wednesday</b></td><td>CAO</td><td>C-Programming</td><td></td><td>SWD</td><td>-</td><td>-</td></tr>
<tr><td><b>Thrusday</b></td><td>-</td><td>CProgramming</td><td>DIS</td><td>CAO</td><td>-</td><td>WD</td></tr>
<tr><td><b>Friday</b></td><td>-</td><td>C-Programming</td><td>DIS</td><td></td><td>WD</td><td>WD Lab</td></tr>
</table> </center>
</html>
26
Output:
27
Experiment-9
Aim : Apply CSS(Cascade Style Sheet) to change a certain portion, Bold , Italic and underline
certain words in your HTML web page.
Source: Style.css
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.stylebig {
font-size: 18px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
}
.stylemedium {
font-size: 14px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
}
.stylesmall {
font-family: "Times New Roman", Times, serif;
28
font-size: 12px;
font-weight: bold;
}
.stylegreen {font-family: "Times New Roman", Times, serif; font-size: 12px; font-weight: bold;
color: #007F00; }
.stylered {
font-size: 12px;
font-family: "Times New Roman", Times, serif;
color: #FF0000;
font-weight: bold;
}
.stylegrey {font-family: "Times New Roman", Times, serif; font-size: 12px; font-weight: bold;
color: #550055; }
.stylelink {font-family: "Times New Roman", Times, serif; font-size: 12px; font-weight: bold;
color: #AA0000; }
Home.Html
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
errorPage="ErrorPage.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="stylesheet/Style.css" type="text/css"/>
<title>Home Page</title>
29
</head>
<body>
<table width="100%" height="100%" >
<tr height="15%">
<td ><%@ include file="Header.jsp" %></td>
</tr>
<tr height="80%">
<td align="center" valign="baseline"><table width="70%">
<tr>
<td align="center"><a href="Home.jsp" class="stylelink" style="textdecoration:none">Home</a></td>
<td align="right"><a href="Student_Login.jsp" class="stylelink" style="textdecoration:none">Student Login</a>
<a href="Admin_Login.jsp" class="stylelink" style="textdecoration:none">Administrator Login</a></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
30
<td> </td>
</tr>
</table></td>
</tr>
<tr height="5%">
<td><%@ include file="Footer.jsp" %></td>
</tr>
</table>
</body>
</html>
31
Experiment-10
Aim: Create a registration form and put validation checks on values entered by the users using
java scripts.
Source Code:
StudentLogin.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
errorPage="ErrorPage.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Login Page</title>
<link rel="stylesheet" href="stylesheet/Style.css" type="text/css"/>
<script type="text/javascript">
function val()
{
if(document.form1.studentId.value=="")
{
alert("Please Enter Your Login ID");
document.form1.studentId.focus();
return false;
}
if(document.form1.studentPassword.value=="")
{
32
}
</script>
</head>
<body onLoad="javascript:document.form1.studentId.focus()">
<form name="form1" method="post" action="Student_Login_Handler.jsp" onSubmit="return
val()">
<table width="100%" height="100%" cellpadding="3" cellspacing="0" >
<tr>
<td bgcolor="#E1E1E1" height="15%"><%@ include file="Header.jsp" %></td>
</tr>
<tr>
<td width="100%" height="80%" align="center" valign="baseline"><table width="90%"
cellpadding="3" cellspacing="0" >
<tr>
<td width="8%"><a href="Home.jsp" class="stylelink" style="text-decoration:none; fontfamily: "Times New Roman", Times, serif;">Home</a></td>
<td width="35%" align="center"> </td>
<td width="27%"> </td>
33
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"><table width="40%" border="1" align="center"
bordercolor="#CCCCCC" bgcolor="#CCCCCC">
<tr align="center" bgcolor="#999999">
<td colspan="2" class="stylebig">Student Login Here</td>
</tr>
<tr bgcolor="#E1E1E1">
<td colspan="2"> </td>
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td width="35%" class="style7">Login Id: </td>
<td width="65%"><input name="studentId" type="text" id="studentId"></td>
35
</tr>
<tr bgcolor="#E1E1E1" class="stylesmall">
<td class="style7">Password:</td>
<td><input name="studentPassword" type="password" id="studentPassword"></td>
</tr>
<% if(request.getParameter("valid") != null &&
request.getParameter("valid").equals("invalid")) { %>
<tr bgcolor="#E1E1E1">
<td colspan="2" align="center" class="stylered">Invalid Login Id or Password.</td>
</tr>
<% } %>
<tr bgcolor="#E1E1E1">
<td colspan="2" align="center"><input name="login" class="style10" type="submit"
id="login" value="Login">
<input name="close" type="button" id="close" class="style10" value="Close"
onClick="self.location='Home.jsp'">
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="5%" align="center" ><%@ include file="Footer.jsp" %></td>
</tr>
36
</table>
</form>
</body>
</html>
37
Experiment-11
Aim: Create a JSP page for the form which embedded JSP in HTML.
38
39
40
41
42
43
44
45
46
47
48
49
If you are using Eclipse IDE first time, you need to configure the tomcat server First. Click for
How to configure tomcat server in eclipse IDE
50
51
52
Next
53
Experiment-12
Aim: Using idea from the above experiments tries to create a website for your college (RPS)
54