SlideShare a Scribd company logo
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
ADVANCE JAVA LAB
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
Experiment No: 01
AIM:A. Program for printing hello word:
B.Program for printing system Date & Time JSP/SERLET:
A.class Hello{
public static void main (String args[])
{
System.out.println("Java Hello World");
}
}
B. <%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
<html>
<head>
<title>Display Current Date & Time</title>
</head>
<body>
<center>
<h1>Display Current Date & Time</h1>
</center>
<%
Date date = new Date();
out.print( "<h2 align="center">" +date.toString()+"</h2>");
%>
</body>
</html>
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
Experiment No: 02
AIM: Write a server side program for finding factorial of number.
import java.io.*;
class Factorial
{
publicstaticvoid main(String args[])
{
String str;
int no,fact;
fact=1;
try{
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter number whose Factorial is to be found : ");
System.out.flush();
str=obj.readLine();
no=Integer.parseInt(str);
while(no > 0)
{
fact=fact*no;
no=no-1;
}
System.out.println("FACTORIAL of a given number is : "+fact);
}
catch(Exception e)
{}
}
Experiment No: 03
AIM: . Write a Server side program in JSP/SERVLET for performing Addition of two no
accept numbers from client side by using HTML form
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
import java.util.Scanner;
class AddNumbers
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers = "+z);
}
}
Experiment No: 04
AIM: Write a Server side program in JSP/SERVLET for calculating the simple interest accept
the necessary parameters from client side by using.
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
<%--
Document : interest
Created on : 30 Oct, 2012, 10:30:44 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
Now we have to create the page "intjsp.jsp" to calculate interest
Code for this "intjsp.jsp" page ::
Document : intjsp
Created on : 30 Oct, 2012, 10:41:10 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><br><br><center><pre><H1>
<%
String ns= request.getParameter("principle");
String ns1= request.getParameter("year");
String ns2= request.getParameter("interest");
int n1=Integer.parseInt(ns);
int n2=Integer.parseInt(ns1);
int n3=Integer.parseInt(ns2);
double si=((n1*n2*n3)/100);
double x;
x=n1+si;
%>
<%
out.println("Principal= "+n1);
out.println(" Years= "+n2);
out.println(" Rate of Interest= "+n3);
out.println("<br> ");
out.println(" Simple Interest= "+si);
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
out.println(" Simple Interest= "+x);
%>
</H1>
</pre>
</center>
</body> </body>
</html>
Experiment No: 05
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
AIM: Write a Server side program in JSP/SERVLET for solving Quadratic Equation
accept necessary parameters from HTML form
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Quad Solver</title>
</head>
<body>
<FORM action="GreetingServlet" method="POST">
Quadratic Equation Solver for Equations in the form of
Ax^2 + Bx + C<BR>
<BR>
Enter the value of A: <INPUT type="text" name="A" size="15"><BR>
Enter the value of B: <INPUT type="text" name="B" size="15"><BR>
Enter the value of C: <INPUT type="text" name="C" size="15"><BR>
<br>
<input type="submit" value="Calculate!">
<br>
<BR>
<BR>
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
</FORM>
</body>
</html>
GreetingServlet.java
package com.mycompany.servlet;
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 GreetingServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GreetingServlet() {
super();
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String A = request.getParameter("A").toString();
String B = request.getParameter("B").toString();
String C = request.getParameter("C").toString();
double a = Double.parseDouble(A);
double b = Double.parseDouble(B);
double c = Double.parseDouble(C);
double D = QuadraticSolver.getD();
double[] roots = QuadraticSolver.quadratic();
out.println("<html>");
out.println("<head>");
out.println("<title>Quadratic Equation Solver</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Quadratic Equation Solver </h1>");
out.println("<h2>Your Equation is: <br><br>" + A + "x^2 + " + B + "x + " + C+
"<br>");
//QuadraticSolver solver = new QuadraticSolver ();
out.println("</h2>");
//double D = QuadraticSolver.getD();
if (a == 0.0)
out.println("<br>This is not a Quadratic quation ! ");
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
if (b == 0.0)
out.println("<br>There is no solution ! ");
if (a > 0.0 && b > 0) {
out.println("<br><br>There is only 1 solution -C/B : " );
out.println("<br><br>Your Solution is : - "+ c + " / " + b + " equals" + -c/b );
out.println("<br><br> X1 = "+ roots[0] );
out.println("<br><br> X2 = "+ roots[1] );
if(roots !=null){
out.println("<br><br>Solutions are:<br><br> X1 = " + roots[0] + " or X2 = " +
roots[1]+"<br>");
}
Else
{
out.println("<br><br>There Are No Real Solutions !!");
}
out.println("</h2>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
}
QuadraticSolver.java
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
package com.mycompany.servlet;
import static java.lang.StrictMath.*;
public class QuadraticSolver {
static double a;
static double b;
static double c;
//double D;
double discriminant = 0.0;
double root1;
double root2;
static double[] quadratic() {
double a = 0;
double b = 0;
double c = 0;
// Return the roots of the quadratic equation
double[] roots = new double[2];
double D = Math.pow(b, 2) - (c*1)*(-c);
if (D<0) {
System.out.println("There are no real roots");
System.out.println(D);
return roots;
}
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
// Use Viete's formula to avoid loss of significance
//double q = -0.5 * (b + copySign(sqrt(d), b));
/roots[0] = q/a;
//roots[1] = c/q;
//return roots;
//roots[0]=-b/2/a+Math.pow(Math.pow(b,2)-4*a*c,0.5)/2/a;
roots[0] = ((-b + sqrt(D)) / (2 * a));
return roots;
}
static double getD() {
double D=0;
D = b * b - 4.0f * a * c;
return D;
}
public static void main(String[] args) {
//double D=0;
// D = Math.pow(b, 2) - (c*a)*(-c);
double D = QuadraticSolver.getD();
double[] roots = quadratic();
System.out.println(roots[0]);
System.out.println(roots[1]);
}
My Directory structure:
MyFirstServlet
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
Deployment descriptor:MyFirstServlet
Java Resources :src
Com.mycompany.servlet
GreetingServlet.java
QuadraticSolver.Java
Libraries
Java Script resources
Build
WebContent
META-INF
WEB-INF
Classes
Lib
Web.xml
Index.jsp
Experiment No: 06
AIM: Write a Server side program in JSP/SERVLET for Income Tax Calculation
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Calculate Interest JSP</title>
</head>
<body>
<%
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String gender = request.getParameter("gender");
String profession = request.getParameter("profession");
String prefix = " ";
if (gender.equals("Male")) { prefix = "Mr."; }
else if (gender.equals("Female")) { prefix = "Ms."; } %>
<FONT COLOR = "Blue">Hello <%=prefix
%>&nbsp;<%=fname%>&nbsp;<%=lname%> &nbsp; who works in a
<%=profession %></FONT>
<% String sincome = request.getParameter("income");
float income = Float.parseFloat(sincome);
out.println("<BR>Your Annual Income is <FONT COLOR = Blue> " +income +
"</FONT>");
float tax;
float diff;
if(income <= 100000)
{
out.println("<BR>You are below the Tax Bracket!!");
}
else if(income >100000 && income <= 200000)
{
out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.2,00000");
out.println("<BR><B><U> Tax Rule: </U></B>10% of income above Rs.1
Lakh");
diff = income - 100000;
tax = (float)0.1*diff;
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+
"</FONT>");
}
else if(income >200000 && income <= 300000)
{
out.println("<BR>Your Tax Bracket is between between Rs.1,00000 to
Rs.3,00000");
out.println("<BR><B><U>Tax Rule: </U></B> 10% of income upto Rs.1 Lakh
and 20% of rest of income");
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
diff = income - 200000;
tax = (float)0.2*diff + (float)0.1*100000;
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+
"</FONT>");
}
else if(income >100000 && income <= 400000)
{
out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.4,00000");
out.println("<BR><B><U>Tax Rule: </U></B>10% of income upto Rs.1 Lakh
20% of income upto Rs.3 Lakh and 30% of rest of income");
diff = income - 300000;
tax = (float)0.3*diff + (float)0.2*200000 + (float)0.1*100000;
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax);
}
else if(income > 400000)
{
out.println("<BR>You fall in the tax bracket greater than Rs.4,00000");
diff = income - 400000;
tax = diff + (float)0.3*300000 + (float)0.2*200000 + (float)0.1*100000;
out.println("<BR><B><U>Tax Rule:</U></B> 10% of income upto Rs.1 Lakh
20% of income upto 3Lakh, 30% of income upto Rs.4 lakh and 100% of rest of
income");
out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+
"</FONT>");
}//end if %>
</body>
</html>
Experiment No: 07
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
AIM: Program:Write a server side JSP/SERVLET program for checking prime number,
accept number from html file handover the no to JSP/Servlet file process it and return the
result.
<%--
Document : index
Created on : 12 Oct, 2012, 7:35:11 PM
Author : nested code team
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><br><br><center>
<form action="primejsp.jsp ">
<h1>Enter the no :: <input type=text name=n ><br><br>
<input type=submit value="Submit"></h1>
</form></center>
</body>
</html>
Now we have to create the page "primejsp.jsp" to calculate interest
Code for this "intjsp.jsp" page ::
<%--
Document : primejsp
Created on : 31 Oct, 2012, 11:59:34 AM
Author :NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><center><h1>The required Result is:: </h1>
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
<h2>
<% int n,i,flag=0;
String ns= request.getParameter("n");
n=Integer.parseInt(ns);
if(n>1)
{
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
}
if(flag==0)
{
out.println("<pre>");
out.println(n+" is a prime no.");
out.println("</pre>");
}
else
{
out.println("<pre>");
out.println(n+" is not a prime no.");
out.println("</pre>");
}
%>
</h2></center>
</body>
</html>
The Outpur will be like ::
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha
Experiment No: 08
AIM: WAP for swapping of two numbers.
package swap;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int a,b;
System.out.println("Enter the two numbers: ");
Scanner s= new Scanner(System.in);
a = s.nextInt();
b = s.nextInt();
System.out.println("Number before swapping:" +a+" " +b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("Number after swapping:" +a+" " +b);
}
}
SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.)
CSE/8th
/Advance JavaLab/PreparedbyVivekKumarSinha

More Related Content

DOC
COMPUTER GRAPHICS LAB MANUAL
PDF
Computer Graphics Lab
DOC
SE Computer, Programming Laboratory(210251) University of Pune
DOCX
Graphics practical lab manual
PDF
Computer graphics lab manual
DOCX
Computer graphics lab assignment
DOC
Computer graphics
PDF
Computer graphics lab manual
COMPUTER GRAPHICS LAB MANUAL
Computer Graphics Lab
SE Computer, Programming Laboratory(210251) University of Pune
Graphics practical lab manual
Computer graphics lab manual
Computer graphics lab assignment
Computer graphics
Computer graphics lab manual

What's hot (20)

DOCX
Computer Graphics Lab File C Programs
DOCX
Cg my own programs
PDF
Computer graphics practical(jainam)
PDF
Basics of Computer graphics lab
DOCX
Computer graphics
PDF
Computer graphics lab report with code in cpp
PPTX
Introduction to graphics programming in c
DOCX
Computer graphics
PPT
computer graphics practicals
DOCX
Wap in c to draw a line using DDA algorithm
DOC
Practical Class 12th (c++programs+sql queries and output)
DOCX
DAA Lab File C Programs
PDF
PPT
Lecture on graphics
PPT
Struct examples
DOCX
Computer graphics programs in c++
DOCX
C graphics programs file
DOCX
Computer Graphics Lab File C Programs
Cg my own programs
Computer graphics practical(jainam)
Basics of Computer graphics lab
Computer graphics
Computer graphics lab report with code in cpp
Introduction to graphics programming in c
Computer graphics
computer graphics practicals
Wap in c to draw a line using DDA algorithm
Practical Class 12th (c++programs+sql queries and output)
DAA Lab File C Programs
Lecture on graphics
Struct examples
Computer graphics programs in c++
C graphics programs file
Ad

Viewers also liked (19)

PDF
Untitled Presentation
PDF
מצגת סטודנטים מבוא ליחבל בר אילן
PDF
Sophie Scholl
PDF
= よちよちrbLT大会レポートるびま投稿振り返り
PDF
Sistim semi hydroponic dalam pembibitan tebu
PDF
Luta pelos teus ideais
PDF
Universidade de conhecimento
DOC
Lab manualsahu[et&amp;t]
DOC
DOC
Dbms lab Manual
PDF
Sophie Scholl
DOC
Cse 7 softcomputing lab
PPSX
Presentasi
PPTX
Net neutrality
PPTX
Crimes Of Pakistan Army Pt-3
PPTX
Introduction to JavaScript Programming
DOC
DBMS Practical File
PDF
BUKU PELAJARAN TENTANG SISTEM PENCERNAAN MAKANAN
PDF
JavaScript Programming
Untitled Presentation
מצגת סטודנטים מבוא ליחבל בר אילן
Sophie Scholl
= よちよちrbLT大会レポートるびま投稿振り返り
Sistim semi hydroponic dalam pembibitan tebu
Luta pelos teus ideais
Universidade de conhecimento
Lab manualsahu[et&amp;t]
Dbms lab Manual
Sophie Scholl
Cse 7 softcomputing lab
Presentasi
Net neutrality
Crimes Of Pakistan Army Pt-3
Introduction to JavaScript Programming
DBMS Practical File
BUKU PELAJARAN TENTANG SISTEM PENCERNAAN MAKANAN
JavaScript Programming
Ad

Similar to Advance java (20)

DOCX
Java PRACTICAL file
PDF
Java Week1(A) Notepad
PDF
Microsoft word java
PDF
Howto get input with java
PPS
JSP Error handling
DOCX
Import java
PPTX
JCalc:Calculations in java with open source API
PDF
Integration Project Inspection 3
PPT
Presentation
PDF
JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer
PDF
Java 스터디 강의자료 - 1차시
PPTX
oops practical file.pptx IT IS A PRACTICAL FILE
DOC
Advanced Java - Praticals
DOCX
java experiments and programs
DOCX
Web lab programs
DOCX
Assignment DetailsYou have learned that some markets are compet.docx
PPT
presentation on java server pages vs servlet.ppt
PPTX
Lecture no 3
PPTX
02. Data Types and variables
PDF
Java programs
Java PRACTICAL file
Java Week1(A) Notepad
Microsoft word java
Howto get input with java
JSP Error handling
Import java
JCalc:Calculations in java with open source API
Integration Project Inspection 3
Presentation
JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer
Java 스터디 강의자료 - 1차시
oops practical file.pptx IT IS A PRACTICAL FILE
Advanced Java - Praticals
java experiments and programs
Web lab programs
Assignment DetailsYou have learned that some markets are compet.docx
presentation on java server pages vs servlet.ppt
Lecture no 3
02. Data Types and variables
Java programs

More from Vivek Kumar Sinha (20)

DOCX
Software engg unit 4
DOCX
Software engg unit 3
DOCX
Software engg unit 2
DOCX
Software engg unit 1
DOCX
Data structure
PPTX
Mathematics basics
PDF
E commerce 5_units_notes
DOCX
Subject distribution
DOCX
Revision report final
DOC
Lession plan mis
DOC
Lession plan dmw
DOC
Faculty planning
PPT
Final presentation on computer network
DOCX
Np syllabus summary
PPT
Internet of things
PPT
Induction program 2017
PDF
E magzine et&amp;t
DOC
Mechanical engineering department (1)
Software engg unit 4
Software engg unit 3
Software engg unit 2
Software engg unit 1
Data structure
Mathematics basics
E commerce 5_units_notes
Subject distribution
Revision report final
Lession plan mis
Lession plan dmw
Faculty planning
Final presentation on computer network
Np syllabus summary
Internet of things
Induction program 2017
E magzine et&amp;t
Mechanical engineering department (1)

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
additive manufacturing of ss316l using mig welding
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Project quality management in manufacturing
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPT
Total quality management ppt for engineering students
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPT
Mechanical Engineering MATERIALS Selection
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Current and future trends in Computer Vision.pptx
PPT
introduction to datamining and warehousing
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Internet of Things (IOT) - A guide to understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
additive manufacturing of ss316l using mig welding
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Project quality management in manufacturing
Foundation to blockchain - A guide to Blockchain Tech
Fundamentals of safety and accident prevention -final (1).pptx
Total quality management ppt for engineering students
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Mechanical Engineering MATERIALS Selection
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Current and future trends in Computer Vision.pptx
introduction to datamining and warehousing
Embodied AI: Ushering in the Next Era of Intelligent Systems
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT 4 Total Quality Management .pptx
Internet of Things (IOT) - A guide to understanding

Advance java

  • 1. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha ADVANCE JAVA LAB
  • 2. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha Experiment No: 01 AIM:A. Program for printing hello word: B.Program for printing system Date & Time JSP/SERLET: A.class Hello{ public static void main (String args[]) { System.out.println("Java Hello World"); } } B. <%@ page import="java.io.*,java.util.*, javax.servlet.*" %> <html> <head> <title>Display Current Date & Time</title> </head> <body> <center> <h1>Display Current Date & Time</h1> </center> <% Date date = new Date(); out.print( "<h2 align="center">" +date.toString()+"</h2>"); %> </body> </html>
  • 3. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha Experiment No: 02 AIM: Write a server side program for finding factorial of number. import java.io.*; class Factorial { publicstaticvoid main(String args[]) { String str; int no,fact; fact=1; try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter number whose Factorial is to be found : "); System.out.flush(); str=obj.readLine(); no=Integer.parseInt(str); while(no > 0) { fact=fact*no; no=no-1; } System.out.println("FACTORIAL of a given number is : "+fact); } catch(Exception e) {} } Experiment No: 03 AIM: . Write a Server side program in JSP/SERVLET for performing Addition of two no accept numbers from client side by using HTML form
  • 4. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha import java.util.Scanner; class AddNumbers { public static void main(String args[]) { int x, y, z; System.out.println("Enter two integers to calculate their sum "); Scanner in = new Scanner(System.in); x = in.nextInt(); y = in.nextInt(); z = x + y; System.out.println("Sum of entered integers = "+z); } } Experiment No: 04 AIM: Write a Server side program in JSP/SERVLET for calculating the simple interest accept the necessary parameters from client side by using.
  • 5. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha <%-- Document : interest Created on : 30 Oct, 2012, 10:30:44 PM Author : NESTED CODE --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> Now we have to create the page "intjsp.jsp" to calculate interest Code for this "intjsp.jsp" page :: Document : intjsp Created on : 30 Oct, 2012, 10:41:10 PM Author : NESTED CODE --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body><br><br><center><pre><H1> <% String ns= request.getParameter("principle"); String ns1= request.getParameter("year"); String ns2= request.getParameter("interest"); int n1=Integer.parseInt(ns); int n2=Integer.parseInt(ns1); int n3=Integer.parseInt(ns2); double si=((n1*n2*n3)/100); double x; x=n1+si; %> <% out.println("Principal= "+n1); out.println(" Years= "+n2); out.println(" Rate of Interest= "+n3); out.println("<br> "); out.println(" Simple Interest= "+si);
  • 6. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha out.println(" Simple Interest= "+x); %> </H1> </pre> </center> </body> </body> </html> Experiment No: 05
  • 7. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha AIM: Write a Server side program in JSP/SERVLET for solving Quadratic Equation accept necessary parameters from HTML form index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Quad Solver</title> </head> <body> <FORM action="GreetingServlet" method="POST"> Quadratic Equation Solver for Equations in the form of Ax^2 + Bx + C<BR> <BR> Enter the value of A: <INPUT type="text" name="A" size="15"><BR> Enter the value of B: <INPUT type="text" name="B" size="15"><BR> Enter the value of C: <INPUT type="text" name="C" size="15"><BR> <br> <input type="submit" value="Calculate!"> <br> <BR> <BR>
  • 8. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha </FORM> </body> </html> GreetingServlet.java package com.mycompany.servlet; 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 GreetingServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public GreetingServlet() { super(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  • 9. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String A = request.getParameter("A").toString(); String B = request.getParameter("B").toString(); String C = request.getParameter("C").toString(); double a = Double.parseDouble(A); double b = Double.parseDouble(B); double c = Double.parseDouble(C); double D = QuadraticSolver.getD(); double[] roots = QuadraticSolver.quadratic(); out.println("<html>"); out.println("<head>"); out.println("<title>Quadratic Equation Solver</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Quadratic Equation Solver </h1>"); out.println("<h2>Your Equation is: <br><br>" + A + "x^2 + " + B + "x + " + C+ "<br>"); //QuadraticSolver solver = new QuadraticSolver (); out.println("</h2>"); //double D = QuadraticSolver.getD(); if (a == 0.0) out.println("<br>This is not a Quadratic quation ! ");
  • 10. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha if (b == 0.0) out.println("<br>There is no solution ! "); if (a > 0.0 && b > 0) { out.println("<br><br>There is only 1 solution -C/B : " ); out.println("<br><br>Your Solution is : - "+ c + " / " + b + " equals" + -c/b ); out.println("<br><br> X1 = "+ roots[0] ); out.println("<br><br> X2 = "+ roots[1] ); if(roots !=null){ out.println("<br><br>Solutions are:<br><br> X1 = " + roots[0] + " or X2 = " + roots[1]+"<br>"); } Else { out.println("<br><br>There Are No Real Solutions !!"); } out.println("</h2>"); out.println("</body>"); out.println("</html>"); out.close(); } } } QuadraticSolver.java
  • 11. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha package com.mycompany.servlet; import static java.lang.StrictMath.*; public class QuadraticSolver { static double a; static double b; static double c; //double D; double discriminant = 0.0; double root1; double root2; static double[] quadratic() { double a = 0; double b = 0; double c = 0; // Return the roots of the quadratic equation double[] roots = new double[2]; double D = Math.pow(b, 2) - (c*1)*(-c); if (D<0) { System.out.println("There are no real roots"); System.out.println(D); return roots; }
  • 12. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha // Use Viete's formula to avoid loss of significance //double q = -0.5 * (b + copySign(sqrt(d), b)); /roots[0] = q/a; //roots[1] = c/q; //return roots; //roots[0]=-b/2/a+Math.pow(Math.pow(b,2)-4*a*c,0.5)/2/a; roots[0] = ((-b + sqrt(D)) / (2 * a)); return roots; } static double getD() { double D=0; D = b * b - 4.0f * a * c; return D; } public static void main(String[] args) { //double D=0; // D = Math.pow(b, 2) - (c*a)*(-c); double D = QuadraticSolver.getD(); double[] roots = quadratic(); System.out.println(roots[0]); System.out.println(roots[1]); } My Directory structure: MyFirstServlet
  • 13. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha Deployment descriptor:MyFirstServlet Java Resources :src Com.mycompany.servlet GreetingServlet.java QuadraticSolver.Java Libraries Java Script resources Build WebContent META-INF WEB-INF Classes Lib Web.xml Index.jsp Experiment No: 06 AIM: Write a Server side program in JSP/SERVLET for Income Tax Calculation <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  • 14. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Calculate Interest JSP</title> </head> <body> <% String fname = request.getParameter("fname"); String lname = request.getParameter("lname"); String gender = request.getParameter("gender"); String profession = request.getParameter("profession"); String prefix = " "; if (gender.equals("Male")) { prefix = "Mr."; } else if (gender.equals("Female")) { prefix = "Ms."; } %> <FONT COLOR = "Blue">Hello <%=prefix %>&nbsp;<%=fname%>&nbsp;<%=lname%> &nbsp; who works in a <%=profession %></FONT> <% String sincome = request.getParameter("income"); float income = Float.parseFloat(sincome); out.println("<BR>Your Annual Income is <FONT COLOR = Blue> " +income + "</FONT>"); float tax; float diff; if(income <= 100000) { out.println("<BR>You are below the Tax Bracket!!"); } else if(income >100000 && income <= 200000) { out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.2,00000"); out.println("<BR><B><U> Tax Rule: </U></B>10% of income above Rs.1 Lakh"); diff = income - 100000; tax = (float)0.1*diff; out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>"); } else if(income >200000 && income <= 300000) { out.println("<BR>Your Tax Bracket is between between Rs.1,00000 to Rs.3,00000"); out.println("<BR><B><U>Tax Rule: </U></B> 10% of income upto Rs.1 Lakh and 20% of rest of income");
  • 15. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha diff = income - 200000; tax = (float)0.2*diff + (float)0.1*100000; out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>"); } else if(income >100000 && income <= 400000) { out.println("<BR>Your Tax Bracket is between Rs.1,00000 to Rs.4,00000"); out.println("<BR><B><U>Tax Rule: </U></B>10% of income upto Rs.1 Lakh 20% of income upto Rs.3 Lakh and 30% of rest of income"); diff = income - 300000; tax = (float)0.3*diff + (float)0.2*200000 + (float)0.1*100000; out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax); } else if(income > 400000) { out.println("<BR>You fall in the tax bracket greater than Rs.4,00000"); diff = income - 400000; tax = diff + (float)0.3*300000 + (float)0.2*200000 + (float)0.1*100000; out.println("<BR><B><U>Tax Rule:</U></B> 10% of income upto Rs.1 Lakh 20% of income upto 3Lakh, 30% of income upto Rs.4 lakh and 100% of rest of income"); out.println("<BR>Tax to be paid is <FONT COLOR = Blue> "+tax+ "</FONT>"); }//end if %> </body> </html> Experiment No: 07
  • 16. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha AIM: Program:Write a server side JSP/SERVLET program for checking prime number, accept number from html file handover the no to JSP/Servlet file process it and return the result. <%-- Document : index Created on : 12 Oct, 2012, 7:35:11 PM Author : nested code team --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body><br><br><center> <form action="primejsp.jsp "> <h1>Enter the no :: <input type=text name=n ><br><br> <input type=submit value="Submit"></h1> </form></center> </body> </html> Now we have to create the page "primejsp.jsp" to calculate interest Code for this "intjsp.jsp" page :: <%-- Document : primejsp Created on : 31 Oct, 2012, 11:59:34 AM Author :NESTED CODE --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body><center><h1>The required Result is:: </h1>
  • 17. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha <h2> <% int n,i,flag=0; String ns= request.getParameter("n"); n=Integer.parseInt(ns); if(n>1) { for(i=2;i<=n/2;i++) { if(n%i==0) { flag=1; break; } } } if(flag==0) { out.println("<pre>"); out.println(n+" is a prime no."); out.println("</pre>"); } else { out.println("<pre>"); out.println(n+" is not a prime no."); out.println("</pre>"); } %> </h2></center> </body> </html> The Outpur will be like ::
  • 18. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha Experiment No: 08 AIM: WAP for swapping of two numbers. package swap; import java.util.*; public class Main { public static void main(String[] args) { int a,b; System.out.println("Enter the two numbers: "); Scanner s= new Scanner(System.in); a = s.nextInt(); b = s.nextInt(); System.out.println("Number before swapping:" +a+" " +b); a=a+b; b=a-b; a=a-b; System.out.println("Number after swapping:" +a+" " +b); } }
  • 19. SHRI RAWATPURA SARKAR INSTITUTEOF TECHNOLOGY ,NEWRAIPUR (C.G.) CSE/8th /Advance JavaLab/PreparedbyVivekKumarSinha