Sie sind auf Seite 1von 48

Java Programming Lab Manual

LIST OF EXPERIMENTS
1. 2. 3. 4. Write a Program to Input a String and display it on screen. Write a Program to compute the area of a circle using variables. Write a Program to add two numbers using Command Line Arguments. Write a Program to check whether the given number is Even or Odd using if-else statement. 5. Write a Program to determine the season of a particular month . 6. Write a Program to display menu (Add, Sub. Mul, Div) using switch statement. 7. Write a Program to find the factorial of a given number using while statement. 8. Write a Program to reverse a 5digit number and calculate sum of its digits using for statement. 9. Write a Program to that uses continue to print a triangular multiplication for 1 to 4. 1 24 369 4 8 12 16 10. Write a Program to sort a list of 7 numbers in ascending order . 11. Write a Program to generate a Floyd triangle using 2D array. 0 12 345 6789 12. Write a Program to make a class and introduce methods and fields. 13. Write a Program to create a class using constructor statements. 14. Write a Program to demonstrate the fundamentals of inner class. 15. Write a Program to inherit the property of one class into another. 16. Write a Program to inherit the property of a base class in derived class using super statement. 17. Write a Program to make a package. 18. Write a Program to handle Arithmetic exception using try - catch statement. 19. Write a Program to implement nested try - catch statements. 20. Write a Program to create thread and control main thread. 21. Write a Program to create multiple threads. 22. Write a Program to display This is an Applet string on an applet. 23. Write a Program to make a simple moving banner applet. 24. Write a Program to implement URL class on applet. 25. Write a Program to display IP address of a system. 26. Write a Program to display hostname of a system. 27. Write a Program to display protocol, hostname, port & file name of a system. 28. Write a Program for chatting using tcp/ip socket 29. Write a Program to set the AWT component controls. 30. Write a Program to insert, delete, and update a table using JDBC-ODBC connection.

INTRODUCTION TO JAVA
Java language was developed by Sun Microsystem in the year 1991 as a part of green project.

GREEN PROJECT:
a research group was working to develop software to control consumer electronics devices, during this time they developed a device called " star 7" for which the operating system was planned to be developed in "c++" however one of the team member "James Gosling " was not very satisfy with the performance of c++ hence he developed a new language for start he named it as "oak" .he used to see an oak outside his office in 1995 Sun Microsystem renamed this language as java. FEATURES OF JAVA: 1) Object Oriented Programming 2) Platform Independent 3) Robust 4) Reliable, Safe & Secure 5) Compiler and Interpreter 6) Dynamic 7) Multithreaded 8) High perfomance 9) Portable 10) Simple & Easy to learn Object Oriented
o o

Object oriented throughout - no coding outside of class definitions, including main(). An extensive class library available in the core language packages.

Platform Independence
o

The Write-Once-Run-Anywhere ideal has not been achieved (tuning for different platforms usually required), but closer than with other languages.

Robust
o

Exception handling built-in, strong type checking (that is, all data must be declared an explicit type), local variables must be initialized.

Security
o o o

No memory pointers Programs runs inside the virtual machine sandbox. Array index limit checking

security manager - determines what resources a class can access such as reading and writing to the local disk Compiler/Interpreter
o o o

Code is compiled to bytecodes that are interpreted by a Java virtual machines (JVM) . This provides portability to any machine for which a virtual machine has been written. The two steps of compilation and interpretation allow for extensive code checking and improved security.

Dynamic Binding
o o o

The linking of data and methods to where they are located, is done at runtime. New classes can be loaded while a program is running. Linking is done on the fly. Even if libraries are recompiled, there is no need to recompile code that uses classes in those libraries. This differs from C++, which uses static binding. This can result in fragile classes for cases where linked code is changed and memory pointers then point to the wrong addresses.

High Performance
o

Interpretation of bytecode slowed performance in early versions, but advanced virtual machines with adaptive and just-in-time compilation and other techniques now typically provide performance up to 50% to 100% the speed of C++ programs.

