Skip to main content

FEATURED POST

Why the World is Running Out of Computers

Question: Write a program to implement synchronization.

Question: Write a program to implement synchronization.


class Callme
{

                       public synchronized void call(String msg)

                       {

                        System.out.print("["+msg);

                        try

                        {

                                    Thread.sleep(1000);

                        }

                        catch(InterruptedException e)

                        {

                                    System.out.println(e);

                        }

                        System.out.println("]");

                       }

}

class Caller implements Runnable

{

                       String s;

                       Callme target;

                       Thread t;

                       Caller(Callmetar,Stringmsg)

                       {

                        t = new Thread(this);

                        target = tar;

                        s = msg;

                        t.start();

                       }

                       public void run()

                       {

                        target.call(s);

                       }

}

class Sync
{

                       public static void main(String args[])

                       {

                        Callmeob = new Callme();

                        Caller o1 = new Caller(ob,"Hello");

                        Caller o2 = new Caller(ob,"Synchronized");

                        Caller o3 = new Caller(ob,"World");

                        try

                        {

                                    o1.t.join();

                                    o2.t.join();

                                    o3.t.join();

                        }

                        catch(InterruptedException e)

                        {

                                    System.out.println(e);

                        }

                       }

}
OUTPUT:











Keyword:
How to recover the classnotfoundexception in Java?
What are the top most requirements or expectations of client for develop Java web application?
Java program question paper in 2020
java applet
applet programming in java
creating applet in java



Comments

Popular Posts

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:  Ø “Car” that inherits “Vehicle” and also stores number of passengers.  Ø “Truck” that inherits “Vehicle” and also stores the load limit.  Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{   int wheels;   double speed; } class Car extends Vehicle{   int pass;   void input(){    Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:");    wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):");    speed=sc.nextDouble(); System.out.println("No. of passengers:");   ...

Question: Write a java program that implements bank transactions using user defined exception.

Question: Write a java program that implements bank transactions using user defined exception. import java.util.*; class UDE{     public static void main(String ts7[]) throws MinimumBal {         Scanner sc= new Scanner(System.in);         double bal; System.out.println("Enter current balance:"); bal=sc.nextDouble(); System.out.println("Enter amount to withdrawal");         int n = sc.nextInt();         try {             if (bal<n)                   throw new MinimumBal("Account ae taka nei bhai !\nYour Current balance is "+bal);             else      System.out.print...

Difference Between Instance and Static Variables in Java

Instance and Static Variables import java.util.*; import java.lang.*; import java.io.*; //Using Instance Variable class VarDemo{     int i=0;     VarDemo(){         i++;         System.out.println(i);     }          public static void main (String[] args) {         VarDemo v1 = new VarDemo();         VarDemo v2 = new VarDemo();         VarDemo v3 = new VarDemo();     } } // Using Static Variable class VarDemo {    static int i=0;     VarDemo(){         i++;         System.out.println(i);     }          public static void main (String[] args) {         VarDemo v1 = new VarDemo();         VarDemo v2 = new VarDemo();         VarDemo v3 = new VarDemo();     } }