0% found this document useful (0 votes)
29 views

Java Full

Uploaded by

aneeshshinde167
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Java Full

Uploaded by

aneeshshinde167
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SRNO PRACTICAL SIGNATUR

. E
1 Create a class and implement the concept of
constructor overloading

2 Create a class and implement the concept of


METHOD overloading
3 Create a class and implement the concept of
Inheritance.
4 Create a class and implement the concept of
Interface.
5

6 Write a program to create a calculator using


Servlet..

7 Write a program to develop Breshham’s


midpoint circle drawing algrothm.
8 Write a program to find the number of
cookies
PRACTICAL 1
Aim:- Create a class and implement the concept of constructor overloading

CODE:
package constructor;
public class Constructor
{
int value1;
int value2;

Constructor() {
value1 =10;
value2 =20;
System.out.println("inside Constructor");
}
public void display()
{
System.out.println("value1...." + value1);
System.out.println("value2...." + value2);
}
public static void main(String[] args) {
Constructor d1=new Constructor();
d1.display();
}

OUTPUT:
PRACTICAL 2
Aim:- Create a class and implement the concept of METHOD overloading .

CODE:
package method;
public class METHOD {
public int sum(int x, int y)
{
return(x+y);
}
public int sum(int x, int y, int z){
return(x+y+z);
}
public double sum (double x, double y)
{
return(x+y);
}
public static void main(String[] args)
{
METHOD s= new METHOD();
System.out.println(s.sum(10,20));
System.out.println(s.sum(10,20,30));
System.out.println(s.sum(10.5,20.5));
}

OUTPUT:
PRACTICAL 3
Aim:- Create a class and implement the concept of Inheritance.

Code:
package inheritence;
public class Inheritence {
public static void main(String[] args) {
AddSub obj= new AddSub();
obj.num1=5;
obj.num2=4;
obj.sum();
System.out.println(obj.result);
obj.sub();
System.out.println(obj.result);
obj.mult();
System.out.println(obj.result);
obj.div();
System.out.println(obj.result);
}
class Add {
int num1,num2,result;
public void sum()
{ result=num1 + num2; }
}
class AddSub extends Add
{
int num1, num2, result;
public void sum()
{ result=num1 + num2; }

public void sub()


{ result=num1 - num2; }
public void mult()
{ result=num1*num2; }
public void div()
{ result=num1/num2;}
}

Output:
PRACTICAL 4
Aim:- Create a class and implement the concept of Interface.

Code:
Interfaceexample.java

package interfaceexample;
public class Interfaceexample implements car {

public static void main(String[] args) {


Interfaceexample a = new Interfaceexample();
a.ignition(10);
a.display();

}
public void ignition(int fuel){
System.out.println("In Interfaceexample class");
System.out.println(isHybrid);
System.out.println(engineCapacity);
}

Car.java

package interfaceexample;

public interface car {


public int engineCapacity = 10;
public boolean isHybrid = false;
public void ignition(int fuel);
}

Output:
Practical6
AIM: write a program to create a calculator using Servlet.

Index.html
Code:

<html>
<head>
<title>Calculator App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="CalcServlet">
Enter First Number <input type="text" name="txtN1"><br>
Enter Second Number <input type="text" name="txtN2"><br>

Select Operation
<input type="radio" name="opr" value="+">Addition
<input type="radio" name="opr" value="-">Subtraction
<input type="radio" name="opr" value="*">Multiply
<input type="radio" name="opr" value="/">Division
<input type="reset">
<input type="submit" name="opr" value="Calculate">
</form>
</body>
</html>

CalcServlet.java
Code:
package pac;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CalcServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
out.println("<html><head>Servlet CalcServlet</html></head></title><body>");

double n1=Double.parseDouble(request.getParameter("txtN1"));
double n2=Double.parseDouble(request.getParameter("txtN2"));
double result=0;

String opr=request.getParameter("opr");
if(opr.equals("+")) result=n1+n2;
if(opr.equals("-")) result=n1-n2;
if(opr.equals("*")) result=n1*n2;
if(opr.equals("/")) result=n1/n2;
out.println("<h1>Result="+result);
out.println("</body></html>");
}
}

Output
PRACTICAL 7
AIM: Write a program to find the number of cookies
CODE:
Index.html
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="CookieCounter" method="get">
<input type="submit" value="Go To Servlet for Visit Counter/">
</form>
</body>
</html>
CookieCounter.java
package mypackage;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieCounter extends HttpServlet {
static int count=1;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try(PrintWriter out= response.getWriter())
{
String initialCount=String.valueOf(count);
Cookie myCookie=new Cookie("noOfVisit",initialCount);
response.addCookie(myCookie);
int cookieVal=Integer.parseInt(myCookie.getValue());
if(cookieVal==1)
{
out.println("welcome");
}
else
{
out.println("You visited <b>"+count+"</b> times");
}
count++;
}
}
}
OUTPUT:
Practical 8
Aim: Develop a simple JSP application to display values obtained from the
use of Intrinsic objects of various types.
Code:
Index.jsp
<%--
Document : index
Created on : Feb 14, 2024, 1:10:40 PM
Author : Machine014
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-
8">
<title>JSP Page</title>
</head>
<body>
<h1>Use of Intrinsic Objects in JSP</h1>
<h1> Request Object</h1>
Query String<%=request.getQueryString()%><br>
Context Path<%=request.getContextPath()%><br>
Remote Host<%=request.getRemoteHost()%><br>
<h1> Respond Object</h1>
Character Encoding Type <%=request.getCharacterEncoding()
%><br>
Content Type<%=request.getContentType()%><br>
Locale<%=request.getLocale()%><br>
<h1> Session Object</h1>
ID <%=session.getId()%><br>
creation Time <%=new java.util.Date(session.getCreationTime())
%><br>
Last Access Time <%=new
java.util.Date(session.getLastAccessedTime())%><br>

</body>
</html>
Output:

You might also like