Threading
o o o

Lightweight processes, called threads, can easily be spun off to perform multiprocessing. Can take advantage of multiprocessors where available Great for multimedia displays.

What is the Java Virtual Machine? The JVM is the software that executes Java bytecode. A Java program, written in a file with a .java extension, is compiled into class files that have a .class extension. The class files are written in bytecode. To execute these files, the computer uses the JVM to interpret the bytecode. A browser that is capable of executing Java applets has the JVM built into it. To run a Java application, the Java Runtime Environment (JRE) must be installed. The JRE contains the files in the Java Development Kit minus the development tools, only the files necessary to run a Java application are present. The bytecode is the same for all platforms, but the JVM will be different on different platforms because it needs to execute programs using the native code of the machine it is running on. Development Tools: The development tools provide everything you'll need for compiling, running, monitoring, debugging, and documenting your applications. As a new developer, the main tools you'll be using are the javac compiler, the java launcher, and the javadoc documentation tool.

What is an Object Object is instance of class, it contain data as well as behavior of the functions how to manipulate that data. What is a Class Class is a collection of similar objects. A class is a blueprint or prototype from which objects are created.

EXPERIMENT NO. 1
Aim : - Write a program to Input a String and display it on screen
Explanation :- This is a simple program in java to display strings. Program :class first { public static void main(String str[]) { String s=String.valueOf(str[0]); System.out.println("your input is----------> "+s); } } Output:-

Viva -Voice Questions: 1. 2. 3. 4. What do you mean by object oriented programming. What is the difference between java and c++. What is class. What is object.

EXPERIMENT NO. 2
Aim :- Write a program to compute the area of a circle.
Explanation :-This program demonstrate the uses of datatypes and variables to compute area of a circle. Program :class radius { public static void main(String str[]) { int r; double a; float pi=3.1416f; r=Integer.parseInt(str[0]); a=pi*r*r; System.out.println("Area of a circle is="+a); } } Output :-

Viva -Voice Questions: 1. 2. 3. 4. What is datatypes. What is variable. What is the difference between object and variable? Why do I have to put an f after a floating point constant?

EXPERIMENT NO. 3
Aim -: Write a program to add two integer numbers using command line argument.
Explanation -:This program enable the user to add two integer numbers using command line Program -: class add { public static void main(String str[]) { int a,b,c; a=Integer.parseInt(str[0]); b=Integer.parseInt(str[1]); c=a+b; System.out.println("Sum Is =- " + c); } } Output :-

Viva -Voice Questions: 1. What do you mean by command line argument programming. 2. What java uses compiler , interpreter or both. 3. Can I compile group of java files once?

EXPERIMENT NO. 4
Aim: - Write a program to check whether the given number is even or odd using if-else statements.
Explanation :-This program demonstrate the simple use of if else by checking the number using modulo operator. Program :class check { public static void main(String str[]) { int a; a=Integer.parseInt(str[0]); if(0==a%2) { System.out.println("given no. is="+a); System.out.println("Number is Even "); } else { System.out.println("given no. is="+a); System.out.println("Number is Odd "); }} } Output :-

Viva - Voice Questions: 1. What is reserve word and how many?. 2. What is the difference between division and modulo operator. 3. What is jvm 4. What is jdk

EXPERIMENT NO. 5
Aim :- Write a program to determine which season a particular month.
Explanation :-This program is uses the logical operator with ladder if else statement. Program :class season { public static void main(String str[]) {int a; String s; a=Integer.parseInt(str[0]); if(a==12||a==1||a==2) s=Winter; else if(a==3||a==4||a==5) s=Spring; else if(a==6||a==7||a==8) s=Summer; else if(a==9||a==10||a==11) s=Autom; else s=Bogus Month; System.out.println(Enter month number is the :+s) } } Output :-

