added till 8th a
This commit is contained in:
BIN
GenericMethodTest.class
Normal file
BIN
GenericMethodTest.class
Normal file
Binary file not shown.
22
GenericMethodTest.java
Normal file
22
GenericMethodTest.java
Normal file
@@ -0,0 +1,22 @@
|
||||
//write a java code for generic method
|
||||
public class GenericMethodTest
|
||||
{
|
||||
public static <E> void printarray(E[] inputarray)
|
||||
{
|
||||
for(E element :inputarray)
|
||||
{
|
||||
System.out.printf("%s", element);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Integer[] intarray = {1,2,3,4,5};
|
||||
Character[] chararray = {'a','b','c','d'};
|
||||
System.out.println("Array in integer:");
|
||||
printarray(intarray);
|
||||
System.out.println("Array in character");
|
||||
printarray(chararray);
|
||||
}
|
||||
}
|
||||
BIN
MovieBook.class
Normal file
BIN
MovieBook.class
Normal file
Binary file not shown.
29
MovieBook.java
Normal file
29
MovieBook.java
Normal file
@@ -0,0 +1,29 @@
|
||||
class TotalEarnings extends Thread
|
||||
{
|
||||
int total = 0;
|
||||
public void run()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
for(int i=1; i<=10; i++)
|
||||
{
|
||||
total=total+100;
|
||||
}
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MovieBook
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
TotalEarnings te = new TotalEarnings();
|
||||
te.start();
|
||||
synchronized(te)
|
||||
{
|
||||
te.wait();
|
||||
System.out.println("Total earnings: " +te.total);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
MyThread1.class
Normal file
BIN
MyThread1.class
Normal file
Binary file not shown.
BIN
MyThread2.class
Normal file
BIN
MyThread2.class
Normal file
Binary file not shown.
BIN
Table.class
Normal file
BIN
Table.class
Normal file
Binary file not shown.
BIN
TestSynchronization2.class
Normal file
BIN
TestSynchronization2.class
Normal file
Binary file not shown.
70
TestSynchronization2.java
Normal file
70
TestSynchronization2.java
Normal file
@@ -0,0 +1,70 @@
|
||||
class Table
|
||||
{
|
||||
synchronized void printTable(int n)
|
||||
{
|
||||
for(int i=1; i<=5; i++)
|
||||
{
|
||||
System.out.println(n*i);
|
||||
try
|
||||
{
|
||||
Thread.sleep(400);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyThread1 extends Thread
|
||||
{
|
||||
Table t;
|
||||
MyThread1(Table t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
public void run()
|
||||
{
|
||||
t.printTable(5);
|
||||
}
|
||||
}
|
||||
|
||||
class MyThread2 extends Thread
|
||||
{
|
||||
Table t;
|
||||
MyThread2(Table t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
public void run()
|
||||
{
|
||||
t.printTable(100);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestSynchronization2
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Table obj = new Table();
|
||||
MyThread1 t1 = new MyThread1(obj);
|
||||
MyThread2 t2 = new MyThread2(obj);
|
||||
t1.start();
|
||||
t2.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
TotalEarnings.class
Normal file
BIN
TotalEarnings.class
Normal file
Binary file not shown.
BIN
outputs/program 8(a) Generic method.png
Normal file
BIN
outputs/program 8(a) Generic method.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
outputs/program6 TestSynchronization2.png
Normal file
BIN
outputs/program6 TestSynchronization2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
outputs/program7 moviebook.png
Normal file
BIN
outputs/program7 moviebook.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
Reference in New Issue
Block a user