You are on page 1of 20

Program No-1 Program for Commandline arguments


class Command { public static void main(String sr[]) { String st="jak"; System.out.println(st); int a=sr.length; for(int i=0;i<a;i++) { st=sr[i]; System.out.println(st); } } }


Mohit 805/IT/08D

Program No-2 Program to show Floyd series
class Floyd { public static void main(String args[]) { int i,j,k=1; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { System.out.print(k); k++; } System.out.print("\n"); } } }


Mohit 805/IT/08D

setName("DemoThread").println(i).println("current thread :="+t). /*try { for(int i=5. Thread. } } catch(InterruptedException e) { }*/ } } OUTPUT Mohit 805/IT/08D .out.out. //System.i>0.i--) { System.currentThread(). //t. System.out.println("the demo thread is :"+t).sleep(1000).Program No-3 Program to show Multithreading class MainThread1 { public static void main(String ar[]) { Thread t=Thread.

println("The addition is..out.x+y+m+c \t "+(x+y+m+c)).println(" the sum is .show(). } } interface D { int m=40. inter() { super().Program No-4 Program for implementing Interface class A { int x.. int y... b1..add().out. } void add() { int z=x+y. } } Mohit 805/IT/08D . y=12. System. b1. abstract void show(). } class inter extends A implements D { int c. } public void show() { System. A() { x=11.="+z). } public static void main(String ar[]) { inter b1=new inter(). c=30.

OUTPUT Mohit 805/IT/08D .

length.Program No-5 Program to show Stack Handling class stacki { int st[]=new int[8].out. } } } public static void main(String aa[]) { stacki s1=new stacki().out."+st[top]).. stacki() { top=-1. Mohit 805/IT/08D .println(st[j]).i<st. } else { top++. top--.out.out. st[top]=t.length. for(int i=0. } else { System. } void push(int t) { if(top==st. int top.i++) st[i]=0.j>=0. } } void pop() { if(top==-1) { System.length) { System. st[top]=0.println("stack is underflow"). int i=st.j--) { System. for(int j=top.println(" the top element of the stack is .println("stack is overflow").

s1. s1.push(10). s1.push(40).push(60). s1. s1. } } OUTPUT Mohit 805/IT/08D .pop().push(70).push(20).push(50). s1. s1. s1. s1.push(30). s1.pop().pop().push(80).char ch. s1.