Viva -Voice Questions: 1. What is the difference between logical and bitwise operator. 2. What is byte code 3. What language is the Java compiler and JVM written in?

EXPERIMENT NO. 6
Aim :- Write a program to Display menu (1.Add, 2.Sub, 3.Mul , 4.Div) using switch statement.
Explanation :-This program describe the uses of switch statement with 4 case,when particular case value matches code related with that casewill be executed other wise default scase will be executed. Program :class choice { public static void main(String str[]) { int a,b,c,d,k=0; a=Integer.parseInt(str[0]); b=Integer.parseInt(str[1]); c=Integer.parseInt(str[2]); do { switch(a) { case 1: { d=b+c; System.out.println("addition="+d); break; } case 2: { d=b-c; System.out.println("subtraction"+d); break; } case 3: { d=b*c; System.out.println("multiplication="+d); break; } case 4: {

d=b/c; System.out.println("division="+d); break; } default : { System.out.println("Enter correct choice"); } } k++; } while(k<=0); } }

Output :-

Viva - Voice Questions: What is the difference between if and switch statement. What is break and what it do. 3. Is there any limit to the length of an identifier?.
1. 2.

EXPERIMENT NO. 7
Aim: - Write a program to find the factorial of a given number while statement.
Explanation :- While statement is entry controlled loop statement 1st it evaluate condition then body of the code is executed. Program :class fact { public static void main(String str[]) { int num,fac=1,i=1; num=Integer.parseInt(str[0]); while(num>=i) { fac=fac*i; i++; } System.out.println(Factorial of a given no is=+fac); } } Output :-

Viva -Voice Questions: 1. What is the difference between while and do while loop. 2. What is the difference between break and continue statements.

EXPERIMENT NO. 8
Aim :- Write a program to reverse a 5digit number and calculate sum of its digit using for loop.
Explanation :- for statement is entry controlled loop statement 1st it evaluate condition then body of the code is executed in this we can reverse any integer number.. Program :class rev { public static void main(String str[]) { int a,b,sum=0,rev=0; a=Integer.parseInt(str[0]); for(;a>0;) { b=a%10; rev=rev*10+b; sum=sum+b; a=a/10; } System.out.println("revers is "+rev); System.out.println("sum of the digit "+sum); } } Output :-

Viva Voice Questions: 1. What is the type casting. 2. How many types we can convert data

EXPERIMENT NO. 9
Aim: - Write a program to that use continue to print a triangular multiplication for 1 to 4.
1 24 369 4 8 12 16 Explanation :- for statement is entry controlled loop statement 1st it evaluate condition then body of the code is executed. This is the nesting of for statement with continue label. Program :class table { public static void main(String str[]) { huk: for(int i=1;i<5;i++) { for(int j=1;j<5;j++) { if(j>i) { System.out.println(); continue huk; } System.out.print(" "+i*j); }} System.out.println(); }} Output :-

Viva - Voice Questions: 1. What is the difference between continue and continue with label 2. What is the difference between break and break with label

EXPERIMENT NO. 10
Aim :- Write a program to sort a list of 7 numbers in ascending order
Explanation :-This program demonstrate the uses of array, how to initialize and how to create memory for array elements. Program :class order { public static void main(String str[]) { int a[],n; a=new int[10]; for(int i=0;i<=6;i++) a[i]=Integer.parseInt(str[i]); for(int j=0;j<=6;j++) { for(int i=0;i<=6;i++) { if(a[j]<a[i]) { n=a[j]; a[j]=a[i]; a[i]=n; } }} System.out.println("Orded of the given no is "); for(int k=0;k<=6;k++) System.out.print(" "+a[k]); }} Output-:

Viva Voice Questions: 1. How do I copy an array? 2. What is the difference between simple variable and array. 3. How array in java is differ from c/c++

