0% found this document useful (0 votes)
15 views29 pages

Lab Manual AL406 Java

This document is a lab manual for the Java Lab course (AL-4-6) for the B.Tech program in Computer Science and Business Systems for the 2022-23 academic session. It includes faculty details, course objectives, program outcomes, and a schedule of practical experiments that students will perform, along with their mapping to course and program outcomes. The manual aims to equip students with essential Java programming skills and knowledge through various hands-on experiments.

Uploaded by

Aarna Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views29 pages

Lab Manual AL406 Java

This document is a lab manual for the Java Lab course (AL-4-6) for the B.Tech program in Computer Science and Business Systems for the 2022-23 academic session. It includes faculty details, course objectives, program outcomes, and a schedule of practical experiments that students will perform, along with their mapping to course and program outcomes. The manual aims to equip students with essential Java programming skills and knowledge through various hands-on experiments.

Uploaded by

Aarna Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

SESSION : 2022-23

Lab Manual
SEM : 4th [EVEN]

Faculty Details

Name of the Faculty: L. N. Pandey

Designation: Asst. Professor

Department: Computer Science and Business System

Course Details

Name of the Program: B.Tech. Batch: 2021-2025

Branch: CSBS Semester: 3RD

Name of Subject: Java Lab Subject Code : AL-4-6

Course Name: Computer Science and Business Systems

Lab Manual AL-406 Java Lab Page 1


SESSION-2022-23
Index
SEM : 4th [EVEN]

LAB MANUAL FILE......................................................................................................................................................... 1

INDEX........................................................................................................................................................................... 2

VISION & MISSION OF INSTITUTE.................................................................................................................................. 3

VISION &MISSION OF DEPARTMENT............................................................................................................................. 4

PROGRAM EDUCATION OBJECTIVES.............................................................................................................................. 5

PROGRAM OUTCOMES................................................................................................................................................. 6

PROGRAM OUTCOMES.............................................................................................................................................................6

COURSE OUTCOMES..................................................................................................................................................... 7

MAPPING OF COURSE OUTCOMES WITH PROGRAM OUTCOMES...................................................................................8

SCHEDULE OF PRACTICAL LIST PERFORMED........................................................................................................ 10

EXPERIMENT 1............................................................................................................................................................ 13

EXPERIMENT 2............................................................................................................................................................ 14

EXPERIMENT 3............................................................................................................................................................ 15

EXPERIMENT 4............................................................................................................................................................ 16

EXPERIMENT 5............................................................................................................................................................ 17

EXPERIMENT 6............................................................................................................................................................ 18

EXPERIMENT 7............................................................................................................................................................ 19

EXPERIMENT 8............................................................................................................................................................ 20

EXPERIMENT 9............................................................................................................................................................ 21

EXPERIMENT 10.......................................................................................................................................................... 22

EXPERIMENT 11.......................................................................................................................................................... 23

EXPERIMENT 12.......................................................................................................................................................... 24

EXPERIMENT 13.......................................................................................................................................................... 25

EXPERIMENT 14.......................................................................................................................................................... 26

Lab Manual AL-406 Java Lab Page 2


SESSION : 2022-23
Vision & Mission of Institute
SEM : 4th [EVEN]

Vision of Institute:

Initially to seek autonomy and eventually grow the Institute into a renowned University by:

 Imparting the best technical and professional education to the students of the Institute.
 Developing all the Departments of the Institute as Centers of Excellence.
 Creating the most congenial and cordial environment of Teaching, Learning and Research in the
Institute.
 Conceiving world - class Education, Ethics and Employability for students in global perspective.

Mission of Institute

To explore and ensure the best environment to transform students into creative, knowledgeable,
principled engineers and managers compatible with their abilities in ever-changing socio-economic and
competitive scenario by:

 Imparting intensive teaching and training through latest technology


 Motivating the teachers for higher learning and innovative research activities with social services.
 Generating maximum opportunities for placement of students in National, Multi-National companies
