| Sr. No. |
NAME OF PROGRAM | DATE | REMARK | ||
| 1. | Write a program to print the series | | | ||
| 2. | Write a program to print factorial of a number | | | ||
| 3. | Write a program to reverse the number | | | ||
| 4. | Write a program to show inheritance | | | ||
| 5. | Write a program to show abstract class and method | | | ||
| 6. | Write a program to explain inner class | | | ||
| 7. | Write a program to explain interface | | | ||
| 8. | Write a program to show JDBC | | | ||
| 9. | Write a program to built a sevlet | | | ||
| 10. | Writa a program to make a swing servelet | | |
Faculty’s Signature
1.WAP to print the series .
class abc
{
public static void main ( String args[ ] )
{
int n = integer.parseint(args[0]);
for(int i=0;i<n;i++)
{
System.out.println();
for(int j=0;j<=I;j++)
{
System.out.print(“*”);
}
}
}
}
Output :
javac Abc.java
java Abc 3
*
* *
* * *
2.WAP to find factorial of a number.
class Fact
{
public static void main ( String args[ ] )
{
int fact = 1;
int n = Integer.parseInt(args[0]);
if(n>0)
{
fact = fact * n;
n--;
}
System.out.println(“ Factorial = ”+fact);
}
}
Output :
javac Fact.java
java Fact 5
Factorial = 120
3.WAP to reverse a number.
import java.util.*;
class Reverse
{
public static void main ( String args[ ] )
{
int n;
Scanner sc = new Scanner(System.in);
System.out.println(“ Enter the number ”);
n = sc.nextInt();
int s=0,k;
while(n != 0)
{
k=n%10;
s=(s*10)+k;
n=n/10;
}
System.out.println(“ Reversed number = ”+s);
}
}
Output :
javac Reverse.java
java Reverse 125
Reversed number = 521
4.WAP to show Inheritance.
class A
{
int a=10, b=10;
public void X( )
{ System.out.println(“ a = ”+a+” b = ”+b); }
private void Y()
{
a=30;
System.out.println(“ a = ”+a);
}
}
class B extends A
{
int i=10,j=30 ;
super.x();
public void x()
{
System.out.println(“ i = ”+ I +” j = ”+ j);
}}
class C{
public static void main(String args[ ])
{
B ob = new B();
ob.x();
}}
Output:
a=10
b=10
i=10
j=30
5.WAP to show abstract class and method
abstract class A
{
abstract void callme();
void callmetoo()
{
System.out.println(“hello”);
}
}
}
class B extends A
{
void callme()
{
System.out.println(“hi”);
}
}
class Abstractdemo
{
public static void main(String s[])
{
B b=new B();
b.callme();
b.callmetoo();
}
}
Output:
Hi
Hello
6.WAP to explain INNER CLASS
class Outer
{
int outer_n=100;
void test()
{
Inner inner=new Inner();
inner.display();
}
class Inner
{
void display()
{
system.out.println(“data of outer class”+outer_n);
}
}
}
class Test
{
public static void main(string s[])
{
Outer outer1 = new Outer();
outer1.test();
}
}
Output:
Data of outer class 100
7.WAP to explain Interface
class Num2
{
public int a,b;
public Num2(int a,int b)
{
this.a=a;
this.b=b;
}
public int g2()
{ return a>b?a:b; } }
class Num3 extends Num2
{
private int c;
public Num3(int a,int b,int c)
{
super(a,b);
this.c=c;
}
public int g3()
{ return g2()>c?g2():c; }}
class Test
{
public static void main(String s[])
{
Num3 x= new Num3(6,7,8);
System.out.println(x.g3());
System.out.println(x.g2());
}
}
Output:
8
7
8.WAP to show JDBC
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
class Connection extends JFrame implements ActionListener
{
JFrame f=new JFrame(“Employee”);
JTextfield t1=new JTextfield( );
JTextfield t2=new JTextfield( );
JTextfield t3=new JTextfield( );
public connection()
{
JPanel p=new JPanel( );
JLabel l1=new JLabel( “Employee_id”);
JLabel l2=new JLabel( “Department”);
JLabel l3=new JLabel( “Project”);
JButton b1=new JButton(“SAVE”);
JButton b2=new JButton(“CANCEL”);
f.getContentPane().add(p);
p.setLayout(null);
p.add(l1);
l1.setBounds(100,50,150,40);
p.add(l2);
l2.setBounds(100,150,150,40);
p.add(l3);
l3.setBounds(100,200,150,40);
p.add(t1);
t1.setBounds(300,55,150,30);
p.add(t2);
t2.setBounds(300,155,150,30);
p.add(t3);
t3.setBounds(300,255,150,30);
p.add(b1);
b1.setBounds(200,500,80,40);
p.add(b2);
b2.setBounds(350,800,80,40);
f.setSize(1000,600);
f.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void ActionPerformed(ActionEvent e)
{
if(e.getActioncommand( )==”SAVE”)
{ try {
class.forName(“Sun.jdbc.odbc.JdbcOdbcDriver”);
Connection cn=DriverManager.getConnection(“jdbc:odbc:Employee:Database”);
Prepared statement sc=cn.prepared statement(“insert intoEmployee(Employee_id,Department,Project)values(?,?,?)”);
String Employee_id=t1.getText();
String Department=t2.getText();
String Project=t3.getText();
sc.setInt(1,Integer.parseInt(Employee_id));
sc.setString(2,Department);
sc.setString(3,Project);
sc.executeUpdate( );
JOptionPane.showMessageDialog(f,”values inserted”);
cn.close( );
catch(Exception e)
{
System.out.println("ERROR"+e);
System.out.println( “values inserted are incorrect”);
}
}
if(e.getActioncommand( )==”CANCEL”)
{
t1.setText( “ ” );
t2.setText( “ ” );
t3.setText( “ ” );
}}
public static void main(String s[])
{ new connection( ); } }
9.WAP to build a Servlet
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoServlet extends GenericServlet
{
public void service(servletRequest req,servletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>");
out.println("hello Servlet");
out.println("</body></html>");
}
}
10.WAP to make a SWING APPLET
import java.awt.*;
import javax.swing.*;
import javax Swing.JApplet.*;
public class Test extends JApplet implements ActionListener
{
public JLabel label1=new JLabel(“Swing Applet”);
public JPanel panel=new JPanel;
public JButton but1=new JButton(“ON”);
public JButton but2=new JButton(“OFF”);
public void int()
{
panel.add(label1);
panel.add(but1);
panel.add(but2);
but1.add ActionListener(this);
but2.add ActionListener(this);
}
Public void actionPerformed(ActionEvent e)
{
If(e.getSource==but1)
Label1.setVisible(true);
Else
Label1.setVisible(false);
}
}
Html body
<html>
<applet code=test,width=200,height=600>
</applet>
</html>
Output:
|
|