EXPERIMENT NO. 11
Aim :- Write a program to generate a pattern using 2D array.
0 12 345 6789 Explanation :- This program demonstrate the uses of 2D array, how to initialize and how to create memory for array elements. Program :class pattern {public static void main(String str[]) {int toD[][]=new int[4][]; toD[0]=new int[1]; toD[1]=new int[2]; toD[2]=new int[3]; toD[3]=new int[4]; int i,j,k=0; for(i=0;i<4;i++) for(j=0;j<i+1;j++) { toD[i][j]=k; k++; } for(i=0;i<4;i++) { for(j=0;j<i+1;j++) System.out.print(toD[i][j]+" "); System.out.println(); }}} Output-:

Viva Voice Questions 1. How can we create memory for 4D array. 2. How do you deallocate an array in Java?

EXPERIMENT NO. 12
Aim :- Write a program to make a class and introduce method and field.
Explanation :-This program tells the uses of creating class ,method and field. Program :class democlass { public static void main(String str[]) { demo obj=new demo(); demo obj1=new demo(); obj.w=10;obj.h=20; obj.l=30; obj1.w=12; obj1.h=22;obj1.l=17; obj.disp(); obj1.disp(); }} class demo { int w,h,l; void disp() {System.out.println("volum is"); System.out.println(w+h+l); }} Output-:

Viva Voice Questions: 1. What is class 2. What is the difference between structured and object oriented programming. 3. What is the difference between class and structure 4. What are the access modifier.

EXPERIMENT NO. 13
Aim :- Write a program to creat a class using constructor.
Explanation :-This program tells the uses of constructor ,how to use in classes. Program :class democlass { public static void main(String str[]) { System.out.println("object one is"); demo obj=new demo(); int v=obj.vol(); System.out.println(+v); System.out.println("object two is"); demo obj1=new demo(); int k=obj1.vol(); System.out.println(+k); } } class demo { int w,h,l; demo() { System.out.println("calling constructor"); System.out.println("volum is"); w=10; h=15; l=20; } int vol() { return(w*l*h); } }

Output-:

Viva Voice Questions: 1. What is constructor. 2. Why we use constructor. 3. What do you mean by garbage collection

EXPERIMENT NO. 14
Aim :- Write a program to demonstrate the fundamental of inner class.
Explanation :-This program demonstrate the fundamentals of inner class. Program :class innerclass { public static void main(String str[]) { outer obj=new outer(); obj.test(); } } class outer { int w=25; void test() { inner in=new inner(); in.disp(); } class inner { void disp() { System.out.println("outer class data is"+w); } } } Output-:

Viva - Voice Questions: 1. What does it mean that a method or field is "static"? 2. how many public class are possible in java 3. What is the difference between jre and java?

EXPERIMENT NO. 15
Aim -: Write a program to inherit a property of one class to another.
Explanation -:This program enable the user to inherite the property of a base class into the derived class. Program -: class inherit { public static void main(String str[]) { parent a=new parent(); child b=new child(); a.i=10; a.j=20; System.out.println("content of parent class"); a.show(); System.out.println(); b.i=15; b.j=25; b.k=35; System.out.println("content of child class"); b.show(); b.showc(); System.out.println(); b.sum(); } } class parent { int i,j; void show() { System.out.println("i and j = "+i+" "+j); } } class child extends parent { int k; void showc() {

System.out.println("k = "+k); } void sum() { System.out.println("sum is"+(i+j+k)); } }

Output-:

Viva voice Questions: 1. What do you mean by inheritance 2. How multiple inheritance is achieve in java 3. What is the keyword to achieve inheritance.

EXPERIMENT NO. 16
Aim -: Write a program to inherite a property of a base class in derived class using super statement
Explanation -:This program enable the user to inherite the property of a base class into the derived class using supper statement supper is the 1st statement of constructor. Program -: class item { int itemno; String disc; float rate; int qoh; void disp() { System.out.println("item class"); System.out.println("item no is"+itemno); System.out.println("disc is"+disc); System.out.println("reate is"+rate); System.out.println("quantity is"+qoh); } item() { itemno=0; disc=" "; rate=0; qoh=0; } item(int n,String s,float r,int q) { itemno=n; disc=s; rate=r; qoh=q; } }

