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