SOURCE CODE:
[Link]
import [Link].*;
class sort
{
public static void main(String args[])throws IOException
{
int a[];
int p,n,c,t,i;
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter the number of element");
n=[Link]([Link]());
a=new int[n];
[Link]("Enter the "+n+" number");
for(i=0;i<n;i++)
{
a[i]=[Link]([Link]());
}
for(p=0;p<n-1;p++)
{
for(c=0;c<n-1-p;c++)
{
if(a[c]>a[c+1])
{
t=a[c];
a[c]=a[c+1];
a[c+1]=t;
}
}
}
[Link]("ASCENDING \t DESCENDING");
for(i=0;i<n;i++)
{
[Link](a[i]+"\t\t\t"+a[n-1-i]);
}
}
}
OUTPUT
SOURCE CODE:
[Link]
import [Link].*;
class alpha
{
public static void main(String args[])throws IOException
{
String name[],t;
int i,j,x,n;
DataInputStream ds=new DataInputStream([Link]);
[Link]("Enter the number of member");
n=[Link]([Link]());
name=new String[n];
[Link]("Enter the "+n+" name");
for(i=0;i<n;i++)
{
name[i]=[Link]();
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
x=name[j].compareTo(name[j+1]);
if(x>0)
{
t=name[j];
name[j]=name[j+1];
name[j+1]=t;
}
}
}
[Link]("ALPHABETICAL ORDER");
for(i=0;i<n;i++)
[Link](name[i]);
}
}
OUTPUT:
SOURCE CODE:
[Link]
import [Link].*;
class file
{
public static void main(String args[])throws IOException
{
int empno,salary;
String name,design;
int more;
FileOutputStream fos=new FileOutputStream("[Link]");
PrintWriter write=new PrintWriter(fos);
DataInputStream ds=new DataInputStream([Link]);
do
{
[Link]("Enter employee no:");
empno=[Link]([Link]());
[Link]("Enter employee name:");
name=([Link]());
[Link]("Enter employee salary no:");
salary=[Link]([Link]());
[Link]("Enter designation:");
design=([Link]());
[Link](empno+"\t" +name+ "\t" +design+"\t"+salary);
[Link]("add more records=1,exit=0");
more=[Link]([Link]());
}
while(more==1);
[Link]();
}
}
OUTPUT
SOURCE CODE
[Link]
import [Link].*;
class fileread
{
public static void main(String args[])throws IOException
{
int empno,salary;
String name,design;
FileInputStream fis=new FileInputStream("[Link]");
InputStreamReader isn=new InputStreamReader(fis);
StreamTokenizer tokens=new StreamTokenizer(isn);
while([Link]()!=tokens.TT_EOF)
{
empno=(int)[Link];
[Link]();
name=[Link];
[Link]();
salary=(int)[Link];
design=[Link];
[Link]();
salary=(int)[Link];
[Link](empno+" "+name+" "+salary+" "+design);
}
}
}
OUTPUT
SOURCE CODE:
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
class except
{
public static void main(String args[])throws IOException
{
int ch;
DataInputStream ds=new DataInputStream([Link]);
do
{
[Link]("menu");
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("Enter your choice");
ch=[Link]([Link]());
switch(ch)
{
case 1:
int a=5,b=0,c;
try
{
c=a/b;
[Link]("Result"+c);
}
catch(Exception e)
{
[Link]([Link]());
[Link]();
}
break;
case 2:
String s="abcds";
try
{
[Link]([Link](5));
}
catch(Exception e)
{
[Link]([Link]());
[Link]();
}
break;
case 3:
int x[]=new int[5];
try
{
[Link](x[5]);
}
catch(Exception e)
{
[Link]([Link]());
[Link]();
}
break;
case 4:
break;
}
}
while(ch<5);
}
}
OUTPUT:
SOURCE CODE:
[Link]
import [Link].* ;
public class jdbcquery
{
public static void main( String args[] )
{
try
{
[Link]( "[Link]" ) ;
Connection conn = [Link](
"jdbc:odbc:studentdsn" ) ;
Statement stmt = [Link]() ;
ResultSet rs = [Link]( "SELECT * FROM studenttable");
while( [Link]() )
{
[Link]( [Link](1) ) ;
[Link]( [Link](2) ) ;
}
[Link]() ;
[Link]() ;
[Link]() ;
}
catch( SQLException se )
{
[Link]( "SQL Exception:" ) ;
while( se != null )
{
[Link]( "State : " + [Link]() ) ;
[Link]( "Message: " + [Link]() ) ;
[Link]( "Error : " + [Link]() ) ;
se = [Link]() ;
}
}
catch( Exception e )
{
[Link]( e ) ;
}
}
}
OUTPUT:
Studenttable:
SOURCE CODE:
[Link]
import [Link].* ;
public class jdbcinsertstr
{
public static void main( String args[] )
{
int returnvalue,no1=105; String name1="sema";
try
{
[Link]( "[Link]" ) ;
Connection conn =
[Link]("jdbc:odbc:studentdsn" ) ;
Statement stmt = [Link]() ;
// insert into studenttable values(105,'sema');
String str1="insert into studenttable values("+no1+",'"+name1+"')";
returnvalue=[Link](str1);
[Link]("inserted "+returnvalue+" row in the database");
[Link]() ;
[Link]() ;
}
catch( SQLException se )
{
[Link]( "SQL Exception:" ) ;
while( se != null )
{
[Link]( "State : " + [Link]() ) ;
[Link]( "Message: " + [Link]() ) ;
[Link]( "Error : " + [Link]() ) ;
se = [Link]() ;
}
}
catch( Exception e )
{
[Link]( e ) ;
}
}
}
OUTPUT:
studenttable
SOURCE CODE:
[Link]
import [Link].* ;
public class jdbcupdate
{
public static void main( String args[] )
{
int returnvalue,no1=103; String name1="Vini";
try
{
[Link]( "[Link]" ) ;
Connection conn =
[Link]("jdbc:odbc:studentdsn" ) ;
Statement stmt = [Link]() ;
// update studenttable set studname='Meena' where studid=103;
String sqlbuffer="UPDATE studenttable set studname='"+name1+"'
where studid="+no1;
returnvalue=[Link](sqlbuffer);
[Link]("Updated "+returnvalue+" row in the database");
[Link]() ;
[Link]() ;
}
catch( SQLException se )
{
[Link]( "SQL Exception:" ) ;
while( se != null )
{
[Link]( "State : " + [Link]() ) ;
[Link]( "Message: " + [Link]() ) ;
[Link]( "Error : " + [Link]() ) ;
se = [Link]() ;
}
}
catch( Exception e )
{
[Link]( e ) ;
}
}
}
OUTPUT:
studenttable before updation:
Studenttable after updation:
SOURCE CODE:
[Link]
import [Link].*;
public class jdbcdelete
{
public static void main( String args[] )
{
int returnvalue,no1=103;
try
{
[Link]( "[Link]" ) ;
Connection conn = [Link](
"jdbc:odbc:studentdsn" ) ;
Statement stmt = [Link]() ;
String sqlbuffer="Delete from studenttable where studid="+no1;
[Link](sqlbuffer);
returnvalue=[Link](sqlbuffer);
[Link]("deleted "+returnvalue+" rows in the database");
[Link]() ;
[Link]() ;
}
catch( SQLException se )
{
[Link]( "SQL Exception:" ) ;
while( se != null )
{
[Link]( "State : " + [Link]() ) ;
[Link]( "Message: " + [Link]() ) ;
[Link]( "Error : " + [Link]() ) ;
se = [Link]() ;
}
}
catch( Exception e )
{
[Link]( e ) ;
}}}
OUTPUT:
studenttable before deletion:
Studenttable after deletion:
SOURCE CODE:
[Link]
import [Link].*;
import [Link].*;
public class jdpre
{
public static void main(String arg[])
{
DataInputStream x=new DataInputStream([Link]);
PreparedStatement ps; int rno;
try
{
[Link]("[Link]");
Connection con=[Link]("jdbc:odbc:studdsn");
[Link]("enter the no");
rno=[Link]([Link]());
[Link]("enter the name");
String sname=[Link]();
[Link]("enter the address");
String sadd=[Link]();
[Link]("enter the course");
String scourse=[Link]();
ps=[Link]("insert into studtable values(?,?,?,?)");
[Link](1,rno);
[Link](2,sname);
[Link](3,sadd);
[Link](4,scourse);
[Link]();
[Link]("1 row is inserted");
[Link]() ;
[Link]() ;
}
catch(Exception e)
{
[Link](e);
}}}
OUTPUT:
studtable:
SOURCE CODE:
[Link]
import [Link].*;
public class db
{
public static void main(String[] args)
{
try
{
[Link]("[Link]");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,
*.accdb)};DBQ=" + "g:\\[Link]";
Connection con = [Link](url);
[Link]("Connection Successful");
Statement select = [Link]();
ResultSet result = [Link]("SELECT * FROM student");
while ([Link]())
{
String rno = [Link](1);
String name = [Link](2);
String m1 = [Link](3);
String m2 = [Link](4);
[Link](rno + " " + name+" "+m1+" "+m2);
}
}
catch (Exception ex)
{
[Link]("Got an exception!");
[Link]([Link]());
}
}
}
OUTPUT:
studenttable:
SOURCE CODE:
[Link]
import [Link].*;
import [Link];
public class TreeExample
{
JFrame f;
TreeExample()
{
f=new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style");
DefaultMutableTreeNodecolor=new DefaultMutableTreeNode("color");
DefaultMutableTreeNode font=new DefaultMutableTreeNode("font");
[Link](color);
[Link](font);
DefaultMutableTreeNode red=new DefaultMutableTreeNode("red");
DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black=new DefaultMutableTreeNode("black");
DefaultMutableTreeNode green=new DefaultMutableTreeNode("green");
[Link](red); [Link](blue); [Link](black); [Link](green);
JTree jt=new JTree(style);
[Link](jt);
[Link](200,200);
[Link](true);
}
public static void main(String[] args)
{
new TreeExample();
}
}
OUTPUT:
SOURCE CODE:
[Link]
[Link].*;
import [Link].*;
public class TextFieldExampleact implements ActionListener
{
JTextField tf1,tf2,tf3;
JButton b1,b2;
TextFieldExampleact()
{
JFrame f= new JFrame();
[Link](JFrame.EXIT_ON_CLOSE);
tf1=new JTextField();
[Link](50,50,150,20);
tf2=new JTextField();
[Link](50,100,150,20);
tf3=new JTextField();
[Link](50,150,150,20);
[Link](false);
b1=new JButton("+");
[Link](50,200,50,50);
[Link](this);
[Link]().add(tf1);[Link]().(tf2);
[Link]().add(tf3);[Link]().add(b1);
f. setSize(300,300);
[Link]().setLayout(null);
f..setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s1=[Link]();
String s2=[Link]();
int a=[Link](s1);
int b=[Link](s2);
int c=0;
if([Link]()==b1){
c=a+b;
}
String result=[Link](c);
[Link](result);
}
public static void main(String[] args)
{
new TextFieldExampleact();
}
}
OUTPUT:
SOURCE CODE:
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class lab2 extends JFrame
{
private JLabel label1, label2, label3,label4,disp;
private JTextField t,t1;
private JRadioButton r4,r5,r6;
private JCheckBox r1, r2, r3;
private JButton b1,b2;
private ButtonGroup radioGroup;
public lab2()
{
super( "Testing JLabel" );
Container c = getContentPane();
[Link]( new FlowLayout() );
label1 = new JLabel( "ENTER YOUR NAME " );
disp= new JLabel( " " );
[Link]( label1 );
t = new JTextField( " ");
[Link]( t );
label2 = new JLabel( "ENTER YOUR AGE");
[Link]( label2 );
t1 = new JTextField( " ");
[Link]( t1 );
label3 = new JLabel();
[Link]( "SELECT YUOR S/W" );
[Link]( label3 );
r1 = new JCheckBox( "oracle", false );
[Link]( r1 );
r2 = new JCheckBox( "VB", false );
[Link]( r2 );
r3 = new JCheckBox( "Java", false );
[Link]( r3);
show();
label4 = new JLabel();
[Link]( "SELECT YUOR CITY" );
[Link]( label4 );
r4 = new JRadioButton( "Delhi", false);
[Link]( r4 );
r5 = new JRadioButton( "Mumbai", false );
[Link]( r5 );
r6 = new JRadioButton( "Culcutta", false );
[Link]( r6);
radioGroup = new ButtonGroup();
[Link]( r4 );
[Link]( r5 );
[Link]( r6 );
setSize( 500, 300 );
show();
b1=new JButton("OK");
b2=new JButton("cancel");
[Link](b1);
[Link](b2);
[Link](disp);
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link]("program will be processed\n");
}
});
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
[Link](" ");
[Link](" ");
[Link](" ");
}
});
public static void main( String args[] )
{
lab2 app = new lab2();
[Link]( new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
[Link]( 0 );
}
}
}
}
OUTPUT:
SOURCE CODE:
[Link]
import [Link].*;
public interface AddServerInt extends Remote
{
double add(double d1,double d2) throws RemoteException;
}
[Link]
import [Link].*;
import [Link].*;
public class AddServerImp extends UnicastRemoteObject implements
AddServerInt
{
public AddServerImp() throws RemoteException
{}
public double add(double d1,double d2) throws RemoteException
{
return d1+d2;
}
}
[Link]
import [Link].*;
import [Link].*;
public class AddServer
{
public static void main(String args[])
{
try{
AddServerImp addServer=new AddServerImp();
[Link]("AddServer",addServer);
}
catch(Exception e)
{
[Link]("Exception"+e);
}
}
}
[Link]
import [Link].*;
public class AddClient
{
public static void main(String args[])
{
try
{
String addServerURL="rmi://" + args[0] + "/AddServer";
AddServerInf addServer=(AddServerInf)[Link](addServerURL);
[Link]("First number is "+ args[1]);
double d1=[Link](args[1]).doubleValue();
[Link]("Second number is"+args[2]);
double d2=[Link](args[2]).doubleValue();
[Link]("Sum is"+[Link](d1,d2));
}
catch(Exception e)
{
[Link]("Exception e:"+[Link]());
}
}
}
\bin>javac [Link]
\bin>javac [Link]
\bin>javac [Link]
\bin>javac [Link]
\bin>rmic AddServerImp
\bin>rmiregistry
Open another command prompt:
\bin>java AddServer
Open another command prompt:
\bin>java AddClient localhost 5 8
OUTPUT:
First number is:5
Second number is:8
Sum is:13