Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Showing posts with label SDM JAVA LAB TERM WORK. Show all posts
Showing posts with label SDM JAVA LAB TERM WORK. Show all posts

Saturday, 6 April 2019

UDP Factorial

Question
Write a Java program to implement client-server interaction using connectionless sockets. The client must send a number to a server as a request. The server must process the request as a thread and return the factorial of the requested number as a response to the client. If a negative number is sent from the client, the server must throw a user-defined exception named NegativeNumberException.

Solution:

Server Side:

import java.net.*;

public class UDPserver {

public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
try{
new thread().start();
}catch(Exception e)
{
e.printStackTrace();
}
}
private static class thread extends Thread{
public void run()
{
try{
DatagramSocket ds=new DatagramSocket(9999);
byte[] b1=new byte[1024];
DatagramPacket dp=new DatagramPacket(b1,b1.length);
ds.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
int num=Integer.parseInt(str.trim());
int result=1;
try{
if(num>0)
{
for(int i=1;i<=num;i++)
{
result=result*i;
}
}
else
{
throw new NegativeNumberException("it is negative number");
}
}catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
InetAddress ia=InetAddress.getLocalHost();
byte[] b2=String.valueOf(result).getBytes();
DatagramPacket dp1=new DatagramPacket(b2,b2.length,ia,dp.getPort());
ds.send(dp1);
}catch(Exception x)
{
}
}
}
}
class NegativeNumberException extends Exception
{
String msg;
NegativeNumberException(String msg)
{
this.msg=msg;
}
public String toString()
{
return msg;
}

}



Client Side:

import java.net.*; import java.util.Scanner; public class UDPclient { public static void main(String[] args)throws Exception { // TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
DatagramSocket ds=new DatagramSocket();
System.out.println("Enter The Number Whose Factorial u Need");
int i=s.nextInt();
byte[] b=String.valueOf(i).getBytes();
InetAddress ia=InetAddress.getLocalHost();
DatagramPacket dp=new DatagramPacket(b,b.length,ia,9999);
ds.send(dp);
byte[] b1=new byte[1024];
DatagramPacket dp1=new DatagramPacket(b1,b1.length);
ds.receive(dp1);
String str=new String(dp1.getData(),0,dp1.getLength());
System.out.println("the Factorial result is "+str); } }

Credits: Harshita

TCP Factorial (Modification)

Question Label Internal 5 TCP 
Write a Java program to implement client-server interaction using connection-oriented sockets. 
 The client must send a number to a server as a request. The server must process the request  as a thread and return the factorial of the requested number as a response to the client.
   If a negative number is sent from the client, the server must throw a user-defined exceptionnamed NegativeNumberException.


Server Side
// Java implementation of  Server side 
// It contains two classes : Server and 
//ClientHandler 
// Save file as Server.java 
  
import java.io.*; 
import java.net.*; 
//Exception Class
class NegativeNumberException extends Exception {
private String op;

   public NegativeNumberException(String op) {
this.op = op;
}

public String toString() {
return "NegativeNumberException: Operation Factorial is Denied by server";
}
}

// Server class 
public class ServerFactorial  

    public static void main(String[] args) throws IOException  
    { 
        // server is listening on port 5080
        ServerSocket ss = new ServerSocket(5080); 
         Socket s = null; 
              
            try 
            { 
                // socket object to receive incoming client requests 
                s = ss.accept(); 
                     
                // obtaining input and out streams 
                DataInputStream dis = new DataInputStream(s.getInputStream()); 
                DataOutputStream dos = new DataOutputStream(s.getOutputStream()); 
                  
                // create a new thread object 
                Thread t = new ClientHandle(s, dis, dos); 
  
                // Invoking the start() method 
                t.start();         
            } 
            catch (Exception e){ 
                s.close(); 
                e.printStackTrace(); 
            } 
        } 
    } 

  
// ClientHandler class 
class ClientHandle extends Thread{
final DataInputStream dis; 
    final DataOutputStream dos; 
    final Socket s; 
      
  
    // Constructor 
    public ClientHandle(Socket s, DataInputStream dis, DataOutputStream dos)  
    { 
        this.s = s; 
        this.dis = dis; 
        this.dos = dos; 
    } 
  
