SlideShare a Scribd company logo
B.Tech CS
Object Oriented Techniques
Practical File
Sudeep Singh
Syntax Of Classes
♦♦ Simple class ♦♦
<class- keyword> <class- name>
{
<method- access specifier> <type- return/non_return> <method- name>()
{ operations }
}
♦♦ static top most class ♦♦
<static- keyword><class- keyword> <class- name>
{
<method- access specifier> <type- return/non_return> <method- name>()
{ operations }
}
♦♦ main class ♦♦
<class- keyword> <class- name>
{
public static void main (String [ ]s )
{
System.out.println(“Welcome In BHABHA GROUP OF INSTITUTION”) ;
}
}
♦♦1 program to add two number ♦♦
class sum
{
public static void main(String[]s)
{
int a,b,c;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
c=a+b;
System.out.println("sum = "+c);
} }
♦♦2 program to multiply two number ♦♦
class multi
{
public static void main(String[]s)
{
int a,b,c;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
c=a*b;
System.out.print("sum = "+c);
}
}
♦♦3 program to print factorial of any number ♦♦
class factorial
{
public static void main(String[]s)
{
int a,f=1;
a=Integer.parseInt(s[0]);
for(int i=a;i>=1;i--)
{ f=f*i; }
System.out.println("Factorial of n = "+f);
} }
♦♦4 program to find number is palindrom or not♦♦
class palindrom
{
public static void main(String[]s)
{
int a,b,c=0,d;
a=Integer.parseInt(s[0]);
d=a;
do
{ b=a%10;
c=c*10+b;
a=a/10; }
while(a>0);
if(d==c)
System.out.println("number is palindrom "+d);
else System.out.println("number is not palindrom "+d); } }
♦♦5 program to find out no.is Armstrong or not ♦♦
class armstrong
{
public static void main(String[]s)
{
int a,b,c=0,d;
a=Integer.parseInt(s[0]);
{
d=a;
do
{ b=a%10;
c=c+b*b*b;
a=a/10; }
while(a>0);
if(d==c)
System.out.println("number is armstrong "+d);
else System.out.println("number is not armstrong "+d); } } }
♦♦6 program to find out even & odd number ♦♦
class number
{
public static void main(String[]s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
for(int i=a;i<=b;i++)
{ if(i%2==0)
System.out.println("Number is even = "+i);
else System.out.println("Number is odd = "+i); } } }
♦♦7 program to print the table from “x” to “y”♦♦
class table
{
public static void main(String []s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
if(a<=b)
{
for(int i=a;i<=b;i++)
{
for(int j=1;j<=10;j++)
{
System.out.print(j*i+" ");
}
System.out.println(" ");
}}
else
{
for(int i=b;i<=a;i++)
{
for(int j=1;j<=10;j++)
{
System.out.print(j*i+" ");
}
System.out.println(" ");
}
}
}
}
♦♦ 8 program to print no. in various format ♦♦
class print
{
public static void main(String[]s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
for(int i=a;i<=b;i++)
{
for(int j=a;j<=i;j++)
{
System.out.print(" "+j);
}
System.out.println(" ");
} System.out.println(" ");
for(int i=b;i>=a;i--)
{
for(int j=a;j<=i;j++)
{
System.out.print(" "+j);
}
System.out.println(" ");
}
System.out.println(" ");
for(int i=b;i>=a;i--)
{
for(int j=b;j>=i;j--)
{
System.out.print(" "+j);
}
System.out.println(" ");
}
System.out.println(" ");
for(int i=a;i<=b;i++)
{
for(int j=b;j>=i;j--)
{
System.out.print(" "+j);
}
System.out.println(" ");
}
System.out.println(" ");
for(int i=a;i<=b;i++)
{
for(int j=i;j>=a;j--)
{
System.out.print(" "+j);
}
System.out.println(" ");
} System.out.println(" ");
for(int i=b;i>=a;i--)
{
for(int j=i;j>=a;j--)
{
System.out.print(" "+j);
} System.out.println(" ");
} } }
♦♦ 9 program Of Overriding ♦♦
class x
{
public void test(int a,int b )
{
int c= a + b ;
System.out.println("from class x sum ="+c);
}
}
class y extends x
{
public void test(int a,int b )
{
int c= a * b ;
System.out.println("from class y multiplication ="+c);
}
}
class overriding
{
public static void main(String [ ]s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
y obj=new y( );
obj.test(a,b);
}
}
♦♦ 10 program Of Overloading ♦♦
class x
{
public void test(int a, int b )
{
int c = a * b ;
System.out.println("multiplication of number = "+c);
} }
class y
{
public void test(int a, int b, int d )
{
int c= a + b + d ;
System.out.println("sum of given number = "+c);
} }
class overloading
{
public static void main (String [ ] s)
{
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
int d=Integer.parseInt(s[2]);
x obj = new x( );
obj.test(a ,b );
y obj1 = new y( );
obj1.test(a ,b ,d );
} }
♦♦11 Communication of class by creating object♦♦
class A
{
public void show( )
{
System.out.println("welcome from A");
}
}
class B
{
public void show1( )
{
A obj=new A( );
obj.show( );
}
}
class C
{
public static void main (String [ ] s)
{
B obj=new B( );
obj.show1( );
}
}
♦♦ 12 Communication of class by inheritance ♦♦
class A
{
public void show( )
{
System.out.println("welcome from A");
} }
class B extends A
{
public void show1( )
{
System.out.println("welcome from B");
} }
class D
{
public static void main (String [ ] s)
{
B obj = new B( );
obj.show( );
} }
♦ 13 Area of circle & rectangle using object ♦
class circle
{
public void area_c(int r )
{
int ar;
ar=r*r*22/7;
System.out.println("Area of circle= "+ar);
}
}
class rect
{
public void area_rec(int le, int br )
{
int ar;
ar=le*br;
System.out.println("Area of rectangle= "+ar);
}
}
class area
{
public static void main (String [ ] s)
{
int r=Integer.parseInt(s[0]);
int le=Integer.parseInt(s[1]);
int br=Integer.parseInt(s[2]);
circle obj=new circle( );
obj.area_c(r );
rect obj1=new rect( );
obj1.area_rec(le, br );
}
}
♦♦14 use of abstract class ♦♦
abstract class test
{
abstract public void show( );
{ }
}
class help extends test
{
public void show( )
{
System.out.println(" from class help ");
} }
class take extends test
{
public void show( )
{
System.out.println(" from class take ");
} }
class give extends test
{
public void show( )
{
System.out.println(" from class give ");
} }
class abstractdemo
{
public static void main (String [ ] s)
{
help obj=new help( );
obj.show( );
take obj1=new take( );
obj1.show( );
give obj2=new give( );
obj2.show( ); } }
♦♦ 15 use of package ♦♦
packagea;
public class a1
{ public void sum(inta, int b)
{ int c= a + b;
System.out.println("sum="+c); } }
packagea;
public class a5
{ public void fact(int a, int b)
{for(inti=a;i<=b;i++)
{ int f=1;
for(intj=i;j>=1;j--)
{ f=f*j; }
System.out.print("Factof "+i);
System.out.println("="+f); } } }
packagea;
public class a4
{ public void table(int a,int b)
{ for(int i=a;i<=b;i++)
{ System.out.print("tableof "+i);
System.out.print("=");
for(intj=1;j<=10;j++)
{ System.out.print(" "+j*i); }
System.out.println(" "); } } }
packagea;
public class a3
{ public void mul(int a, int b)
{ int c= a * b;
System.out.println("mul="+c); } }
packagea;
public class a2
{ public void sub(inta, int b)
{ if(a>b)
{ int c= a - b;
System.out.println("sub ="+c); }
else
{ int c= b - a;
System.out.println("sub ="+c); } } }
import a.*;
class cal
{ public static void main(String []s)
{ int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
a1 obj=new a1();
obj.sum(a,b);
a2 obj1=new a2();
obj1.sub(a,b);
a3 obj3=new a3();
obj3.mul(a,b);
a4 obj4=new a4();
obj4.table(a,b);
a5 obj5=new a5();
obj5.fact(a,b); } }
♦♦ 16 “try” and “catch” block ♦♦
class ab
{
public static void main(String [ ]s)
{
try
{
int i=Integer.parseInt(s[0]);
int j=Integer.parseInt(s[1]);
int k=i/j;
System.out.print("result="+k);
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦17 Userthread by extending Thread class ♦♦
class abc extends Thread
{
public abc()
{
start();
}
public void run()
{
try
{
for(int i=5;i<=9;i++)
{ System.out.print("table of "+i);
System.out.print("=");
for(int j=1;j<=10;j++)
{ System.out.print(" "+j*i); }
System.out.println(" ");
sleep(500);
}
}
catch(Exception e)
{System.out.print(e);}
}
}
class test
{
public static void main (String []s)
{
try
{
abc obj=new abc();
}
catch(Exception e)
{System.out.print(e);}
} }
♦♦18 multiplethread with join(); ♦♦
class sud extends Thread
{
String name;
public sud(String name)
{
this.name=name;
start();
}
public void run()
{
try
{
for(int i=0;i<5;i++)
{
System.out.println("name =" +" " +name +"=" +i);
sleep(500);
}
}
catch(Exception e)
{System.out.print(e);}
}
}
class main
{
public static void main(String []s)
{
try
{
sud one=new sud("first ");
sud sec=new sud("second");
sud third=new sud("third ");
sec.join();
one.join();
third.join();
for(int i=0;i<5;i++)
{
System.out.println("main = " +i);
}
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦19 Take input until char= ’z’ in io-package ♦♦
import java.io.*;
classabc
{
public static void main(String []s)
{
char c;
try
{
BufferedReader B=new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.print("enter until z =");
c=(char)B.read();
}
while(c!= 'z');
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦20 Take input until string=’off’ in io package
import java.io.*;
classabc
{
public static void main(String []s)
{
String l;
try
{
BufferedReader B=new BufferedReader(new
InputStreamReader(System.in));
do
{
l=B.readLine();
System.out.print("enter until off =");
if(l.equals ("off"))
{break;}
}
while(true);
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦21 Open a file in read mode in io-package ♦♦
import java.io.*;
class file
{
public static void main(String []s)
{
try
{
FileInputStream B=new FileInputStream("sud.txt");
while (B.read()!=-1)
{
char c=(char)B.read();
System.out.print(c);
}
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦22insert value in database ♦♦
importjava.sql.*;
class insert
{
public static void main(String []s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("Jdbc:Odbc:Contact_detail");
PreparedStatementpst=con.prepareStatement("insert into
values('abc' ,+918009000260,'abc@gmail.com')");
pst.close();
con.close();
}
catch(Exception e)
{System.out.print(e);}
}
}
♦♦23featch value from database ♦♦
importjava.sql.*;
classfeatch
{
public static void main(String []s1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("Jdbc:Odbc:Contact_detail");
Statement smt=con.createStatement();
ResultSetrs=smt.executeQuery("select * from emp");
while(rs.next())
{
int a=rs.getInt(1);
String s=rs.getString(2);
System.out.print(a +" " +s);
} }
catch(Exception e)
{System.out.print(e);}
}}
<HTML>
<from method=”get” action=”demo”>Enter the number : -
<input type="text" name="number"/><br>
<input type="submit" name="submit"/><br>
</form></html>
♦♦24Display Welcome with user Servlat♦♦
import java.io.*;
importjavax.servlet.*;
public class demo extends GenericServlet
{
publi void service(ServletRequestreq,ServletResponse res)
throws ServletException, IOexception
{
res.setContent Type("text/HTML");
PrintWriter out=res.getWriter();
for(inti=0;i<10;i++)
{
out.print("Welcome");
} } }
♦25receive data from HTML and cheak even/odd ♦
import java.io.*;
importjavax.servlet.*;
public class demo extends GenericServlet
{
publi void service(ServletRequestreq,ServletResponse res)
throws ServletException, IOexception
{
res.setContent Type("text/HTML");
PrintWriter out=res.getWriter();
int a=Interger.ParseInt(req.getParameter("number"));
if(a%2==0)
<html><form method="get" action="first">
Enter Name:-<input type="text" name="name"/><br><br>
Enter Password :- <input type="password" name="password"/><br><br>
<input type="submit" name="submit"/><br>
</form></html>
import java.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
public class firstextends GenericServlet
{
public void service(ServletRequestreq,ServletResponseres) throws
ServletException, IoException
{
RequestDispatcherrd=req.getRequestDispatcher("home")
res.setContentType("text/HTML");
PrintWriter out=res.getWriter();
String name=(String)req.getParameter("name");
String password=(String)req.getParameter("password");
if (name.equals("sudeep") &&password.equals("abc123"))
rd.forword(req, res)
out.print("Number is even = "+a);
else
out.print("Number is odd = "+a);
}}
♦♦ 26passing values between servlet ♦♦
“login.html”
“first.java”
import java.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
public class firstextends GenericServlet
{
publi void service(ServletRequestreq,ServletResponseres) throws
ServletException, IOexception
{
res.setContentType("text/HTML");
PrintWriter out=res.getWriter();
String n=(String)req.getAttribute("name");
String p=(String)req.getAttribute("password");
out.print("name="+n +" " +"password="+p));
}
}
“home.java”

More Related Content

What's hot

ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
guest9006ab
 
Pnno
PnnoPnno
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
C++ programs
C++ programsC++ programs
C++ programs
Mukund Gandrakota
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
Sayantan Sur
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
Mahmoud Samir Fayed
 
C programs
C programsC programs
C programs
Koshy Geoji
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
Germán Küber
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
jonbodner
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185
Mahmoud Samir Fayed
 
Advance java
Advance javaAdvance java
Advance java
Vivek Kumar Sinha
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
Ankit Dixit
 

What's hot (20)

ADA FILE
ADA FILEADA FILE
ADA FILE
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
C++ file
C++ fileC++ file
C++ file
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Pnno
PnnoPnno
Pnno
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C++ programs
C++ programsC++ programs
C++ programs
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
 
C programs
C programsC programs
C programs
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185The Ring programming language version 1.5.4 book - Part 10 of 185
The Ring programming language version 1.5.4 book - Part 10 of 185
 
Advance java
Advance javaAdvance java
Advance java
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
 

Similar to Java Program

Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
Soumya Behera
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
Karuppaiyaa123
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
100 Small programs
100 Small programs100 Small programs
100 Small programs
SHAZIA JAMALI
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
Abhishek Jena
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
hanumanthu mothukuru
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
kokah57440
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
VEERA RAGAVAN
 
Operators
OperatorsOperators
Operators
Daman Toor
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
eyewatchsystems
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
walia Shaan
 
JAVAPGMS.docx
JAVAPGMS.docxJAVAPGMS.docx
JAVAPGMS.docx
Mgm Mallikarjun
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
arishmarketing21
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 

Similar to Java Program (20)

Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
100 Small programs
100 Small programs100 Small programs
100 Small programs
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
 
Operators
OperatorsOperators
Operators
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
JAVAPGMS.docx
JAVAPGMS.docxJAVAPGMS.docx
JAVAPGMS.docx
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 

Recently uploaded

Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
dhavalvaghelanectarb
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
jrodriguezq3110
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
Softradix Technologies
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
chandangoswami40933
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
OnePlan Solutions
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 

Recently uploaded (20)

bgiolcb
bgiolcbbgiolcb
bgiolcb
 
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 

Java Program

  • 1. B.Tech CS Object Oriented Techniques Practical File Sudeep Singh
  • 2. Syntax Of Classes ♦♦ Simple class ♦♦ <class- keyword> <class- name> { <method- access specifier> <type- return/non_return> <method- name>() { operations } } ♦♦ static top most class ♦♦ <static- keyword><class- keyword> <class- name> { <method- access specifier> <type- return/non_return> <method- name>() { operations } } ♦♦ main class ♦♦ <class- keyword> <class- name> { public static void main (String [ ]s ) { System.out.println(“Welcome In BHABHA GROUP OF INSTITUTION”) ; } }
  • 3. ♦♦1 program to add two number ♦♦ class sum { public static void main(String[]s) { int a,b,c; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); c=a+b; System.out.println("sum = "+c); } } ♦♦2 program to multiply two number ♦♦ class multi { public static void main(String[]s) { int a,b,c; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); c=a*b; System.out.print("sum = "+c); } }
  • 4. ♦♦3 program to print factorial of any number ♦♦ class factorial { public static void main(String[]s) { int a,f=1; a=Integer.parseInt(s[0]); for(int i=a;i>=1;i--) { f=f*i; } System.out.println("Factorial of n = "+f); } } ♦♦4 program to find number is palindrom or not♦♦ class palindrom { public static void main(String[]s) { int a,b,c=0,d; a=Integer.parseInt(s[0]); d=a; do { b=a%10; c=c*10+b; a=a/10; } while(a>0); if(d==c) System.out.println("number is palindrom "+d); else System.out.println("number is not palindrom "+d); } }
  • 5. ♦♦5 program to find out no.is Armstrong or not ♦♦ class armstrong { public static void main(String[]s) { int a,b,c=0,d; a=Integer.parseInt(s[0]); { d=a; do { b=a%10; c=c+b*b*b; a=a/10; } while(a>0); if(d==c) System.out.println("number is armstrong "+d); else System.out.println("number is not armstrong "+d); } } } ♦♦6 program to find out even & odd number ♦♦ class number { public static void main(String[]s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); for(int i=a;i<=b;i++) { if(i%2==0) System.out.println("Number is even = "+i);
  • 6. else System.out.println("Number is odd = "+i); } } } ♦♦7 program to print the table from “x” to “y”♦♦ class table { public static void main(String []s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); if(a<=b) { for(int i=a;i<=b;i++) { for(int j=1;j<=10;j++) { System.out.print(j*i+" "); } System.out.println(" "); }} else { for(int i=b;i<=a;i++) { for(int j=1;j<=10;j++) { System.out.print(j*i+" "); } System.out.println(" "); } } } }
  • 7. ♦♦ 8 program to print no. in various format ♦♦ class print { public static void main(String[]s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); for(int i=a;i<=b;i++) { for(int j=a;j<=i;j++) { System.out.print(" "+j); } System.out.println(" "); } System.out.println(" "); for(int i=b;i>=a;i--) { for(int j=a;j<=i;j++) { System.out.print(" "+j); } System.out.println(" "); } System.out.println(" "); for(int i=b;i>=a;i--) { for(int j=b;j>=i;j--) { System.out.print(" "+j);
  • 8. } System.out.println(" "); } System.out.println(" "); for(int i=a;i<=b;i++) { for(int j=b;j>=i;j--) { System.out.print(" "+j); } System.out.println(" "); } System.out.println(" "); for(int i=a;i<=b;i++) { for(int j=i;j>=a;j--) { System.out.print(" "+j); } System.out.println(" "); } System.out.println(" "); for(int i=b;i>=a;i--) { for(int j=i;j>=a;j--) { System.out.print(" "+j); } System.out.println(" "); } } }
  • 9. ♦♦ 9 program Of Overriding ♦♦ class x { public void test(int a,int b ) { int c= a + b ; System.out.println("from class x sum ="+c); } } class y extends x { public void test(int a,int b )
  • 10. { int c= a * b ; System.out.println("from class y multiplication ="+c); } } class overriding { public static void main(String [ ]s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); y obj=new y( ); obj.test(a,b); } } ♦♦ 10 program Of Overloading ♦♦ class x { public void test(int a, int b ) { int c = a * b ; System.out.println("multiplication of number = "+c); } } class y { public void test(int a, int b, int d )
  • 11. { int c= a + b + d ; System.out.println("sum of given number = "+c); } } class overloading { public static void main (String [ ] s) { int a=Integer.parseInt(s[0]); int b=Integer.parseInt(s[1]); int d=Integer.parseInt(s[2]); x obj = new x( ); obj.test(a ,b ); y obj1 = new y( ); obj1.test(a ,b ,d ); } } ♦♦11 Communication of class by creating object♦♦ class A { public void show( ) { System.out.println("welcome from A"); } } class B { public void show1( )
  • 12. { A obj=new A( ); obj.show( ); } } class C { public static void main (String [ ] s) { B obj=new B( ); obj.show1( ); } } ♦♦ 12 Communication of class by inheritance ♦♦ class A { public void show( ) { System.out.println("welcome from A"); } } class B extends A { public void show1( ) { System.out.println("welcome from B"); } }
  • 13. class D { public static void main (String [ ] s) { B obj = new B( ); obj.show( ); } } ♦ 13 Area of circle & rectangle using object ♦ class circle { public void area_c(int r ) { int ar; ar=r*r*22/7; System.out.println("Area of circle= "+ar); } } class rect {
  • 14. public void area_rec(int le, int br ) { int ar; ar=le*br; System.out.println("Area of rectangle= "+ar); } } class area { public static void main (String [ ] s) { int r=Integer.parseInt(s[0]); int le=Integer.parseInt(s[1]); int br=Integer.parseInt(s[2]); circle obj=new circle( ); obj.area_c(r ); rect obj1=new rect( ); obj1.area_rec(le, br ); } } ♦♦14 use of abstract class ♦♦ abstract class test { abstract public void show( ); { } } class help extends test { public void show( ) { System.out.println(" from class help "); } }
  • 15. class take extends test { public void show( ) { System.out.println(" from class take "); } } class give extends test { public void show( ) { System.out.println(" from class give "); } } class abstractdemo { public static void main (String [ ] s) { help obj=new help( ); obj.show( ); take obj1=new take( ); obj1.show( ); give obj2=new give( ); obj2.show( ); } }
  • 16. ♦♦ 15 use of package ♦♦ packagea; public class a1 { public void sum(inta, int b) { int c= a + b; System.out.println("sum="+c); } } packagea; public class a5 { public void fact(int a, int b) {for(inti=a;i<=b;i++) { int f=1; for(intj=i;j>=1;j--) { f=f*j; } System.out.print("Factof "+i); System.out.println("="+f); } } } packagea; public class a4 { public void table(int a,int b) { for(int i=a;i<=b;i++) { System.out.print("tableof "+i); System.out.print("="); for(intj=1;j<=10;j++) { System.out.print(" "+j*i); } System.out.println(" "); } } } packagea; public class a3 { public void mul(int a, int b) { int c= a * b; System.out.println("mul="+c); } } packagea; public class a2 { public void sub(inta, int b) { if(a>b) { int c= a - b; System.out.println("sub ="+c); } else { int c= b - a; System.out.println("sub ="+c); } } }
  • 17. import a.*; class cal { public static void main(String []s) { int a=Integer.parseInt(s[0]); int b=Integer.parseInt(s[1]); a1 obj=new a1(); obj.sum(a,b); a2 obj1=new a2(); obj1.sub(a,b); a3 obj3=new a3(); obj3.mul(a,b); a4 obj4=new a4(); obj4.table(a,b); a5 obj5=new a5(); obj5.fact(a,b); } }
  • 18. ♦♦ 16 “try” and “catch” block ♦♦ class ab { public static void main(String [ ]s) { try { int i=Integer.parseInt(s[0]); int j=Integer.parseInt(s[1]); int k=i/j; System.out.print("result="+k); } catch(Exception e) {System.out.print(e);} } }
  • 19. ♦♦17 Userthread by extending Thread class ♦♦ class abc extends Thread { public abc() { start(); } public void run() { try { for(int i=5;i<=9;i++) { System.out.print("table of "+i); System.out.print("="); for(int j=1;j<=10;j++) { System.out.print(" "+j*i); } System.out.println(" "); sleep(500); } } catch(Exception e) {System.out.print(e);} } } class test { public static void main (String []s) { try { abc obj=new abc(); } catch(Exception e) {System.out.print(e);} } }
  • 20. ♦♦18 multiplethread with join(); ♦♦ class sud extends Thread { String name; public sud(String name) { this.name=name; start(); } public void run() { try { for(int i=0;i<5;i++) { System.out.println("name =" +" " +name +"=" +i); sleep(500); } } catch(Exception e) {System.out.print(e);} } } class main { public static void main(String []s) { try { sud one=new sud("first "); sud sec=new sud("second"); sud third=new sud("third "); sec.join(); one.join(); third.join(); for(int i=0;i<5;i++) { System.out.println("main = " +i); } } catch(Exception e) {System.out.print(e);} } }
  • 21.
  • 22. ♦♦19 Take input until char= ’z’ in io-package ♦♦ import java.io.*; classabc { public static void main(String []s) { char c; try { BufferedReader B=new BufferedReader(new InputStreamReader(System.in)); do { System.out.print("enter until z ="); c=(char)B.read(); } while(c!= 'z'); } catch(Exception e) {System.out.print(e);} } }
  • 23. ♦♦20 Take input until string=’off’ in io package import java.io.*; classabc { public static void main(String []s) { String l; try { BufferedReader B=new BufferedReader(new InputStreamReader(System.in)); do { l=B.readLine(); System.out.print("enter until off ="); if(l.equals ("off")) {break;} } while(true); } catch(Exception e) {System.out.print(e);} } }
  • 24. ♦♦21 Open a file in read mode in io-package ♦♦ import java.io.*; class file { public static void main(String []s) { try { FileInputStream B=new FileInputStream("sud.txt"); while (B.read()!=-1) { char c=(char)B.read(); System.out.print(c); } } catch(Exception e) {System.out.print(e);} } }
  • 25. ♦♦22insert value in database ♦♦ importjava.sql.*; class insert { public static void main(String []s) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("Jdbc:Odbc:Contact_detail"); PreparedStatementpst=con.prepareStatement("insert into values('abc' ,+918009000260,'abc@gmail.com')"); pst.close(); con.close(); } catch(Exception e) {System.out.print(e);} } } ♦♦23featch value from database ♦♦ importjava.sql.*; classfeatch { public static void main(String []s1) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("Jdbc:Odbc:Contact_detail"); Statement smt=con.createStatement(); ResultSetrs=smt.executeQuery("select * from emp"); while(rs.next()) { int a=rs.getInt(1); String s=rs.getString(2); System.out.print(a +" " +s); } } catch(Exception e) {System.out.print(e);} }}
  • 26. <HTML> <from method=”get” action=”demo”>Enter the number : - <input type="text" name="number"/><br> <input type="submit" name="submit"/><br> </form></html> ♦♦24Display Welcome with user Servlat♦♦ import java.io.*; importjavax.servlet.*; public class demo extends GenericServlet { publi void service(ServletRequestreq,ServletResponse res) throws ServletException, IOexception { res.setContent Type("text/HTML"); PrintWriter out=res.getWriter(); for(inti=0;i<10;i++) { out.print("Welcome"); } } } ♦25receive data from HTML and cheak even/odd ♦ import java.io.*; importjavax.servlet.*; public class demo extends GenericServlet { publi void service(ServletRequestreq,ServletResponse res) throws ServletException, IOexception { res.setContent Type("text/HTML"); PrintWriter out=res.getWriter(); int a=Interger.ParseInt(req.getParameter("number")); if(a%2==0)
  • 27. <html><form method="get" action="first"> Enter Name:-<input type="text" name="name"/><br><br> Enter Password :- <input type="password" name="password"/><br><br> <input type="submit" name="submit"/><br> </form></html> import java.io.*; importjavax.servlet.*; importjavax.servlet.http.*; public class firstextends GenericServlet { public void service(ServletRequestreq,ServletResponseres) throws ServletException, IoException { RequestDispatcherrd=req.getRequestDispatcher("home") res.setContentType("text/HTML"); PrintWriter out=res.getWriter(); String name=(String)req.getParameter("name"); String password=(String)req.getParameter("password"); if (name.equals("sudeep") &&password.equals("abc123")) rd.forword(req, res) out.print("Number is even = "+a); else out.print("Number is odd = "+a); }} ♦♦ 26passing values between servlet ♦♦ “login.html” “first.java”
  • 28. import java.io.*; importjavax.servlet.*; importjavax.servlet.http.*; public class firstextends GenericServlet { publi void service(ServletRequestreq,ServletResponseres) throws ServletException, IOexception { res.setContentType("text/HTML"); PrintWriter out=res.getWriter(); String n=(String)req.getAttribute("name"); String p=(String)req.getAttribute("password"); out.print("name="+n +" " +"password="+p)); } } “home.java”