and nurturing entrepreneurship quality.
 Producing highly intellectual citizens through technical education to constitute an elegant society
and meeting social challenges.

Lab Manual AL-406 Java Lab Page 3


SESSION : 2022-23
Vision &Mission Of
Department
SEM : 4th [EVEN]

Vision

 To be a center of Excellence in Computer science & Management offering fundamental and


advanced knowledge.

Mission

 To impart knowledge in the state of art in Computer science & Management with relevant
theoretical basics.
 To impart Quality education through well designed curriculum in tune with challenging
Software needs of the industry.
 To facilitate the development of academic-industry Collaboration.

Write a program that accepts two numbers from the user and print their sum.
Write a program to calculate addition of two number using prototyping of methods.
Program to demonstrate function overloading for calculation of average.
Program to demonstrating overloaded constructor for calculating box volume.
Program to show the detail of students using concept of inheritance.
Program to demonstrate package concept.
Program to demonstrate implementation of an interface which contains two methods declaration
square and cube.
Program to demonstrate exception handling in case of division by zero error.
Program to demonstrate multithreading.
Program to demonstrate JDBC concept using create a GUI based application for student information.
Program to display “Hello World” in web browser using applet.
Program to add user controls to applets.
Write a program to create an application using concept of swing.
Program to demonstrate student registration functionality using servlets with session management.

Lab Manual AL-406 Java Lab Page 4


SESSION : 2022-23
Program Education
Objectives
SEM : 4th [EVEN]

Program Education Objectives

 To ensure graduates will be proficient in utilizing the fundamental knowledge of


basic sciences, mathematics, Computer Science and Business systems for the
applications relevant to various streams of Engineering and Technology.

 To enrich graduates with the core competencies necessary for applying knowledge of
computer science and Data analytics tools to store, retrieve, implement and analyze
data in the context of business enterprise

 To enable graduates to gain employment in organizations and establish themselves


as professionals by applying their technical skills and leadership qualities to solve
real world problems and meet the diversified needs of industry, academia and
research

 To equip the graduates with entrepreneurial skills and qualities which help them to
perceive the functioning of business, diagnose business problems, explore the
entrepreneurial opportunities and prepare them to manage business efficiently.

Lab Manual AL-406 Java Lab Page 5


SESSION : 2022-23
Program Outcomes
SEM : 4th [EVEN]

Program Outcomes
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization for the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for public
health and safety, and cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of information to
provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools, including prediction and modeling to complex engineering activities, with an
understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with the society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

Lab Manual AL-406 Java Lab Page 6


SESSION : 2022-23
Course Outcomes
SEM : 4th [EVEN]

COURSE OUTCOMES

At the end of the course:-

CO1 Once the student has successfully completed this course, he/she will be able to:

CO 1. Understand and implement object oriented feature of java.

CO 2. Understand and implement window based application.

CO 3. Understand and implement exception handling mechanism.

CO 4. Understand and implement the concept of thread.

CO 5. Implement the concept of Database Connectivity in Java.

Lab Manual AL-406 Java Lab Page 7


SESSION : 2022-23
Syllabus
SEM : 4th [EVEN]

Course Objectives:

1. Understand fundamentals of programming such as variables, conditional and iterative execution,


methods, etc.
2. Understand fundamentals of object-oriented programming in Java and be familiar of the important
concepts like class, inheritance and multithreading, AWT and JDBC.
3. Students will able to use the Java SDK environment to create, debug and run simple Java programs.

Unit 1.
Overview of Java, Installation, First Simple Program, Compilation process, Java Keywords, Identifiers,
Literals, Comments, Data Types, Variables, Dynamic initialization, type conversion and casting, Operators,
Control Statements.

Unit 2.
Declaring Objects, Introducing Methods, Constructors, this Keyword, Garbage Collection, finalize Method,
Overloading Methods, Overloading Constructors, Using Objects as Parameters, Inheritance, Creating a
Multilevel Hierarchy, Packages and Interfaces, Exception Handling, Multithreading