    @Override
    public void run()  
    {  
        String received; 
        String toreturn; 
  int num,count = 1;
             try { 
  
                // Ask user what he wants 
                dos.writeUTF("Press any number to get Factorial..\n");
                // receive the answer from client 
                received = dis.readUTF(); 
                
                num=Integer.parseInt(received);
                try{
                if (num<0) {
    throw new NegativeNumberException(received);
    }
                }catch(Exception e) {
                toreturn=e.toString();
                dos.writeUTF(toreturn);
                System.out.println("Closing this connection."); 
                        this.s.close(); 
                                      }
                if(num<=9) {
                count=1;
                for(int i=1;i<=num;i++) {
                count=count*i;
                }
                 // write the 
                // answer from the client 
                toreturn = "Factorial of "+num+"="+count; 
                dos.writeUTF(toreturn);  
                }
      //Today's Modification Ma'am Asked
     //If the number is Greather than 9 Step //Down It to One's Place And
// Find It one's place FFactorial
//Example: 24=>4 => Factorial Of 4=24
                else {
                count=1;
                int n=num%10;
                for(int i=1;i<=n;i++) {
                count=count*i;
                }
                 // write the 
                // answer from the client 
            toreturn="Step Down the num:"+num+" to: "+n+"\n Factorial="+count;
            dos.writeUTF(toreturn);
                }
            

                Thread.sleep(1000); 
             }catch(Exception ef)
             {
            ef.printStackTrace();
             }
        try
        { 
            // closing resources 
            this.dis.close(); 
            this.dos.close(); 
              
        }catch(IOException ee){ 
            ee.printStackTrace(); 
        }  
        }
    }



Client Side:
  
import java.io.*; 
import java.net.*; 
import java.util.Scanner; 
  
// Client class

public class ClientFactorial  

    public static void main(String[] args) throws IOException  
    { 
        try
        { 
            Scanner scn = new Scanner(System.in); 
              
            // getting localhost ip 
            InetAddress ip = InetAddress.getByName("localhost"); 
      
 // establish the connection with server port 5080 
            Socket s = new Socket(ip, 5080); 
      
  // obtaining input and out streams 
            DataInputStream dis = new DataInputStream(s.getInputStream()); 
            DataOutputStream dos = new DataOutputStream(s.getOutputStream()); 
      
                System.out.println(dis.readUTF()); 
                String tosend = scn.nextLine(); 
                dos.writeUTF(tosend);             
                String received = dis.readUTF(); 
                System.out.println(received);
                              
        }catch(Exception e){ 
            e.printStackTrace(); 
        } 
    } 


Note: Green mark one is Modification Asked in B1 Lab Ia.

Thursday, 4 April 2019

Sixth Week Term Work Program 2 (Hashing)

Question:
Post Graduate course of CSE department can accommodate a maximum of 20 students. Each
PG student in the department is identified by his/her Roll No, USN, Name, Semester and
Mobile Number. Using the appropriate Collection class, write a Java Program to simulate the
following scenarios:
a. On request, the capacity got increased from 20 to 25.
b. Only 10 students enroll for the course.
c. Four students from Roll No.s 3 – 6 voluntarily un-enroll from the course.
d. After a month, six more students get enrolled in the course.

e. Print the information of all the students currently enrolled in the course.

Java Program:

import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Map;


class StudentDetails{
String name;
String usn;
String div;
String Course="Java";
int sem;
StudentDetails(String name, String usn, String div,  int sem){
this.name=name;
this.usn=usn;
this.div=div;
this.sem=sem;
}

}

