Java Lab VV
Java Lab VV
8
Aim - WAP in java to illustrate multithreading, inheritance, interface.
Code :
interface RunnableTask {
void runTask();
class Animal {
void makeSound() {
void makeSound() {
System.out.println("Bark");
this.taskName = taskName;
this.animal = animal;
animal.makeSound();
runTask();
thread.start();
}
Output Window:
Experiment No. 9
Aim - WAP to create a file. Read and write from the file using byte stream
class.
Code :
import java.io.*;
f.write(contentBytes);
} catch (IOException e) {
e.printStackTrace();
f.read(contentBytes);
String fileContent = new String(contentBytes);
} catch (IOException e) {
e.printStackTrace();
Output Window:
Experiment No. 10
Aim - WAP in java to illustrate list.
Code :
import java.util.*;
//ArrayList
AL.add(1);
AL.add(2);
AL.add(3);
AL.add(4);
AL.add(5);
AL.remove(3);
//LinkedList
LL.add(9);
LL.add(10);
LL.addAll(AL);
LL.add(4,11);
LL.addFirst(12);
LL.addLast(13);
//Vector
vector.add("Apple");
vector.add("Banana");
vector.add("Cherry");
vector.set(1, "Blueberry");
System.out.println("Vector elements after modification:"+ vector);
vector.remove(2);
Output Window:
Experiment No. 11
Aim - WAP in java to illustrate set.
Code :
import java.util.*;
//hashSet
hashSet.add("Apple");
hashSet.add("Banana");
hashSet.add("Cherry");
hashSet.add("Apple");
retainSet.add("Apple");
retainSet.add("Banana");
hashSet.retainAll(retainSet);
//linkedHashSet
linkedHashSet.add("Elephant");
linkedHashSet.add("Frog");
linkedHashSet.add("Dog");
linkedHashSet.addAll(hashSet);
//treeSet
treeSet.add("Giraffe");
treeSet.add("Hippo");
treeSet.add("Iguana");
treeSet.add("Giraffe");
treeSet.addAll(linkedHashSet);
treeSet.retainAll(hashSet);
}
}
Output Window: