added till 8th a

This commit is contained in:
Misa
2026-01-29 14:55:08 +05:30
commit fd0c995cd6
13 changed files with 121 additions and 0 deletions

BIN
GenericMethodTest.class Normal file

Binary file not shown.

22
GenericMethodTest.java Normal file
View 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

Binary file not shown.

29
MovieBook.java Normal file
View 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

Binary file not shown.

BIN
MyThread2.class Normal file

Binary file not shown.

BIN
Table.class Normal file

Binary file not shown.

BIN
TestSynchronization2.class Normal file

Binary file not shown.

70
TestSynchronization2.java Normal file
View 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

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB