Practical 25
import [Link];
import [Link];
class A extends Exception {
A(String msg) {
super(msg);
}
}
class B {
public static void main(String args[]) {
[Link]("Enter the Password");
Scanner sc = new Scanner([Link]);
String Pass;
Pass = [Link]();
try {
if ()
throw new A("Authentication Failure");
else
[Link]("Welcome");
} catch (A e) {
[Link]([Link]());
}
}
}
Practical 26
import [Link];
class throwown1 extends Exception {
throwown1(String msg) {
super(msg);
}
}
class thowAge {
public static void main(String[] args) {
[Link]("Enter your age");
Scanner sc = new Scanner([Link]);
int age = [Link]();
try {
if (age < 0)
throw new throwown1("Your age is negative");
else
[Link]("Correct age");
} catch (throwown1 e) {
[Link]("This is My Exception Block {Executed}");
[Link]([Link]());
}
}
}
25 Practical
public class ex2
public static void main(String args[]) }
try
int a[]=new int[5]; [Link](a[10]);
} catch(ArithmeticException e)
[Link]("Arithmetic Exception occurs"); }
catch(ArrayIndexOutOfBoundsException e)
[Link]("ArrayIndexOutOfBoundsException occurs");
} finally
[Link]("program end");
}
}
}
Prac 21
class A extends Thread
{
public void run()
{
[Link]("Even no Thread:");
try
{
for(int i=1;i<=10;i++)
{
if(i%2==0)
[Link](i);
[Link](500);
}
}
catch(InterruptedException e){}
}
}
class B extends Thread
{
public void run()
{
[Link]("Odd no Thread:");
try
{
for(int i=1;i<=10;i++)
{
if(i%2!=0)
[Link](i);
[Link](500);
}
}
catch(InterruptedException e){}
}
}
class Threading
{
public static void main(String args[])
{
A a1=new A();
[Link]();
try
{
[Link]();
}
catch(InterruptedException e){}
B b1=new B();
[Link]();
}
}
Prac 22
class A extends Thread
{
public void run()
{
[Link]("Thread1 Execution Started");
[Link]("Thread1 Termination");
}
}
class B extends Thread
{
public void run()
{
[Link]("Thread2 Execution Started");
[Link]("Thread2 Termination");
}
}
class C extends Thread
{
public void run()
{
[Link]("Thead3 Execution Started");
[Link]("Thread3 Termination");
}
}
class Priority
{
public static void main(String args[])
{
A obj=new A();
B obj1=new B();
C obj2=new C();
[Link](Thread.MAX_PRIORITY);
[Link](Thread.NORM_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link]();
[Link]();
[Link]();
}
}