program to assign two integer..... class A1_xy { public static void main(String a[]) { int x=10,y=20; if ( x > y ) { System.out.println("x is greater y"); } else { System.out.println("x is not greater than y"); } } } program to list the factorial..... class A2_fact { public static void main(String a[]) { int i=1,n=10,fact=1; while ( i<=n ) { fact=fact*i; System.out.println("factorial of"+i+"="+fact); i++; } } } circumference..... import java.io.*; import java.util.*; class A3_circle { public static void main(String a[]) { float pi=3.142f,area,cir; Scanner sc=new Scanner(System.in); System.out.println("Enter radius of a circle:"); int r=sc.nextInt(); area = pi*r*r; cir = 2*pi*r; System.out.println("Area of circle="+area); System.out.println("Circumference of a circle="+cir); } } two integers and two float number..... class A4_overload { int x=100,y=200; public static void main(String ar[]) { A4_overload obj=new A4_overload(); obj.add(); System.out.println("Sum of integers="+obj.add(10,20)); System.out.println("Sum of float numbers="+obj.add(10.5f,20.3f)); } void add() { int sum=x+y; System.out.println("Sum of default values="+sum); } int add(int x,int y) { return (x+y); } float add(float x,float y) { return (x+y); } } program to mathematical operator... classAddSub { intx=6,y=2;i nt sum() { return(x+y); } int sub() { return(x-y); } } classMulDivextendsAddSub { intmul() { return(x*y); } int div() { return(x/y); } } class mathop { publicstaticvoid main(Stringa[]) { MulDiv obj=new MulDiv();System.out.println("Sum="+obj.sum());S ystem.out.println("Subtraction="+obj.sub());Syste m.out.println("Multiplication="+obj.mul());System. out.println("Division="+obj.div()); } } Program with class variable that is available for all instances of a class... class A6_static { int x; static int y,z; static void mul() { //x=10; // ‘x’ can not be accessed here because it is non-static. y=5; z=15; int m=y*z; System.out.println("Multiplication of y & z="+m); } public static void main(String ar[]) { A6_static s1=new A6_static(); A6_static s2=new A6_static(); s1.x=10; s2.x=20; s1.y=100; s2.y=200; System.out.println("s1's x="+s1.x); System.out.println("s2's x="+s2.x); System.out.println("s1's y="+s1.y); System.out.println("s2's y="+s2.y); A6_static.mul(); } } Program to create a student class with following attributes; Enrollment No... import java.util.*;; public class A7_student { static int eno; static String name; static float m1,m2,m3,tot; static void input() { Scanner sc=new Scanner(System.in); System.out.println("Enter student enrollment no:"); eno=sc.nextInt(); System.out.println("Enter student name:"); name=sc.next(); System.out.println("Enter subject1 marks:"); m1=sc.nextFloat(); System.out.println("Enter subject2 marks:"); m2=sc.nextFloat(); System.out.println("Enter subject3 marks:"); m3=sc.nextFloat(); } A7_student(float x,float y,float z) { if(x>=50 && y>=50 && z>=50) { tot=x+y+z; } else { tot=0; } } void display() { System.out.println("enrollment no is:"+eno); System.out.println("Name is:"+name); System.out.println("Marks1="+m1); System.out.println("Marks2="+m2); System.out.println("Marks3="+m3); System.out.println("Total="+tot); } public static void main(String a[]) { A7_student[] obj=new A7_student[3]; for(int i=0;i<3;i++) { A7_student.input(); obj[i]=new A7_student(m1,m2,m3); obj[i].display(); } } } program to demonstrate multiple inheritance.... import java.io.*; interface circle { float pi= 3.142f ; float compute ( float r ); } class rect { float compute ( float l, float b ) { return ( l * b ) ; } } class area extends rect implements circle { public float compute ( float r ) { return ( pi * r * r ); } } class A8_multipleI { public static void main(String args[]) { area a = new area (); System.out.println ( "Area of circle=" + a.compute ( 1f ) ); System.out.println ( "Area of rectangle=" + a.compute ( 5f, 10f ) ); } } Illustrate creation of thread by... import java.io.*; class A extends Thread { public void run () { System.out.println ( "thread A is running" ) ; } } class A9_a_tthread { public static void main ( String args[] ) { A obj = new A (); obj.start () ; } } import java.io.*; class A implements Runnable { public void run () { System.out.println ( "thread A is running" ) ; } } class A9_b_Rthread { public static void main ( String args[] ) { A obj = new A () ; Thread t = new Thread ( obj ) ; t.start () ; } } Create a package “BCA”.... package BCA; public class A11_student { String name,gender; int age; public A11_student(String n,int a,String g) { name=n; age=a; gender=g; } public void display() { System.out.println("Name is:"+name); System.out.println("Age is:"+age); System.out.println("Gender is:"+gender); } } b. Import above package and access the member variables and function contained in a package. import BCA.*; class A11_pkg { public static void main(String ar[]) { A11_student obj=new A11_student("abc",20,"f"); obj.display(); } } Program to catch Negative Array Size Exception... class B1_array { public static void main(String ar[]) { try { int a[]=new int[-2]; System.out.println("Exception not caught because array size is not negative"); } catch(NegativeArraySizeException e) { System.out.println("Exception Caught \n because Array size is initialized to Negative value"); } } } Program to create 4×4 grid .... import java.awt.*; import java.awt.event.*; public class B5_grid { Frame f; B5_grid() { f=new Frame("Grid with Buttons"); Button b1=new Button("1"); Button b2=new Button("2"); Button b3=new Button("3"); Button b4=new Button("4"); Button b5=new Button("5"); Button b6=new Button("6"); Button b7=new Button("7"); Button b8=new Button("8"); Button b9=new Button("9"); Button b10=new Button("10"); Button b11=new Button("11"); Button b12=new Button("12"); Button b13=new Button("13"); Button b14=new Button("14"); Button b15=new Button("15"); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.add(b5); f.add(b6); f.add(b7); f.add(b8); f.add(b9); f.add(b10); f.add(b11); f.add(b12); f.add(b13); f.add(b14); f.add(b15); f.setLayout(new GridLayout(4,4)); f.setSize(400,300); // void setSize(width, height) f.setVisible(true); } public void windowClosing(WindowEvent we) { f.setVisible(false); } public static void main(String ar[]) { new B5_grid(); } } frame with two buttons father and mother.... import java.awt.*; import java.awt.event.*; public class B6_button1 implements ActionListener { Frame f; Button b1 = new Button("Father"); Button b2 = new Button("Mother"); TextField t; B6_button1() { f=new Frame(); f.setVisible(true); b1=new Button("Father"); b1.setSize(800,900); b2=new Button("Mother"); b2.setSize(150,150); t=new TextField(); t.setSize(500,100); b1.addActionListener(this); b2.addActionListener(this); f.setSize(500,200); f.setLayout(new GridLayout(3,1)); f.add(t); f.add(b1); f.add(b2); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { t.setText("Father Name is: ABC Father age is: 50"+ "\n" + "Father Designation is: BusinessMan"); } else if(e.getSource()==b2) { t.setText("Mother Name is: XYZ Mother age is: 45 Mother Designation is: Bank Employee"); } } public static void main(String ar[]) { new B6_button1(); } } frame which displays your personal details .... import java.awt.*; import java.awt.event.*; public class B7_person implements ActionListener { Frame f; Button b; TextField t; B7_person() { f=new Frame(); b=new Button("Click"); t=new TextField(); f.setSize(300,500); f.setVisible(true); f.add(t); f.add(b); f.setLayout(new GridLayout(2,1)); b.addActionListener(this); } public void actionPerformed(ActionEvent e) { t.setText("Name: Khushi Degree: BCA"); } public static void main(String ar[]) { new B7_person(); } } create a window with TextFields and Buttons....import java.awt.*; import java.applet.*; import java.awt.event.*; public class B8_add extends Applet implements ActionListener { TextField t1,t2,t3; Label l1,l2,l3; Button b1,b2; public void init() { t1=new TextField(20); t2=new TextField(20); t3=new TextField(20); l1=new Label("A"); l2=new Label("B"); l3=new Label("A + B"); b1=new Button("Add"); b2=new Button("Clear"); add(l1); add(t1); add(l2); add(t2); add(l3); add(t3); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e) { int a,b,sum; if(e.getSource()==b1) { a=Integer.parseInt(t1.getText()); b=Integer.parseInt(t2.getText()); sum = a+b; t3.setText(Integer.toString(sum)); } else if(e.getSource()==b2) { t1.setText(" "); t2.setText(" "); t3.setText(" "); } } } good morning good afternoon good ... import java.awt.*; import java.awt.event.*; public class B9 extends Frame implements KeyListener { TextField t; public B9() { Frame f=new Frame("Key board Events"); t=new TextField(); f.add(t); f.setSize(400,300); f.setVisible(true); f.setLayout(null); t.addKeyListener(this); } public void keyTyped(KeyEvent ke) { if(ke.getKeyChar()=='M' || ke.getKeyChar()=='m') { t.setText("Good Morning"); } else if(ke.getKeyChar()=='A' || ke.getKeyChar()=='a') { t.setText("Good AfterNoon"); } else if(ke.getKeyChar()=='E' || ke.getKeyChar()=='e') { t.setText("Good Evening"); } else if(ke.getKeyChar()=='N' || ke.getKeyChar()=='n') { t.setText("Good Night"); } else { t.setText(" "); } } public void keyReleased(KeyEvent ke) { } public void keyPressed(KeyEvent ke) { } public static void main(String ar[]) { new B9(); } } various mouse handling events.... import java.awt.*; import java.awt.event.*; public class B10_me extends Frame { public B10_me() { // adding MouseAdapter to frame mouse_events ph = new mouse_events(); addMouseListener(ph); addMouseMotionListener(ph); setSize(300, 300); setVisible(true); } public static void main(String args[]) { new B10_me(); } } class mouse_events extends MouseAdapter // second class { public void mouseClicked(MouseEvent e) { System.out.println("You clicked mouse at coordinates " + e.getX() + ", " + e.getY()); } public void mouseReleased(MouseEvent e) { System.out.println("Mouse released"); } public void mouseEntered(MouseEvent e) { System.out.println("mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("mouse pressed at:"+e.getX()); } public void mouseDragged(MouseEvent e) { System.out.println("dragging mouse at :"+e.getX()+" , "+e.getY()); } public void mouseMoved(MouseEvent e) { System.out.println("Mouse moved at:"+e.getX() + " , " + e.getY()); } } create menubar and pull-down menus... import java.awt.*; import java.awt.event.*; class B11_menu extends WindowAdapter { Frame f; B11_menu() { f=new Frame("Menu & DropDown Menu"); MenuBar mb=new MenuBar(); Menu m=new Menu("Degree Courses"); Menu subm=new Menu("Science"); MenuItem i1=new MenuItem("BCA"); MenuItem i2=new MenuItem("BBA"); MenuItem i3=new MenuItem("BCom"); MenuItem i4=new MenuItem("BSc"); MenuItem i5=new MenuItem("Msc"); m.add(i1); m.add(i2); m.add(i3); subm.add(i4); subm.add(i5); mb.add(m); m.add(subm); f.setMenuBar(mb); f.setSize(200,200); f.setVisible(true); } public static void main(String ar[]) { new B11_menu(); } }