Write a program to implement the concept of Exception Handling using by creating user defined exceptions.

  import java.lang.Exception; class EvenNumberException extends Exception { EvenNumberException(String emsg) { super(emsg); } } class testexcep { public static void main(String args[]) { int num=5,r; try { r=num%2; if(r!=0) { throw new EvenNumberException("Number is not even"); } } catch(EvenNumberException e) { System.out.println("Caught User defined Exception"); System.out.println(e.getMessage()); } } }     Output: C:\>java testexcep Caught … Read moreWrite a program to implement the concept of Exception Handling using by creating user defined exceptions.

Write a program to implement the concept of Exception Handling using predefined exception.

  class test1 { public static void main(String args[]) { int a[]={5,5}; int x,y; try { x=(a[1]+a[0])/(a[0]-a[1]); } catch(ArithmeticException e) { System.out.println("Divide by zero Error"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Array Index Out Of Range"); } y=((a[0]+a[1])/(a[0]+a[1])); System.out.println("y "+y); } }     Output: C:\>java test1 Divide by zero Error y 1 C:\>    

Write a program to implement the concept of threading by implementing Runnable Interface

  class tclassp implements Runnable { public void run() { for(int i=1;i<5;i++) { System.out.println("From thread p:"+i); } System.out.println("Thread p halts now"); } } class rundemo { public static void main(String args[]) { tclassp tp=new tclassp(); Thread trp=new Thread(tp); trp.start(); System.out.println("End of main thread"); } }     Output: C:\>java rundemo End of main thread From … Read moreWrite a program to implement the concept of threading by implementing Runnable Interface

Write a program to implement the concept of threading by extending Thread Class

  class mythread extends Thread { public void run() { int i=0; while(i<=10) { System.out.println("From Mythread i="+i++); } } } class yourthread extends Thread { public void run() { int j=0; while(j<=10) { System.out.println("From Yourthread j="+j++); } } } public class threaddemo { public static void main (String args[]) { mythread myob=new mythread(); myob.start(); yourthread … Read moreWrite a program to implement the concept of threading by extending Thread Class

Write a Java program to implement the concept of importing classes from user defined package and creating packages.

  package P1; public class student { int rollno; String name; public float marks; public void getstudent(int rno,String n,float m) { rollno=rno; name=n; marks=m; } public void putstudent() { System.out.println("Roll number="+rollno); System.out.println("Name="+name); System.out.println("Marks="+marks); } }  Create Subdirectory P1 in your current working directory  Save it as student.java in subdirectory P1 and compile it … Read moreWrite a Java program to implement the concept of importing classes from user defined package and creating packages.

Write a Java program to implement the concept of importing classes from user defined package and creating packages

  package Pk1; public class student { int rollno; String name; public float marks; public void getstudent(int rno,String n,float m) { rollno=rno; name=n; marks=m; } public void putstudent() { System.out.println("RollNumber="+rollno); System.out.println("Name="+name); System.out.println("Marks="+marks); } }  Create Subdirectory P1 in your current working directory  Save it as student.java in subdirectory P1 and compile it C:\PCKSMPL>cd … Read moreWrite a Java program to implement the concept of importing classes from user defined package and creating packages

Write a program to demonstrate use of extending interfaces.

  interface Circle { final double PI=3.142; } interface Circle2 extends Circle { public void computearea(int radius); } class area implements Circle2 { public void computearea(int radius) { double carea=PI*radius*radius; System.out.println("PI value="+PI); System.out.println("Area of Circle="+carea); } } class demointerface1 { public static void main(String args[]) { area a=new area(); a.computearea(2); } }     Output: … Read moreWrite a program to demonstrate use of extending interfaces.

Write a program to demonstrate use of implementing interfaces.

  interface area { double PI=3.142; double findarea(double m,double n); } class Triangle implements area { public double findarea(double m,double n) { double aot=0.5*m*n; return(aot); } } class Circle implements area { public double findarea(double m,double n) { double aoc=PI*m*n; return(aoc); } } class demointerface { public static void main(String arg[]) { Triangle t=new Triangle(); … Read moreWrite a program to demonstrate use of implementing interfaces.

Write a Java Program to implement multilevel inheritance by applying various access controls to its data members and methods.

  class Length { int l; void setl(int a) { l=a; } void putl( ) { System.out.println("Length="+l); } } class Breadth extends Length { int b; void setb(int y) { b=y; } void putb( ) { System.out.println("Breadth="+b); } } class Height extends Breadth { int h; void seth(int z) { h=z; } void puth( ) … Read moreWrite a Java Program to implement multilevel inheritance by applying various access controls to its data members and methods.

Write a Java Program to implement inheritance and demonstrate use of method overriding.

  class circle { double r; circle(double m) { r=m; } void area() { double acircle=3.142*r*r; System.out.println("Area of Circle"+acircle); } } class shape extends circle { shape(double l) { super(l); } void area() { double perimeter=2*3.142*r; System.out.println("Perimeter="+perimeter); } } class override { public static void main(String arg[]) { shape s=new shape(3.9); s.area(); } }   … Read moreWrite a Java Program to implement inheritance and demonstrate use of method overriding.