Unit 3.
The Applet Class: Applet Basics, The Applet Class, Applet Architecture, Applet Initialization and
Termination , Simple Applet Display Methods, Simple Banner Applet, Using the Status Window, The
HTML APPLET Tag, Passing Parameters to Applets, Improving the Banner Applet.

Unit 4.
Introducing the AWT: Working with Windows, Graphics, and Text, AWT Classes, Window Fundamentals,
Component, Container, Panel, Frame, Working with Frame Windows, Handling Events in a Frame
Window, AWT Controls, Layout Managers, and Menus, Adding and Removing Controls, Grid Layout,
Border Layout, introduction to swing and servlet.

Unit 5.
Event Handling, Two Event Handling Mechanisms, The Delegation Event Model, Events, Event Sources,
Event Listeners, Event Classes, The Mouse Event Class and others, JDBC: JDBCODBC Bridge, the
connectivity model, the driver manager, navigating the resultset object contents, the JDBC exceptional
classes, connecting to remote database.

Reference Books:
1. E. Balagurusamy, “Programming with java A Primer”, McGrawHill.
2. Sharanam Shah, “ Core Java 8 for Beginners”, Shroff Publisher.
3. Naughton &Schildt, “The Complete Reference Java 2”, Tata McGraw Hill.
4. Horstmann& Cornell, “Core Java 2” (Vol I &II ), Pearson.

Lab Manual AL-406 Java Lab Page 8


SESSION : 2022-23
Mapping of Course
Outcomes with Program
SEM : 4th [EVEN]
Outcomes

Mapping of Program Educational Objective and Mission of the Department:

Key components From PEO 1 PEO 2 PEO 3 PEO4


Department Mission

(1) Empowering Graduates will Graduates will Graduates will adapt Graduates will
students with the state of practice their work as teams on in their profession pursue advanced
the art facilities and profession with multidisciplinary with social study and
knowledge for the confidence and projects with awareness, ethics and research.
welfare of the society global effective responsibility.
and the nation. competitiveness communication
and make skills and
(2) Prepare students as intellectual leadership
per the ever-changing contributions to it. qualities.
need of the industry.

(3) To inculcate into


ethical values in the
minds of emerging
engineers.

√ √
Quality education
√ √

Professional career √ √ √ √

Higher education √ √

Research √ √

Innovation and Creativity √ √

Technical and community √


services

Lifelong learning √ √

Lab Manual AL-406 Java Lab Page 9


Mapping of Course Outcomes and Program Outcomes:

Sr. Course
N Outcome PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
o

1 CO 1 H - M - M - - - - - - -

2 CO 2 H - M - M - - - L - M -

3 CO 3 H - M - H - - - - - - -

4 CO 4 H M M - M - - H - - - -

5 CO 5 H - M - H - - - - - M -

*H= High *M= Medium *L=Low

CO1.Write, compile, and execute Java programs that may include basic data types and control flow
constructs using J2SE or other Integrated Development Environments (IDEs) such as Eclipse, NetBeans,
and JDeveloper.

CO2. Write, compile and execute Java programs using object oriented class structures with parameters,
constructors, and utility and calculations methods, including inheritance, test classes and exception
handling.

CO3.Write, compile, and execute Java programs using various Collection classes.

CO4. Write, compile, and execute Java programs manipulating Strings and text documents.

CO5. Write, compile, execute Java programs that include GUIs and event driven programming. ()

Mapping of Program Specific Outcomes and Course Outcomes:

Course Outcomes
Program Specific Outcomes
1 2 3 4 5

1 L H H L L

2 - - L - -

3 - - - L -

*H= High *M= Medium *L=Low

Lab Manual AL-406 Java Lab Page 10


SESSION-2022-23
Schedule of Practical List
Performed
SEM : 4th [EVEN]