// creating printer class class printer extends item { String type; int ppm; printer() { super(); type=" "; ppm=0; } printer(int a,String b,float c,int d,String e,int f) { super(a,b,c,d); type=e; ppm=f; } void disp() { super.disp(); System.out.println("printer class"); System.out.println("type is "+type); System.out.println("ppm is "+ppm); } public static void main(String str[]) { printer p1=new printer(); p1.disp(); printer p2=new printer(10,"husain",4.5f,99,"khan",88); p2.disp(); } }

Output:

Viva - Voice Questions: 1. what is supper statement. 2. How multiple inheritance is achieved in java 3. How do I get multiple return values back from a method?

EXPERIMENT NO. 17
Aim -: Write a program to make a package.
Explanation -:This program enable the user to make a own packageand uses the property of a package class into the derived classes. Program -: import huk.*; class mypack { public static void main(String str[]) { pack obj=new pack("husain ullah khan",12398.45); obj.show(); } }

Output:-

Viva Voice Questions: 1. What is packages 2. What is class libraries 3. Why can't the compiler find my package?

EXPERIMENT NO. 18
Aim -: Write a program to handle Arithmetic exception using try catch statement.
Explanation -:This program enable the user to handle the exception using try catch statement. Program -: class excep { public static void main(String str[]) { int i=0,j; try{ j=39/i; } catch(Exception e) { System.out.println(I am handling exception); System.out.println(e); } } Output:-

Viva Voice Questions: 1. what is exception . 2. what are the advanteges of exception. 3. What is the super class of exception.

EXPERIMENT NO. 19
Aim -: Write a program to implement nested try catch statement.
Explanation -:This program enable the user handle exception using multiple try catch statements Program -: class excep {public static void main(String str[]) { try{ int i=str.length; System.out.println(i); int b=33/i; int c[]={1}; } catch(ArithmeticException e) { System.out.println(I am handling exception); System.out.println(e); } Catch(ArrayIndexOutOfBoundsException e) { System.out.println(I am handling exception); System.out.println(e); } } } Output:-

Viva - Voice Questions: 1. what are the keywords to handle exception. 2. What is the difference between throw and throws. 3. List any five exception name.

EXPERIMENT NO. 20
Aim -: Write a program to create Thread and control main thread.
Explanation -:This program enable the user to create thread and how to control the main thread Program -: class demoth {public static void main(String str[]) { int i=5; Thread t=Thread.currentThread(); System.out.println("current thread "+t); t.setName("mythread "); System.out.println("changed thread "+t); try{ for(;i>0;) { System.out.println(i); Thread.sleep(1000); i--; } } catch(Exception e) { System.out.println("interupted thread"); }} } Output:-

Viva - Voice Questions: 1. Define thread 2. How many types we can create threads 3. What is the advanteg of threading

EXPERIMENT NO. 21
Aim -: Write a program to create multiple thread.
Explanation -:This program enable the user to create multi threading programming Program -: class multi { public static void main(String str[]) { new NewThread("one"); new NewThread("two"); new NewThread("three"); try{ Thread.sleep(1000); } catch(Exception e) { System.out.println("interupted thread"); } System.out.println("main thread exited "); } } class NewThread implements Runnable { String name; Thread t; NewThread(String tname) {name=tname; t=new Thread(this,name); System.out.println("New thread "+t); t.start(); } public void run() { try{ for(int i=5;i>0;i++) { System.out.println(name+" :"+i); Thread.sleep(1000); } }

catch(Exception e) { System.out.println(name+"Interupted"); } System.out.println(name+"Exited"); }} Output:-

Viva -Voice Questions: 1. what is the advanteg of multi threading programming 2. what is thread model 3. what are the methods in thread class

EXPERIMENT NO. 22
Aim -: Write a program to display This is an Applet string on an applet.
Explanation -:This program demonstrate the user make internet programming using Applet. Program -: import java.awt.*; import java.applet.*; /*<applet code="app" width=300 height=50> </applet> */ public class app extends Applet { String msg="This is an Applet"; public void init() { setBackground(Color.cyan); setForeground(Color.red); start( ); } public void paint(Graphics g) { Font f=new Font("Monotype Corsiva",Font.BOLD+Font.ITALIC,14); g.setFont(f); g.drawString(msg,50,30); }} Output:-

Viva Voice Questions: 1. Define applet 2. What are the applet methods.

EXPERIMENT NO. 23
Aim -: Write a program to make a simple moving banner applet.
Explanation -: This program demonstrate the user to make banner on an applet programming Program -: import java.awt.*; import java.applet.*; /*<applet code="SimpleBanner" width=300 height=100> </applet> */ public class SimpleBanner extends Applet implements Runnable { String msg="A Simple Banner Applet"; Thread t=null; boolean stopflag; public void init() { setBackground(Color.cyan); setForeground(Color.red); } public void start() { t=new Thread(this); stopflag=false; t.start(); } public void run() { char ch; for(;;) { try { repaint(); Thread.sleep(250); ch=msg.charAt(0); msg=msg.substring(1,msg.length()); msg+=ch; if(stopflag) break; } catch(Exception e) {

System.out.println("Exception :"+e); } } } public void stop( ) { stopflag=true; t=null; } public void paint(Graphics g) { g.drawString(msg,50,30); } }

Output:-

Viva Voice Questions: 1. What is graphics class in applet? 2. What are the advantages of applet?

EXPERIMENT NO. 24
Aim -: Write a program to implement URL class on applet.
Explanation -:This program enable the user to implement url on an applet Program -: import java.awt.*; import java.applet.*; import java.net.*; public class App1 extends Applet { public void start() { AppletContext ac=getAppletContext(); URL u=getCodeBase(); Try { ac.showDocument(new URL(u+"test.html"),"_parent"); } catch(Exception e) { showStatus("URL not found"); } }} Output:-

Viva Voice Questions: 1. what is url 2. what is the difference between codebase and getcodebase method

EXPERIMENT NO. 25
Aim :- Write a program to display IP address of a system.
Explanation -:This is the simple network program to find ip address of a system Program -: import java.net.*; public class ipadd { public static void main(String args[]) { try { InetAddress i=InetAddress.getLocalHost( ); String s=i.toString( ); System.out.println(s.substring(s.indexOf(/)+1)); } catch(Exception e) { System.out.println(Exception : +e); } } } Output:-

Viva Voice Questions: 1. what is ip addressing scheme 2. what is internet protocol 3. what are the different classes of addressing scheme

EXPERIMENT NO. 26
Aim :- Write a program to display host name of a system.
Explanation -:This program enable the user to find host name Program:import java.net.*; public class host { { public static void main(String args[]) try {

InetAddress i=InetAddress.getLocalHost( ); String s=i.toString( ); System.out.println(s.substring(0,(s.indexOf("/")))); } catch(Exception e) {

System.out.println("Exception : "+e); } }} Output:-

Viva - voice Questions: 1. what information host address contain 2. what is inet address

EXPERIMENT NO. 27
Aim :- Write a program to display protocol, host name , port and filename of a system.
Explanation -:This program enable the user to display protocol hostname, port and file of a sysytem Program:import java.net.*; public class host{ { try { public static void main(String args[])

InetAddress i=InetAddress.getLocalHost( ); String s=i.toString( ); System.out.println(s.substring(0,(s.indexOf("/")))); } catch(Exception e) {

System.out.println("Exception : "+e); } }} Output:-

Viva Questions: 1. what is the difference between port and socket 2. what is protocol

EXPERIMENT NO. 28
Aim :- Write a program for chatting using tcp/ip socket
Explanation -:This program enable the user to chat with tcp/ip socket Program:import java.net.*; import java.io.*; public class ChatServer { public static void main(String args[]) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ServerSocket ss=new ServerSocket(2345); Socket skt=ss.accept( ); BufferedReader skt_in=new BufferedReader(new InputStreamReader(skt.getInputStream( ))); PrintStream skt_out=new PrintStream(skt.getOutputStream( )); while(true) { System.out.println(skt_in.readLine( )); skt_out.println(What is your name); yourname=skt_in.readLine( ); System.out.println(yourname); String s=skt_in.readLine( ); System.out.println(s); String myname=br.readLine( ); skt_out.println(myname); break; } while(true) { String recv=skt_in.readLine( ); System.out.println(yourname+:+recv); String send=br.readLine( ); skt_out.println(send); } } catch(Exception e) { System.out.println(Exception :+e); }}}

