11 a.
code execute and debug programs in java to handle checked exceptions
package a;
import java.io.FileWriter;
import java.io.IOException;
public class checked {
public static void main(String args [])throws IOException
FileWriter obj=new FileWriter("C:\\Users\\BETP LAB 01\\Desktop\\b");
System.out.println("file written successfully");
Output
file written Successfully
b. code execute and debug program to java to unchecked exceptions.
package a;
import java.io.FileWriter;
import java.io.IOException;
public class unchecked {
public static void main(String args [])throws IOException
int i=10/0;
System.out.println(i);
}
Output
Exception in thread "main" java.lang.ArithmeticException: / by zero
at a/a.checked.main(checked.java:6)
c. write a program to implement file writer.
package a;
import java.io.*;
public class MyFileReader {
public static void main(String [] args)throws IOException
FileWriter fw=new FileWriter("C:\\Users\\BETP LAB 01\\Desktop\\aa.txt");
String s="good morning to all 4th sem students";
char ch[]=s.toCharArray();
for(int i=0;i<ch.length;i++)
fw.write(ch[i]);
fw.close();
Output
12) Design an interface it like one that build different types of toys and check compliancre with
ISP
package a;
public interface barkable {
public void bark();
interface flyable
public void fly();
class dog implements barkable
public void bark()
System.out.println("dog is barking");
class bird implements flyable
public void fly()
System.out.println("bird is flyable");
class java
{
public static void main(String [] args)
dog a1=new dog();
bird a2=new bird();
a1.bark();
a2.fly();
Output
dog is barking
bird is flyable
4.Install memory monitoring tool and observe how jum allocates memory.
package a;
public class jconso {
public static void main(String [] args)
Thread t1=new Thread1();
t1.start();
System.out.println("thread 1 started");
class Thread1 extends Thread
public void run()
{
while(true)
Output
thread 1 started