Batch A Batch B
Completi Completi
S. Name of Mappi Type Catego CO PO PSO on on Sig
N Experiment ng of Exp. ry Mappi Mappin Mappi n
o. with ng g ng
Unit

1 Write a I Study Core CO1 PO5,PO PSO2


program 12
that accepts
two
numbers
from the
user and
print their
sum.

2 Write a I Progra Core CO1 PO1, PSO1,


program to m PO5, PSO2
calculate PO12
addition of
two number
using
prototyping
of methods.

3 Program to I Progra CO1, PO1, PSO1,


demonstrate m CO2 PO3, PSO2
function Core PO5,
overloading PO12
for
calculation
of average.

4 Program to I Progra PO1, PSO 1,


demonstrati m PO3, PSO2
ng Core CO1, PO5,
overloaded CO2 PO12
constructor
for
calculating
box volume.

5 Program to I Progra PO1, PSO 1,


show the m PO3, PSO2
detail of Core CO1, PO5,
students CO2 PO12
using
concept of

Lab Manual AL-406 Java Lab Page 11


inheritance.

6 Program to I Progra Core PO1, PSO 1,


demonstrate m PO3, PSO2
package CO1, PO5,
concept. CO2 PO12

7 Program to I Progra PO1, PSO 1,


demonstrate m PO3, PSO2
implementat Core CO1, PO5,
ion of an CO2 PO12
interface
which
contains two
methods
declaration
square and
cube.

8 Program to I Progra PO1, PSO 1,


demonstrate m PO3, PSO2
exception Core CO1, PO5,
handling in CO2 PO12
case of
division by
zero error.

9 Program to II Progra Core PO1, PSO 1,


demonstrate m PO3, PSO2
multithreadi CO1 PO5,
ng. PO12

10 Program to II Progra PO1, PSO 1,


demonstrate m PO3, PSO2
JDBC Core CO1 PO5,
concept PO12
using create
a GUI based
application
for student
information.

11 Program to II Progra PO1, PSO 1,


display m PO3, PSO2
“Hello Core CO1, PO5,
World” in CO2 PO12
web browser
using applet

12 Program to IV Progra Core


add user m
controls to
applets.

13 Write a IV Progra Core


program to m
create an
application

Lab Manual AL-406 Java Lab Page 12


using
concept of
swing.

14 Program to II Progra Core


demonstrate m
student
registration
functionality
using
servlets with
session
management
.

Lab Manual AL-406 Java Lab Page 13


SESSION : 2022-23
Experiment 1
SEM : 4th [EVEN]

Write a program that accepts two numbers from the user and print their
sum.
import java.util.Scanner;
class Test
{ public static void main(String args[])
{ Scanner input = new Scanner(System.in);
int x, y, z;

System.out.print("Enter first integer value : ");


x = input.nextInt();

System.out.print("Enter first integer value : ");


y = input.nextInt();

z = x + y ;

System.out.println(x + " + " + y + " = " + z);


}
}

Lab Manual AL-406 Java Lab Page 14


SESSION : 2022-23
Experiment 2
SEM : 4th [EVEN]

Write a program to calculate addition of two number using prototyping of


methods.
import java.util.Scanner;
public class Exp02
{ public static void main(String args[])
{ Scanner input = new Scanner(System.in);
int x,y,z;

System.out.print("Enter first integer value : ");


x = input.nextInt();

System.out.print("Enter first integer value : ");


y = input.nextInt();

z = sum(x,y) ;

System.out.println(x + " + " + y + " = " + z);


}
static int sum(int a, int b)
{ int s;
s = a + b ;
return s;
}
}

Lab Manual AL-406 Java Lab Page 15


SESSION : 2022-23
Experiment 3
SEM : 4th [EVEN]

Program to demonstrate function overloading for calculation of average.