public class PgStudent {
public static void main(String[] args) {



Map<Integer,StudentDetails> map=new HashMap<Integer,StudentDetails>(); 
//Creating students
StudentDetails s1=new StudentDetails ("amar","2sd15cs08","b",4); 
StudentDetails  s2=new StudentDetails("Akbar","2sd16cs10","b",4); 
StudentDetails s3=new StudentDetails("Antony","2sd16cs09","b",4); 
StudentDetails s4=new StudentDetails("Ajay","2sd16cs01","b",4);
StudentDetails s5=new StudentDetails("siya","2sd16cs02","b",4);
StudentDetails s6=new StudentDetails("Riya","2sd16cs03","b",4);
StudentDetails s7=new StudentDetails("Maya","2sd16cs04","b",4);
StudentDetails s8=new StudentDetails("Shriya","2sd16cs05","b",4);
StudentDetails s9=new StudentDetails("Fida","2sd16cs06","b",4);
StudentDetails s10=new StudentDetails("Jiya","2sd16cs07","b",4);
//Adding Students to map 
map.put(1,s1);
map.put(2,s2);
map.put(3,s3);
map.put(4,s4);
map.put(5,s5);
map.put(6,s6);
map.put(7,s7);
map.put(8,s8);
map.put(9,s9);
map.put(10,s10);


//Traversing map
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------");



System.out.println("Now students having Usn 3 to 6  will unroll from the course");
map.remove(3);
System.out.println("Student having roll no 3 unrolled");
map.remove(4);
System.out.println("Student having roll no 4 unrolled");
map.remove(5);
System.out.println("Student having roll no 5 unrolled");
map.remove(6);
System.out.println("Student having roll no 6 unrolled");
System.out.println("-----------------------------------------------------------");
System.out.println("List of students after un-rolling from course");
System.out.println("-----------------------------------------------------------");
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------"); 

//After a month 6 more students enrolled

StudentDetails s11=new StudentDetails ("ADI","2sd15cs11","b",4); 
StudentDetails  s12=new StudentDetails("JAI","2sd16cs12","b",4); 
StudentDetails s13=new StudentDetails("RUHI","2sd16cs13","b",4); 
StudentDetails s14=new StudentDetails("RIMA","2sd16cs14","b",4);
StudentDetails s15=new StudentDetails("AMY","2sd16cs15","b",4);
StudentDetails s16=new StudentDetails("ARYA","2sd16cs16","b",4);

map.put(3,s11);
map.put(4,s12);
map.put(5,s13);
map.put(6,s14);
map.put(11,s15);
map.put(12,s16);
System.out.println("Currently Updated list");
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------");
}


}

Credits: Sonali 

Friday, 8 March 2019

Sixth Week Term Work Program 2 (Arraylist)

Question:
Post Graduate course of CSE department can accommodate a maximum of 20 students. Each
PG student in the department is identified by his/her Roll No, USN, Name, Semester and
Mobile Number. Using the appropriate Collection class, write a Java Program to simulate the
following scenarios:
a. On request, the capacity got increased from 20 to 25.
b. Only 10 students enroll for the course.
c. Four students from Roll No.s 3 – 6 voluntarily un-enroll from the course.
d. After a month, six more students get enrolled in the course.

e. Print the information of all the students currently enrolled in the course.