// CLIENT import java.net.*; import java.io.*; public class ChatClient { public static void main(String args[]) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Socket skt=new Socket(rungtaibm,2345); BufferedReader skt_in=new BufferedReader(new InputStreamReader(skt.getInputStream( ))); PrintStream skt_out=new PrintStream(skt.getOutputStream( )); while(true) { skt_out.println(hello can I connect); skt_out.println(skt_in.readLine( )); String myname=br.readLine( ); skt_out.println(myname); skt_out.println(What is yours); String yourname=skt_in.readLine( ); System.out.println(yourname); break; } while(true) { String send=br.readLine( ); skt_out.println(send); String recv=skt_in.readLine( ); System.out.println(yourname +:+recv); } } catch(Exception e) { System.out.println(Exception :+e); } } }

OUTPUT : TCP Server

TCP Client

Viva - Voice Questions: 1. 2. 3. 4. What is tcp/ip protocol In which layer tcp/ip protocol exist Is tcp/ip is connectinless or connectin oriented. What is the difference between ARP and RARP

EXPERIMENT NO. 29
Aim -: Write a program to set the awt component controls.
Explanation -:This program enable the user to make graphical user interface Program -: Import java.awt.*; Import java.applet.*; Public class comp extends Applet { BorderLayout b1=new Borderlayout(); Button b1,b2,b3,b4; Label l1,l2; Public void init() { b1=new Button (ok); b2=new Button (cancel); b3=new Button (ok); b4=new Button (cancel); l1=new label(are u sure ?); l2=new label(are u sure ?); setLayout(null); b1.setBounds(20,20,100,20); b2.setBounds(20,30,110,30); b3.setBounds(20,40,120,40); b4.setBounds(20,40,120,40); l1.setBounds(20,50,130,50); l2.setBounds(20,60,140,60); Add(b1);Add(b2);Add(b3);Add(b4);Add(l1);Add(l2); }} Output-:

Viva - Voice Questions: 1. what is awt components. 2. what is the difference betweem awt and swing component 3. what is team class

EXPERIMENT NO. 30
Aim -: Write a program to insert, delete and update a table using JDBC-ODBC connection .
Explanation -:This program enable the user to work with database Program -: import java.sql.*; import java.util.*; class badabase { Public static void main(String str[]) { Try { Resultset rs; Class.forName(sun.jdbc.odbc.jdbcodbcDriver); String url=jdbc:odbc:huk; Connection con; Con=DriverManager.getconnection(url); Statement set=con.createstatement(); Rs=ser.executeQuery(Select * from db); String ins=Insert into db values(husain,it,539); String del=Delet form db where name =huk; preparedStatement set=con.preparedstatement(ins); set.getString(1,huk); set.executeupdate(); con.commit(); while(rs.next()) { System.out.println(rs.getString(1)+ +rs.getString(2); } Con.close(); } Catch(exception e) { Sysstem.out.println(no such class); }} } Viva Voice Questions: 1. what is JDBC-ODBC and DSN 2. what is the locking of databade