public class Exp03
{ public static void main(String args[])
{
System.out.println("Avg : " + avg(10,20));
System.out.println("Avg : " + avg(10,20,30));
System.out.println("Avg : " + avg(10,20,30,40));
}
static double avg(int a,int b)
{
return (a+b)/2;
}
static double avg(int a,int b,int c)
{
return (a+b+c)/3;
}
static double avg(int a,int b,int c,int d)
{
return (a+b+c+d)/4;
}
}

Lab Manual AL-406 Java Lab Page 16


SESSION : 2022-23
Experiment 4
SEM : 4th [EVEN]

Program to demonstrating overloaded constructor for calculating box


volume.
public class Exp04 {
public static void main(String args[]) {
Box a = new Box(10);
a.volume();
Box b = new Box(10, 20);
b.volume();
Box c = new Box(10, 20, 30);
c.volume();
}
}

class Box {
double l, b, h;

Box(double x) {
l = b = h = x;
}

Box(double x, double y) {
l = b = x;
h = y;
}

Box(double x, double y, double z) {


l = x;
b = y;
h = z;
}

void volume() {
System.out.println("Volume of Box " + l * b * h);
}
}

Lab Manual AL-406 Java Lab Page 17


SESSION : 2022-23
Experiment 5
SEM : 4th [EVEN]

Program to show the detail of students using concept of inheritance.


public class Exp05 {
public static void main(String args[]) {
Student e = new Student("KRISH", "RAM", "VIZAG", "9885098850", 10, 19,
'B', "IT");
e.display2();
}
}

class Person {
String name = new String();
String fname = new String();
String add = new String();
String phno = new String();

Person(String a, String b, String


phno = d;
}

void display() {
System.out.println("Name is " + name);
System.out.println("Address " + add);
System.out.println("Father's Name is " + fname);
System.out.println("Contact number " + phno);
}
}

class Student extends Person {


int roll, age;
char section;
String branch = new String();

Student(String a, String b, String c, String d, int e, int f, char g, String


h) {
super(a, b, c, d);
roll = e;
age = f;
section = g;
branch = h;
}

void display2() {
super.display();
System.out.println("Roll Number=" + roll);

Lab Manual AL-406 Java Lab Page 18


System.out.println("AGE=" + age);
System.out.println("SECTION=" + section);
System.out.println("Branch is " + branch);

Lab Manual AL-406 Java Lab Page 19


SESSION : 2022-23
Experiment 6
SEM : 4th [EVEN]

Program to demonstrate package concept.

package p; // Creation of package


import java.util.Scanner; // First way to import class from a
package
import java.io.*; // Second way to import class from package
class Exp06 {
public static void main(String args[]){
// Third way to import class from package.
java.lang.String str = "Example of Package";
System.out.println(str);
}
}

Lab Manual AL-406 Java Lab Page 20


SESSION : 2022-23
Experiment 7
SEM : 4th [EVEN]

Program to demonstrate implementation of an interface which contains two


methods declaration square and cube.

public class Exp07 {


public static void main(String args[]) {
Shapes shapes = new Shapes();
shapes.square(12);
shapes.cube(12);
}
}

interface Shape {
void square(int x);
void cube(int x);
}

class Shapes implements Shape {


public void square(int x) {
System.out.println("Area of Square is : "+ x*x);
}

public void cube(int x) {


System.out.println("Area of Cube is : "+ 6*x*x);
}
}

Lab Manual AL-406 Java Lab Page 21


SESSION : 2022-23
Experiment 8
SEM : 4th [EVEN]

Program to demonstrate exception handling in case of division by zero error.

import java.util.Scanner;
class Exp08 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int x,y,z;
try{
System.out.print("Enter first number : ");
x = input.nextInt();
System.out.print("Enter second number : ");
y = input.nextInt();

z = x / y ;
System.out.println(x + " / " + y + " = " + z);
}catch(ArithmeticException ae){
System.out.println("Can't Divide by Zero");
}
}
}

Lab Manual AL-406 Java Lab Page 22