Solution:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Student{
Scanner in=new Scanner(System.in);
int Rollno;
String usn;
String Name;
int sem;
String Mobileno;
Student() {
System.out.print("Enter The Roll No:");
Rollno=in.nextInt();
System.out.println();
System.out.print("Enter The USN:");
usn=in.next();
System.out.println();
System.out.print("Enter The Name:");
Name=in.next();
System.out.println();
System.out.print("Enter The Sem");
sem=in.nextInt();
System.out.println();
System.out.print("Enter The MobileNo:");
Mobileno=in.next();
System.out.println();

}
Student(String name, int Rollno, String Mobile, String Usn, int sem)
{
this.Name=name;
this.Rollno=Rollno;
this.Mobileno=Mobile;
this.usn =Usn;
this.sem = sem;

}
public String getName() 
{
return Name;
}


public int getRollno() 
{
return Rollno;
}
public String getMobile() 
{
return Mobileno;
}

public String getUsn() 
{
return usn;
}


public int getSemester() 
{
return sem;
}

}
class Course extends Student
{
String course;


Course(String name, int Rollno, String Mobile, String Usn, int sem) 
{
super(name, Rollno, Mobile, Usn, sem);
System.out.println("Enter Course Name:");
course = in.next();


}
public String getCourse() 
{
return course;
}

public void setCourse(String course) 
{
this.course = course;
}
}
public class Pgstudent {
static Scanner in=new Scanner(System.in);
public static void main(String[] args) {
int choice;
int i=0,size=20;
List<Student> studentsList = new ArrayList<Student>(size); // array list to store user input For Student
List<Course> studentsListCourse = new ArrayList<Course>(size); // array list to store user input For Course

while (true) {
System.out.println("\n\n*******************STUDENT RECORD*******************\n");
System.out.println("1. Increase the Capacity");
System.out.println("2. Enter Student Record");
System.out.println("3. Display Record");
System.out.println("4. Enroll Course");
System.out.println("5. DeRoll Course");                                                                        
System.out.println("6. Display Enrolled Student Details");
System.out.println("7. Exit");
System.out.println("Enter choice: ");
choice = in.nextInt();
switch (choice) {
case 1:size=25;
System.out.println("Size Changed to 25");
break;

case 2: if(i<size){

System.out.println("============" + "=================");
System.out.println("Students " + "Personal Details");
System.out.println("============" + "=================");
Student student = new Student();

studentsList.add(student); // add student
i++;
}

else {
System.out.println("U Cannot Store The Student Record");
}
break;
case 3:
for (int j = 0; j < studentsList.size(); j++)
{

Student st = studentsList.get(j);

System.out.println("Information of Student : " + st.getRollno()); 
System.out.println("");
System.out.println("Name: " + st.getName() + " - Roll No: "+st.getRollno() + " - Mobile No: " + st.getMobile() + " - Student USN: " + st.getUsn() + " - Semester: " + st.getSemester());
System.out.println("");
}

break;
case 4:
System.out.println("============ENROLL" + "=================");
System.out.println("============" + "=================");
System.out.println("Enter the Roll NO");
int Froll=in.nextInt(),flag=0;
for (int j = 0; j < studentsList.size(); j++)
{
Student ct = studentsList.get(j);
if(ct.getRollno()==Froll) {
flag=1;
Course course=new Course(ct.getName(),ct.getRollno(), ct.getMobile(),ct.getUsn(),ct.getSemester());
studentsListCourse.add(course); // add student

}
}
if(flag==0) {
System.out.println("No Student Exist With Given RollNo Sorry Try Again");
}

break;
case 5:
System.out.println("Enter the Roll NO");
int Roll=in.nextInt(),flag1=0;
for (int j = 0; j < studentsListCourse.size(); j++)
{

Course ct = studentsListCourse.get(j);
if(ct.getRollno()==Roll) {
flag1=1;
System.out.println("Information of Student : " +ct.getRollno()); 
System.out.println("");
System.out.println("Name: " + ct.getName() + " - Roll No: "+ct.getRollno() + " - Mobile No: " + ct.getMobile() + " - Student USN: " + ct.getUsn() + " - Semester: " + ct.getSemester()+" -Course: "+ct.getCourse());
System.out.println("");
studentsListCourse.remove(ct);
}
}
if(flag1==0) {
System.out.println("Enter Roll No Did Not Enroll Only");
}


break;
case 6:
for (int j = 0; j < studentsListCourse.size(); j++)
{

Course ct = studentsListCourse.get(j);
System.out.println("Information of Student : " + (j + 1)); 
System.out.println("");
System.out.println("Name: " + ct.getName() + " - Roll No: "+ct.getRollno() + " - Mobile No: " + ct.getMobile() + " - Student USN: " + ct.getUsn() + " - Semester: " + ct.getSemester()+"-Course:"+ct.getCourse());
System.out.println("");

}
break;
case 7:
System.out.println("THANKS FOR VISTING");
System.exit(0);
break;
default:
System.out.println("Enter A Valid Option");

}
}   
}

}



Credit: Shubham

Thursday, 7 March 2019

Sixth week Term Work Program 4

Question:
Write a Java program to that simulates copy command.

Solution:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