out.3.22}.7.n++) System.println(" the arra b2 is "+b[2][1]).22.44.9}.5.55}}.55.8. int b[][]=new int [3][].println(" the arra c is "+b[0][n]).println(" the arra 2 is "+a[0][4]).13.88}. System. b[2]=new int[] {11.out.14}.33. int c= b[0].Program No-6 Program to show Collection Framework.length. for(int n=0. } } OUTPUT Mohit 805/IT/08D .println(" the arra b1 is "+b[1][3]).6.66. System.77. b[0]=new int []{12.out.{11. System. b[1]=new int[]{44.2.4.ArrayList class na { public static void main(String ar[]) { int a[][]={{1.out.n<c.

try { fout=new FileOutputStream("A1.println(" the character is .io.close().. dout.close(). fin =new FileInputStream("A1. dout.writeDouble(12.*. dout.readFloat()). dout."+din.."+din.readDouble()).writeInt(1200). System..out. System. FileOutputStream fout=null.writeChar('a'). class file1 { public static void main(String arr[]) throws IOException { FileInputStream fin=null. fout."+din.2f).txt")...11). } catch(Exception e) { } } } Mohit 805/IT/08D .writeBoolean(true)..readBoolean()).readChar()). dout. System. dout. fin.println(" the float is .out..close()."+din.out. din. System.close()..println(" the integer is .out."+din. DataOutputStream dout=new DataOutputStream(fout).println(" the boolean is . System.Program No-7 Program to show File handling import java..writeFloat(3. DataInputStream din=new DataInputStream(fin).out.txt").println(" the double is .readInt())..

OUTPUT Mohit 805/IT/08D .

Program No-8 Program for showing the use of stream classes import java.close(). } din.txt")).io.out.readLine().*. if(s!=null) System. class DataRead1 { public static void main(String args[]) throws IOException { DataInputStream din=new DataInputStream(new FileInputStream("k.println(s). String s=" ". } Output: Mohit 805/IT/08D . while(s!=null) { s=din.

Program No-9 Program for JDBC connectivity import it will ignore it //String t1="maya". Statement S= c. System.executeQuery("select * from Table1").getString(1)+" ") { System. } } } Mohit 805/IT/08D . class TestDB1 { public static void main(String s[]) { try { Class. while(result1.printStackTrace().println(" "). System.getString(2)+" ").odbc. System.out. //here system and manager are username and password not for excel for oracle etc.out.getString(3)+" ").createStatement(). Connection c=DriverManager. //int t=420. ResultSet result1=S.print("marks"+ result1.print("name"+ result1.JdbcOdbcDriver").forName("sun.out.print("rollno"+ result1.*. } } catch(Exception e) { e.jdbc.sql.getConnection("jdbc:odbc:anu")..

Output: Mohit 805/IT/08D .

//This is just to show the sequence of functions g. public void init() { s="init".awt..30). } public void paint(Graphics g) { s=s+"paint". public class TestApplet1 extends Applet { String s.30. s=s+"start"..awt.drawString(s.Program No-10 Program to create an Applet /* <applet code="TestApplet1" height=400 width=400> </applet> */ import java.out. } } Mohit 805/IT/08D . } public void start() { setBackground(Color.event.*. import java. } public static void main(String.applet. s) { System.*. import java.*.println("main").RED).

Output: Mohit 805/IT/08D .

show().out. public class Temp { public void show() { System. } } Output: Mohit 805/IT/08D . t1.Program No-11 Program for creating a package package p1.print("package 1"). } public static void main(String a[]) { Temp t1=new Temp1().

} } Mohit 805/IT/08D . do { s=ss. System. DataOutputStream dos. Socket s.writeUTF("hello" + str). }} public static void main(String s[]) throws Exception { new MyServer().flush().out.println("client connected"). public MyServer() { try { System.getInputStream()). dos. } catch(Exception e) { System. serverChat(). public class MyServer { ServerSocket ss.println(s).out. System.*. dos. dos=new DataOutputStream(s.println(e). } while(!str.out. dis=new DataInputStream(s. System. import java.getOutputStream()).out. ss=new ServerSocket(10).println("server started"). } public void serverChat() throws Exception { String str. DataInputStream dis.*.io.out.Program No-12 Program for Networking Code For Server import java.equals("stop")).accept().println("Client Message"+ str).

String s1. BufferedReader br=new BufferedReader(new InputStreamReader(System.Code For Client /*public Chatting*/ import java. dout=new DataOutputStream(s. } catch(Exception e) { System. import java. } public static void main(String s[]) { new MyClient().io. clientChat().10). public class MyClient { Socket s. } while(!s1.writeUTF(s1). } } class My implements Runnable { DataInputStream din.*.readLine(). dout. DataInputStream t1. Thread t1=new Thread(m).println(e). Mohit 805/IT/08D . dout. do { s1=br.equals("stop")).start(). DataOutputStream dout. public MyClient() { try { s=new Socket("localhost".*.getOutputStream()).in)).out. } } public void clientChat() throws IOException { My m=new My(din). din=new DataInputStream(s.flush().getInputStream()).

equals("stop")). } } Mohit 805/IT/08D . } public void run() { String s2=" ".println(s2). do { try { s2=din.out.readUTF(). System.My(DataInputStream din) { this. } catch(Exception e) {} } while(!s2.din=din.

Output: Mohit 805/IT/08D .