SESSION : 2022-23
Experiment 9
SEM : 4th [EVEN]

Program to demonstrate multithreading.

class Simple1 extends Thread{


public void run(){
System.out.println("Performing task one");
}
}

class Simple2 extends Thread{


public void run(){
System.out.println("Performing task two");
}
}

class Exp09{
public static void main(String args[]){
Simple1 t1=new Simple1();
Simple2 t2=new Simple2();

t1.start();
t2.start();
}
}

Lab Manual AL-406 Java Lab Page 23


SESSION : 2022-23
Experiment 10
SEM : 4th [EVEN]

Program to demonstrate JDBC concept using GUI based application for


student information.

import java.sql.*;
public class FirstExample {
static final String DB_URL = "jdbc:mysql://localhost/MyDB";
static final String USER = "root";
static final String PASS = "root";
static String QUERY;
QUERY = "SELECT id, first, last, age FROM Employees";

public static void main(String[] args) {


// Open a connection
try{
Connection conn;
con = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);) {
// Extract data from result set
while (rs.next()) {
// Retrieve by column name
System.out.print("ID: " + rs.getInt("id"));
System.out.print(", Age: " + rs.getInt("age"));
System.out.print(", First: " +
rs.getString("first"));
System.out.println(", Last: " +
rs.getString("last"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

Lab Manual AL-406 Java Lab Page 24


Lab Manual AL-406 Java Lab Page 25
SESSION : 2022-23
Experiment 11
SEM : 4th [EVEN]

Program to display “Hello World” in web browser using applet.

Prerequisite:

1. Create an HTML File. With <Applet> Tag. Say Hello.html


2. Create Java Applet with Java. Say Exp10.java

Solution :

Program 1 :

<!--HTML File : Hello.html-->


<head>
<title>Hello World Applet</title>
</head>
<body>
<applet code="HelloWorld.class" width="200" height="200">
</applet>
</body>
</html>

Program 2.

// Java File : Exp10.java


import java.applet.Applet;
import java.awt.Graphics;
public class Exp10 extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World !", 10, 30);
}
}

Lab Manual AL-406 Java Lab Page 26


SESSION : 2022-23
Experiment 12
SEM : 4th [EVEN]

Program to add user controls to applets.

// Java File : Exp12.java


import java.awt.*;
import java.applet.Applet;
import java.awt.Graphics;
public class Exp12 extends Applet {
public void init(){
add(new Button("Click Me"));
add(new TextField("Hello",15));
add(new CheckBox("Check1"));
}
public void paint(Graphics g) {
g.drawString("Hello World !", 10, 30);
}
}

Lab Manual AL-406 Java Lab Page 27


SESSION : 2022-23
Experiment 13
SEM : 4th [EVEN]

Write a program to create an application using concept of swing.

public class Exp11 {


public static void main(String[] args) {
JFrame f = new JFrame();// creating instance of JFrame

JButton b = new JButton("click");// creating instance of


JButton
b.setBounds(130, 100, 100, 40);// x axis, y axis, width,
height

f.add(b);// adding button in JFrame

f.setSize(400, 500);// 400 width and 500 height


f.setLayout(null);// using no layout managers
f.setVisible(true);// making the frame visible
}
}

Lab Manual AL-406 Java Lab Page 28


SESSION : 2022-23
Experiment 14
SEM : 4th [EVEN]

Program to demonstrate student registration functionality using servlets


with session management.

// Import required java libraries


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

// Extend HttpServlet class


public class HelloWorld extends HttpServlet {

private String message;

public void init() throws ServletException {


// Do required initialization
message = "Hello World";
}

public void doGet(HttpServletRequest request,


HttpServletResponse response)
throws ServletException, IOException {

// Set response content type


response.setContentType("text/html");

// Actual logic goes here.


PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}

public void destroy() {


// do nothing.
}
}

Lab Manual AL-406 Java Lab Page 29

You might also like