// file streams (STREAMS)
public class program {
public static void main(String[] args)  {
FileInputStream fin=null;
FileOutputStream fout=null;
int num;
try {
fin=new FileInputStream(args[0]);
fout=new FileOutputStream(args[1]);
while((num=fin.read())!=-1) {
fout.write(num);
System.out.print((char)num);
}

}catch(Exception e) {
e.printStackTrace();

}
finally {
System.out.println();
if(fin!=null)
try {
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
if(fout!=null)
try {
fout.close();
}catch(Exception e) {
e.printStackTrace();

}
}

}

}

Output:
//Command Line Argument
123456789000111 My name Khan And I am not A hero.

Sixth Week Term Work Program 3 [ IA-1 2 B) ]

Question:
Write a Java program the implements a generic sort method using any of the sorting techniques.

public class GenericSorting {
//Modification: Sorting Wrt To String Length.
public static <T extends Comparable<T>> void sortingMethod1(T array[])
   {
   int i,j,n;
   n=array.length;
   for(i=0;i<n;i++)
   for(j=0;j<n-i-1;j++)
   if((((String) array[j]).length())>((String) array[j+1]).length())
   {
   T temp;
   temp=array[j];
   array[j]=array[j+1];
   array[j+1]=temp;
   }
   
   for(T element: array)
  System.out.printf("%s ", element);
   System.out.println();
   }

   public static <T extends Comparable<T>> void sortingMethod(T array[])
   {
   int i,j,n;
   n=array.length;
   for(i=0;i<n;i++)
   for(j=0;j<n-i-1;j++)
   if(array[j].compareTo(array[j+1])>0)
   {
   T temp;
   temp=array[j];
   array[j]=array[j+1];
   array[j+1]=temp;
   }
   
   for(T element: array)
  System.out.printf("%s ", element);
   System.out.println();
   }
   public static void main(String args[])
   {
   Integer i[]={3,2,1,7,6};
           String s[]={"pear","orange","apple"};
   sortingMethod(i);
 sortingMethod(s);
 
 System.out.println("\nSorting As per String Length");
 sortingMethod1(s);
 
   }
}

Output:
1 2 3 6 7 
apple orange pear 

Sorting As per String Length

pear apple orange 

Blue Marked Are Modification Asked By Ma'am In B1 Batch.

Sixth Week Term Work Program 1 [ IA-1 3 A) ]

Question:
 Write a Java program to create the below-mentioned Student record using appropriate
Collection class to perform the following operations on a single student:
a. Add a student
b. Display all the details of the student
c. Delete/remove student record
Members of the class Student is given below:

Student
name
USN
division
CGPA


Solution:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class SingleStudentRecord {
 ArrayList<Comparable> stud=new   ArrayList<Comparable>(4);
static Scanner in=new Scanner(System.in);
public void EnterRecord() {
System.out.print("Enter The Name:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The USN:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The Division:");
stud.add(in.next());
System.out.println();
System.out.print("Enter The CGPA:");
stud.add(in.nextFloat());
System.out.println();
}
public void DisplayRecord() {
Iterator<Comparable> itr=stud.iterator();
while(itr.hasNext()) {
System.out.println(itr.next());
}        

}
public void DeleteRecord() {
System.out.println("Deleted The Student Record");
stud.removeAll(stud);
}
public static void main(String[] args) {
SingleStudentRecord s=new SingleStudentRecord();
int choice;
int i=0;
    while (true) {
        System.out.println("\n\n*******************STUDENT RECORD*******************\n");
        System.out.println("1. Enter Student Record");
        System.out.println("2. Display Record");
        System.out.println("3. Delete Record");
        System.out.println("4. Exit");
        System.out.println("Enter choice: ");
        choice = in.nextInt();
        switch (choice) {
        case 1: if(i==0)
        {
        s.EnterRecord();
        i++;
        }
        else {
        System.out.println("U Can Store Only One Student Record");
        }
                break;
        case 2:
        if(i==1)
        {
        s.DisplayRecord();
        }
        else {
        System.out.println("No Record Exists");
        }
        break;
        case 3:if(i==1) {
        s.DeleteRecord();
        i--;
        }
        else {
        System.out.println("No Record To delete");
        }
        break;
        case 4:
        System.out.println("THANKS FOR VISTING");
        System.exit(0);
        break;
        default:
        System.out.println("Enter A Valid Option");

}
}
}
}

