0% found this document useful (0 votes)
1 views6 pages

java2

The document contains Java code examples demonstrating how to handle checked and unchecked exceptions, implement a file writer, and design interfaces for different types of toys. It includes code snippets for writing to a file, handling arithmetic exceptions, and implementing interfaces for barking and flying behaviors. Additionally, it shows a simple memory monitoring tool using threads.

Uploaded by

hhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

java2

The document contains Java code examples demonstrating how to handle checked and unchecked exceptions, implement a file writer, and design interfaces for different types of toys. It includes code snippets for writing to a file, handling arithmetic exceptions, and implementing interfaces for barking and flying behaviors. Additionally, it shows a simple memory monitoring tool using threads.

Uploaded by

hhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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

You might also like