Output:

**********STUDENT RECORD**********

1. Enter Student Record
2. Display Record
3. Delete Record
4. Exit
Enter choice: 
1
Enter The Name:Amit

Enter The USN:2Sd16cs012

Enter The Division:B

Enter The CGPA:8.4


Enter choice: 
2
Amit
2Sd16cs012
B
8.4


Enter choice: 
3
Deleted The Student Record


Enter choice: 
4
THANKS FOR VISTING


Saturday, 23 February 2019

Extra Program #1(Awt) [ IA-1 3 B) ]

Question:









The program should display the message "Successfully Submitted" on the console when clicked on the "Submit" button and the text should get cleared when the user clicks on "Clear" button.


Program:


import java.awt.*;
import java.awt.event.*;

public class extraRegistrationForm {
public static void main(String[] args) {
Frame f = new newRegistrationFrame("Registration Form");
f.setSize(250, 300);
f.setVisible(true);
}
}
//Frame class
class newRegistrationFrame extends Frame {

TextField t1,t2;
public newRegistrationFrame(String title) {
super(title);
setLayout(null);
setBackground(Color.white);
Label l1=new Label("Enter your name:");
l1.setBounds(10, 40, 120, 50);
Label l2=new Label("Enter your Mobile no:");
l2.setBounds(10, 70, 120, 50);
add(l1);
add(l2);
t1=new TextField();
t1.setEditable(true);
t1.setBounds(130, 55, 100, 20);
t2=new TextField();
t2.setBounds(130, 85, 100, 20);
t2.setEditable(true);
add(t1);
add(t2);

//Add  button to frame and attach listener
Button b = new Button("Submit");
b.setBounds(30, 150, 100, 30);
add(b);
b.addActionListener(new ButtonListener());

Button b1 = new Button("Clear");
b1.setBounds(140, 150, 100, 30);
add(b1);
b1.addActionListener(new ButtonListener());

//Attach window listener
addWindowListener(new WindowCloser());
}

//Listener for button

class ButtonListener implements ActionListener {
Label t=new Label();
public void actionPerformed(ActionEvent evt) {
if(evt.getActionCommand().equals("Submit")) {
//If we Have Print It On Console
System.out.println("Successfully Submitted");

/* 
If we have print It on The Awt Window
  t.setText("Successfully Submitted");

 t.setBounds(100, 210, 150, 30);

 add(t);
*/
}
else if(evt.getActionCommand().equals("Clear")) {
t1.setText("");
t2.setText("");
}
}
}
//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}

Credits: Arjun

Fifth Week Term Work Program 4


Question









Program:


import java.awt.*;
import java.awt.event.*;

public class Registrationform {
public static void main(String[] args) {
Frame f = new RegistrationFrame("Registration Form");
f.setSize(260, 200);
f.setVisible(true);
}
}
//Frame class
class RegistrationFrame extends Frame {
public RegistrationFrame(String title) {
super(title);
setLayout(null);
setBackground(Color.white);
Label l1=new Label("Enter your name:");
l1.setBounds(10, 40, 120, 50);
Label l2=new Label("Enter your Mobile no:");
l2.setBounds(10, 70, 120, 50);
add(l1);
add(l2);
TextField t1=new TextField();
t1.setEditable(true);
t1.setBounds(130, 55, 100, 20);
TextField t2=new TextField();
t2.setBounds(130, 85, 100, 20);
t2.setEditable(true);
add(t1);
add(t2);

//Add  button to frame 
Button b = new Button("Submit");
b.setBounds(30, 150, 100, 30);
add(b);

Button b1 = new Button("Clear");
b1.setBounds(140, 150, 100, 30);
add(b1);


//Attach window listener
addWindowListener(new WindowCloser());
}

//Listener for window
class WindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
}
}