Snippets Collections
Producer-Consumer Inter-thread communication

Table.java 

public class Table
{
	private String obj;
	private boolean empty = true;
	 
	public synchronized void put(String obj)
	{  
	   if(!empty)
	    {   try
		    {  wait();
			}catch(InterruptedException e)
			{ e.printStackTrace(); }
		}
				
		this.obj = obj; 
		empty = false;
		System.out.println(Thread.currentThread().getName()+" has put "+obj);
		notify();
		
	}
	
	public synchronized void get()
	{   
	    if(empty)
	    {   try
		    {   wait();
			}catch(InterruptedException e)
			{ e.printStackTrace(); }
		}
		
		empty = true;
		System.out.println(Thread.currentThread().getName()+" has got "+obj);
		notify();		
	}
	
	public static void main(String[] args)
	{
		Table table = new Table();
		
		Runnable p = new Producer(table);
		Runnable c = new Consumer(table);
		
		Thread pthread = new Thread(p, "Producer");
		Thread cthread = new Thread(c, "Consumer");
		
		pthread.start(); cthread.start();
		
		try{ pthread.join(); cthread.join(); }
		catch(InterruptedException e){ e.printStackTrace(); }
	}
}

Producer.java

public class Producer implements Runnable
{   private Table table;

	public Producer(Table table)
	{ this.table = table; }
	
	public void run()
	{   java.util.Scanner scanner = new java.util.Scanner(System.in);
		for(int i=1; i <= 5; i++)
		{   System.out.println("Enter text: ");
	        table.put(scanner.next());	
            try{ Thread.sleep(1000); }	
			catch(InterruptedException e){ e.printStackTrace(); }		
		}
	}
}

Consumer.java

public class Consumer implements Runnable
{   
	private Table table;

	public Consumer(Table table)
	{ this.table = table; }
	
	public void run()
	{   for(int i=1; i <= 5; i++){ 
			table.get();
		}
		
	}
}

Inter-thread Synchronization example

Users.java


public class Users implements Runnable
{   private Account ac;
    
    public Users(Account ac)
    { this.ac = ac; }
	
    public void run()
    {   
        Thread t = Thread.currentThread();
         
        String name = t.getName();
		for(int i=1; i<=5; i++)
		{
			if (name.equals("John"))
			{  ac.deposit(200); } 
			if (name.equals("Mary"))
			{  ac.withdraw(200); }
		}
    }
}

Account.java

public class Account 
{   private double balance;
    
    public Account(double startBalance)
    { this.balance = startBalance; }
    	
    public   synchronized   void deposit(double amount)
    { Thread t = Thread.currentThread();
	  double bal = this.getBalance(); bal += amount;
	  try{ Thread.sleep(1000); }
      catch(InterruptedException ie)
      { ie.printStackTrace();  }
	  this.balance = bal;
	  System.out.println(t.getName() + " has deposited "+amount); }

    public  synchronized void withdraw(double amount)
    {   Thread t = Thread.currentThread();
        if (this.getBalance()>=amount)
        {   try{ Thread.sleep(1000); }
            catch(InterruptedException ie)
            { ie.printStackTrace();  }
            this.balance -= amount;
            System.out.println(t.getName() + " has withdrawn "+amount);
        }         
    }

    public double getBalance() {   return this.balance; }
}



AcTest.java

public class AcTest
{
    public static void main(String[] args)
    {
        Account a = new Account(5000);
        System.out.println("Current balance: "+a.getBalance());

        Runnable john = new Users(a); Runnable mary = new Users(a);

        Thread t1 = new Thread(john,"John");  Thread t2 = new Thread(mary,"Mary");
        t1.start(); t2.start();
        try{
            t1.join(); t2.join();
        }catch(InterruptedException ie)
        { ie.printStackTrace(); 
        }
        System.out.println("Current balance: "+a.getBalance());
    }
}

Synchronization another example     

Sync.java

public class Sync implements Runnable
{   private Display d;
    private String message;
	public Sync(Display d, String message)
	{ this.d = d; this.message = message; }
	
	public void run()
	{  synchronized(d)
         {      // or syncronize the show method
			d.show(this.message); 
	   }
	}
	
	public static void main(String[] args)
	{   Display d = new Display();
		Runnable r1 = new Sync(d, "First Message");  Runnable r2 = new Sync(d, "Second Message");
		Runnable r3 = new Sync(d, "Third message");
		Thread t1 = new Thread(r1); Thread t2 = new Thread(r2); Thread t3 = new Thread(r3);
		t1.start(); t2.start();t3.start();
	}
}





class Display
{    // 	public synchronized void show(String message)
	public void show(String message)   
	{
		System.out.print("{ " + message);
		try{  Thread.sleep(500); }
		catch(InterruptedException e){ e.printStackTrace(); }
		System.out.println(" }");
	}
	
}
Serialization program with 3 files

import java.io.*;

public class Student implements Serializable
{
	private int id;
	private String name;
	private double percentage;
	
	// use transient and static variables to check if they are saved
	
	public Student(int id, String name, double percentage)
	{
		this.id = id;
		this.name = name;
		this.percentage = percentage;
	}
	
	public String toString()
	{
		return "ID: "+this.id+", Name: "+this.name+", Percentage: "+this.percentage;
	}
}





import java.io.*;

public class SerializationDemo
{
	public static void main(String[] args)
	{
		try(FileOutputStream fos = new FileOutputStream("serial.txt");
		    ObjectOutputStream out = new ObjectOutputStream(fos);
		   )
		   {   System.out.println("Creating a student");
			   Student s = new Student(100, "John", 98.56);
			   System.out.println(s);
			   out.writeObject(s);
			   System.out.println("Object serialized");
		   }
		   catch(FileNotFoundException fe){ fe.printStackTrace();}
		   catch(IOException ie){ ie.printStackTrace(); }
	}
}

import java.io.*;

public class DeserializationDemo
{
	public static void main(String[] args)
	{
		try(FileInputStream fis = new FileInputStream("serial.txt");
		    ObjectInputStream in = new ObjectInputStream(fis);
		   )
		   {   System.out.println("Restoring the object");
			   Student s = (Student)in.readObject();
			   System.out.println(s);
			   System.out.println("Deserialization Done");
		   }
		   catch(ClassNotFoundException ce){ ce.printStackTrace();}
		   catch(IOException ie){ ie.printStackTrace(); }
	}
}
import java.io.*;

public class DirList
{
	public static void main(String[] args)
	{	File f = new File(args[0]);
		if(f.isDirectory())
		{	String[] files = f.list();
			for(String each: files)
				System.out.println(each);
		}
		File f1 = new File(f,"/sub");
		f1.mkdir();
	}
}

import java.io.*;

public class ConsoleDemo
{
	public static void main(String[] args)
	{   		 
		Console c = System.console();
		if(c == null)
			return;
		String s = c.readLine("Enter a String: ");
		char[] p = c.readPassword("Enter a Password: ");
		String pw = String.valueOf(p);
		System.out.println("Entered Details: "+s+", "+pw);
	}
}
import java.io.*;

public class FileDemo
{
	public static void main(String[] args)
	{
		File f = new File("sample.txt");
		
		System.out.println("File name: "+f.getName());
		System.out.println("Path: "+f.getPath());
		System.out.println("Absolute path: "+f.getAbsolutePath());
		System.out.println("Parent: "+f.getParent());
		System.out.println("Exists? "+f.exists());
		System.out.println("Writable? "+f.canWrite());
		System.out.println("Readable? "+f.canRead());
		System.out.println("Directory? "+f.isDirectory());
		System.out.println("File? "+f.isFile());
		System.out.println("Last modified: "+f.lastModified());
		System.out.println("Length: "+f.length()+" bytes");
		
		//File r = new File("Newsample.txt");
		//System.out.println("Renamed? "+f.renameTo(r));
		/* the delete() method is used to delete a file or an empty directory*/ 
		
		//f.delete();
      	// other methods
		System.out.println("Free space: "+f.getFreeSpace());
		System.out.println("Total space: "+f.getTotalSpace());
		System.out.println("Usable space: "+f.getUsableSpace());
		System.out.println("Read-only: "+f.setReadOnly());
		
		
	}
}
import java.io.*;

public class BufferedReaderDemo
{
	public static void main(String[] args)
	{   
		try(FileReader fis = new FileReader("BufferedReaderDemo.java");
		    BufferedReader bis = new BufferedReader(fis);
		   )
		{  int c;
		   while((c=bis.read()) != -1)
		   { System.out.print((char)c);
		   }
		}
		catch(IOException ie){ ie.printStackTrace();}
	}
}

import java.io.*;

public class BufferedWriterDemo
{
	public static void main(String[] args)
	{   
		try(FileReader fr = new FileReader("BufferedWriterDemo.java");
		    BufferedReader br = new BufferedReader(fr);
			FileWriter fw = new FileWriter("target.txt");
			BufferedWriter bw = new BufferedWriter(fw);
		   )
		{  int c;
		   while((c=br.read()) != -1)
		   { bw.write((char)c);
		   }
		   
		}
		catch(IOException ie)
		{ ie.printStackTrace();}
	}
}
<a href="https://maticz.com/medicine-delivery-app-development">Medicince Delivery App Development Company</a>
kubectl port-forward "service/rabbitmq-1-rabbitmq-svc" 15672 -n rabbitmq
import java.io.*;

public class CharArrayReaderDemo
{
	public static void main(String[] args)
	{
		String s = "abcdefghijklmnopqrstuvwxyz";
		char[] c = new char[s.length()];
		s.getChars(0, s.length(), c, 0);
		
		try(CharArrayReader car = new CharArrayReader(c))
		{	int i;
			while((i = car.read()) != -1)
				System.out.print((char)i);
		}		catch(IOException ie){ ie.printStackTrace(); }
	}
}
import java.io.*;

public class CharArrayWriterDemo
{
	public static void main(String[] args)
	{
		String s = "abcdefghijklmnopqrstuvwxyz";
		
		CharArrayWriter bas = new CharArrayWriter();
		char[] a = new char[s.length()];
		s.getChars(0, s.length(), a, 0);
		
		try{ bas.write(a); }
		catch(IOException ie){ ie.printStackTrace(); }
				  
		char[] b = bas.toCharArray();
		for(int c: b)
			System.out.print((char)c);
		System.out.println();
	}
}
import java.io.*;

public class FileReaderDemo
{
	public static void main(String[] args)
	{
		try(FileReader fr = new FileReader("FileReaderDemo.java"))
		{
			int c;
			while((c=fr.read())!= -1)
				System.out.print((char)c);
		}
		catch(IOException ie){ ie.printStackTrace(); }
	}
}

import java.io.*;

public class FileWriterDemo
{
	public static void main(String[] args)
	{
		try(FileReader fr = new FileReader("FileWriterDemo.java");
		    FileWriter fw = new FileWriter("Test2.dat");
		)
		{
			int c;
			while((c=fr.read())!= -1)
				fw.write((char)c);
		}
		catch(IOException ie){ ie.printStackTrace(); }
	}
}
import java.io.*;

public class ByteArrayInputStreamDemo
{
	public static void main(String[] args)
	{
		String s = "abcdefghijklmnopqrstuvwxyz";
		byte[] b = s.getBytes();
		ByteArrayInputStream bas = new ByteArrayInputStream(b);
		for(int i=0; i<2;i++)
		{
			int c;
			while((c=bas.read()) != -1)
			{
				if(i==0)
					System.out.print((char)c);
				else
					System.out.print(Character.toUpperCase((char)c));
			}
			System.out.println();
			bas.reset();
		}
	}
}
import java.io.*;

public class ByteArrayOutputStreamDemo
{
	public static void main(String[] args)
	{
		String s = "abcdefghijklmnopqrstuvwxyz";
		
		ByteArrayOutputStream bas = new ByteArrayOutputStream();
		bas.writeBytes(s.getBytes()); 
		  
		byte[] b = bas.toByteArray();
		for(int c: b)
			System.out.print((char)c);
		System.out.println();
	}
}
import java.io.*;

public class BufferedOutputStreamDemo
{
	public static void main(String[] args)
	{   
		try(FileInputStream fis = 
                     new FileInputStream("BufferedInputStreamDemo.java");
		    BufferedInputStream bis = new BufferedInputStream(fis);
			FileOutputStream fos = new FileOutputStream("target.txt");
			BufferedOutputStream bos = new BufferedOutputStream(fos);
		   )
		{  int c;
		   while((c=bis.read()) != -1)
		   { bos.write((char)c);
		   }
		   
		}
		catch(IOException ie)
		{ ie.printStackTrace();}
	}
}
import java.io.*;

public class BufferedInputStreamDemo
{
	public static void main(String[] args)
	{   
		try(FileInputStream fis = 
                        new FileInputStream("BufferedInputStreamDemo.java");
		    BufferedInputStream bis = new BufferedInputStream(fis);
		   )
		{  int c;
		   while((c=bis.read()) != -1)
		   { System.out.print((char)c);
		   }
		   
		}
		catch(IOException ie)
		{ ie.printStackTrace();}
	}
}
<a href=”https://maticz.com/cryptocurrency-payment-gateway-development”>Crypto Payment Gateway Development</a>
import java.io.*;

public class FileOutputStreamDemo
{
	public static void main(String[] args)
	{   FileOutputStream fos = null;
	    FileInputStream  fis = null;
	    try{
			fis = new FileInputStream("FileOutputStreamDemo.java");
			fos = new FileOutputStream("out.txt");
			
			int c = fis.read();
			while(c != -1)
			{   fos.write((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
		finally
		{   try 
			{    if(fis != null)
					fis.close();
			}catch(IOException ie){ ie.printStackTrace(); }
			try 
			{    if(fos != null)
					fos.close();
			}catch(IOException ie){ ie.printStackTrace(); } 
		}		
	}
}

import java.io.*;

public class FileOutputStreamDemo2
{
	public static void main(String[] args)
	{   
	    try(FileInputStream fis = 
                           new FileInputStream("FileOutputStreamDemo2.java");
	        FileOutputStream  fos = new FileOutputStream("out2.txt", true);
		   )
		{   int c = fis.read();
			while(c != -1)
			{   fos.write((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)	{ ie.printStackTrace(); }
	}
}
import java.io.*;

public class FileInputStreamDemo
{
	public static void main(String[] args)
	{   FileInputStream fis = null;
	    try{
			fis = new FileInputStream("FileInputStreamDemo.java");
			System.out.println("Available data: "+fis.available()+
                                   " bytes.");
			int c = fis.read();
			while(c != -1)
			{   System.out.print((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
		finally{
			try
			{   if(fis != null)
					fis.close();
			}
			catch(IOException ie)
			{ ie.printStackTrace(); }
		}		
	}
}


import java.io.*;

public class FileInputStreamDemo2
{
	public static void main(String[] args)
	{   // try-with-resources statement  
	    try(FileInputStream fis = 
                   new FileInputStream("FileInputStreamDemo2.java"))
		{
			System.out.println("Available data: "+fis.available()+
                                   " bytes.");
			int c;
			while((c = fis.read()) != -1)
			{   System.out.print((char)c);
				//c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
	}
}
import java.io.*;

public class FileOutputStreamDemo
{
	public static void main(String[] args)
	{   FileOutputStream fos = null;
	    FileInputStream  fis = null;
	    try{
			fis = new FileInputStream("FileOutputStreamDemo.java");
			fos = new FileOutputStream("out.txt");
			
			int c = fis.read();
			while(c != -1)
			{   fos.write((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
		finally
		{   try 
			{    if(fis != null)
					fis.close();
			}catch(IOException ie){ ie.printStackTrace(); }
			try 
			{    if(fos != null)
					fos.close();
			}catch(IOException ie){ ie.printStackTrace(); } 
		}		
	}
}

import java.io.*;

public class FileOutputStreamDemo2
{
	public static void main(String[] args)
	{   
	    try(FileInputStream fis = 
                           new FileInputStream("FileOutputStreamDemo2.java");
	        FileOutputStream  fos = new FileOutputStream("out2.txt", true);
		   )
		{   int c = fis.read();
			while(c != -1)
			{   fos.write((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)	{ ie.printStackTrace(); }
	}
}
import java.io.*;

public class FileInputStreamDemo
{
	public static void main(String[] args)
	{   FileInputStream fis = null;
	    try{
			fis = new FileInputStream("FileInputStreamDemo.java");
			System.out.println("Available data: "+fis.available()+
                                   " bytes.");
			int c = fis.read();
			while(c != -1)
			{   System.out.print((char)c);
				c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
		finally{
			try
			{   if(fis != null)
					fis.close();
			}
			catch(IOException ie)
			{ ie.printStackTrace(); }
		}		
	}
}


import java.io.*;

public class FileInputStreamDemo2
{
	public static void main(String[] args)
	{   // try-with-resources statement  
	    try(FileInputStream fis = 
                   new FileInputStream("FileInputStreamDemo2.java"))
		{
			System.out.println("Available data: "+fis.available()+
                                   " bytes.");
			int c;
			while((c = fis.read()) != -1)
			{   System.out.print((char)c);
				//c = fis.read();
			}
		}
		catch(IOException ie)
		{ ie.printStackTrace(); }
	}
}
<a href="https://maticz.com/insurance-software-development">Insurance Software Development</a>
Tap to Earn Game Scripts are specialized tools designed to create engaging and interactive "Tap to Earn" games, particularly for platforms like Telegram. These games utilize simple tapping mechanics, allowing users to earn rewards or points with each tap. The scripts simplify the development process, enabling even those with limited coding knowledge to quickly build functional and appealing games.

Hivelance is a top provider of Tap to Earn Game Clone Scripts. Their team of experienced developers will assist you in launching your T2E Telegram games, providing powerful source code with robust security and cutting-edge features.

Know More:

Web - https://www.hivelance.com/tap-to-earn-game-scripts
Telegram - Hivelance
WhatsApp - +918438595928
Mail - Sales@hivelance.com
<a href="https://maticz.com/adventure-game-development">Adventure game development</a>
You are already familiar with an HTML class, but JavaScript also has a class. In JavaScript, a class is like a blueprint for creating objects. It allows you to define a set of properties and methods, and instantiate (or create) new objects with those properties and methods.

The class keyword is used to declare a class. Here is an example of declaring a Computer class:

Example Code
class Computer {};

Classes have a special constructor method, which is called when a new instance of the class is created. The constructor method is a great place to initialize properties of the class. Here is an example of a class with a constructor method:

Example Code
class Computer {
  constructor() {
  }
}

The this keyword in JavaScript is used to refer to the current object. Depending on where this is used, what it references changes. In the case of a class, it refers to the instance of the object being constructed. You can use the this keyword to set the properties of the object being instantiated. Here is an example:

Example Code
class Computer {
  constructor() {
    this.ram = 16;
  }
}

Here is an example of instantiating the Computer class from earlier examples:

Example Code
const myComputer = new Computer();

<Html>  
<head>   
<title>  
Registration Page  
</title>  
</head>  
<body bgcolor="#96D4D4">
<h1>Registration Form</h1>  
<br>  
<form>  
  
<label> Username </label>         
<input type="text" id = "U1" size="15"/> <br> <br>  
<label> Password: </label>     
<input type="password" password="p1" size="15"/> <br> <br>  
  
<label>   
Course :  
</label>   
<select>  
<option value="Course">Course</option>  
<option value="CSE">CSE</option>  
<option value="IT">IT</option>  
<option value="ECE">ECE</option>  
<option value="EEE">EEE</option>  
<option value="CSM">CSM</option>  
<option value="CSD">CSD</option>  
</select>  
<br>  
<br>
<label>   
Section :  
</label><br>  
<input type="radio" name="A"/> A <br>  
<input type="radio" name="B"/> B <br>  <br>
  
<label>   
Gender :  
</label><br>  
<input type="radio" name="male"/> Male <br>  
<input type="radio" name="female"/> Female <br>  
<input type="radio" name="other"/> Other  
<br>  
<br>  
  
<label for="phone">phone:</label>
<input type="text" name="country code"  value="+91" size="2"/>   
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}" size="10"> <br><br>

<label>   
Mail :  
</label><br>  
<input type="email" id="email "name="email"/> <br>  <br>

<label>
State :
</label>
<select>
<option value = "select">select <br>
<option value = "TS">TS <br>
<option value = "AP">AP <br>
<option value = "TN">TN <br>
<option value = "KR">KR <br>
<option value = "BR">BR <br> <br>
</select> <br><br>
<input type="button" value="Submit"/>  
</form> 
 
</body>  
</html>  
import vertexai
from vertexai.generative_models import GenerativeModel

# TODO(developer): Update and un-comment below line
# project_id = "PROJECT_ID"

vertexai.init(project=project_id, location="us-central1")

model = GenerativeModel(model_name="gemini-1.5-flash-001")

response = model.generate_content(
    "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
)

print(response.text)
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

public class TextDemo implements ActionListener 

{ 

    private JFrame frame;

	private JTextField tf1, tf2, tf3;

	private JTextArea ta;

	private JLabel label, label2;

	private JButton b;

		

	public TextDemo()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		tf1 = new JTextField("Enter the name", 25); tf2 = new JTextField(20); tf3 = new JTextField("Enter a value");

		tf1.setFont(new Font("Verdana", Font.BOLD, 18));

		tf2.setFont(new Font("Verdana", Font.BOLD, 18));

		tf3.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(tf1); frame.add(tf2); frame.add(tf3);

		//tf1.addActionListener(this); tf2.addActionListener(this); tf3.addActionListener(this);

		

		ta = new JTextArea(20, 15);

		ta.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(ta);

				

		label = new JLabel();

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

		

		label2 = new JLabel();

		label2.setFont(new Font("Verdana", Font.BOLD, 18));

		label2.setForeground(Color.green);

		frame.add(label2);

		

		b = new JButton("Display");

		b.addActionListener(this);

		frame.add(b);

		

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

		public void actionPerformed(ActionEvent ae)

	{   String message ="";

		message += tf1.getText()+": ";

		message += tf2.getText()+": ";

		message += tf3.getText()+": ";

		label.setText(message);

		label2.setText(ta.getText());

	}

		

	public static void main(String[] args)

	{   new TextDemo();

	}

}
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

public class ListDemo implements ListSelectionListener

{ 

    private JFrame frame;

	private JList<String> list;

	private JLabel label;

	private JToolTip tip;

		public ListDemo()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", 

		                   "September", "October", "November", "December"};

		list = new JList<String>(months);

		list.addListSelectionListener(this);

		frame.add(list);

		

		//JScrollPane sp = new JScrollPane(list);

		//frame.add(sp);

		

		label = new JLabel("I show the selected Date");

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

		

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

	

	public void valueChanged(ListSelectionEvent ae)

	{   String message = "";

	    for(String each: list.getSelectedValuesList())

			message += each +" ";

		label.setText(message);		 

	}

	

	public static void main(String[] args)

	{   new ListDemo();

	}

}
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ComboBoxDemo2 implements ActionListener

{ 

    private JFrame frame;

	private JComboBox cb1, cb2, cb3;

	private JLabel label;

		public ComboBoxDemo2()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", 

		                   "September", "October", "November", "December"};

		cb1 = new JComboBox(); cb2 = new JComboBox(months); cb3 = new JComboBox();

		

		for(int i = 1; i<=31; i++){ cb1.addItem(i); }

		for(int i = 1970; i<2048; i++){ cb3.addItem(i); }	

				

		cb1.addActionListener(this); cb2.addActionListener(this); cb3.addActionListener(this);

		frame.add(cb1); frame.add(cb2); frame.add(cb3);

		

		label = new JLabel("I show the selected Date");

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

				

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

	

	public void actionPerformed(ActionEvent ae)

	{   String message = "";

	    message += (Integer)cb1.getSelectedItem()+", ";

		message += (String)cb2.getSelectedItem()+", ";

		message += (Integer)cb3.getSelectedItem();

		label.setText(message);		 

	}

	

	public static void main(String[] args)

	{   new ComboBoxDemo2();

	}

}
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ComboBoxDemo implements ActionListener

{ 

    private JFrame frame;

	private JComboBox cb;

	private JLabel label;

		

	public ComboBoxDemo()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		cb = new JComboBox();

		cb.addItem("Banana"); cb.addItem("Apple"); cb.addItem("Orange"); 

		cb.addItem("Grape");  cb.addItem("Mango"); cb.addItem("Pineapple");			

		

		cb.addActionListener(this);

		frame.add(cb);

		

		label = new JLabel("I show the selected item");

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

				

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

		public void actionPerformed(ActionEvent ae)

	{   label.setText((String)cb.getSelectedItem());		 

	}

	

	public static void main(String[] args)

	{   new ComboBoxDemo();

	}

}
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class RadioButtonDemo implements ActionListener

{ 

    private JFrame frame;

	private JRadioButton c1, c2, c3, c4;

	private JLabel label;

	 

	public RadioButtonDemo()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		c1 = new JRadioButton("Pizza");

		c1.addActionListener(this);

		c1.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c1);

		

		c2 = new JRadioButton("Burger");

		c2.addActionListener(this);

		c2.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c2);

		

		c3 = new JRadioButton("Rolls");

		c3.addActionListener(this);

		c3.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c3);

		

		c4 = new JRadioButton("Beverage");

		c4.addActionListener(this);

		c4.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c4);

		

		ButtonGroup bg = new ButtonGroup();

		bg.add(c1); bg.add(c2); bg.add(c3); bg.add(c4);

		

		label = new JLabel("I show the selected items");

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

				

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

		public void actionPerformed(ActionEvent ae)

	{   label.setText(ae.getActionCommand());		 

	}

	

	public static void main(String[] args)

	{   new RadioButtonDemo();

	}

}
var link = React.DOM.a({
                    href: this.makeHref('login')
                },
                'log in'
            );// or React.createElement or
//var link = <a href={this.makeHref('login')}>
//   'log in'</a>;
<div>{'Please '+ link + ' with your email...'}</div>
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class CheckBoxDemo implements ItemListener

{ 

private JFrame frame;

	private JCheckBox c1, c2, c3, c4;

	private JLabel label;

	private String message =" ";

		public CheckBoxDemo()

	{

		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		 

		frame.setLayout(new FlowLayout());	

		

		c1 = new JCheckBox("Pizza");

		c1.addItemListener(this);

		c1.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c1);

		

		c2 = new JCheckBox("Burger");

		c2.addItemListener(this);

		c2.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c2);

		

		c3 = new JCheckBox("Rolls");

		c3.addItemListener(this);

		c3.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c3);

		

		c4 = new JCheckBox("Beverage");

		c4.addItemListener(this);

		c4.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(c4);

		

		label = new JLabel("I show the selected items");

		label.setFont(new Font("Verdana", Font.BOLD, 18));

		label.setForeground(Color.RED);

		frame.add(label);

		

		

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

	

	public void itemStateChanged(ItemEvent ie)

	{

		if(c1.isSelected())

			message += c1.getText() +" ";

		if(c2.isSelected())

			message += c2.getText() +" ";

		if(c3.isSelected())

			message += c3.getText() +" ";

		if(c4.isSelected())

			message += c4.getText() +" ";

		label.setText(message);

		

		message = " ";

	}

	

	public static void main(String[] args)

	{

		new CheckBoxDemo();

	}

}
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ButtonDemo  

{   private JFrame frame;

    private JLabel label;

	private JButton b1, b2; 

		public ButtonDemo()

	{

		frame = new JFrame("A Simple Swing App");

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		

		frame.setLayout(new FlowLayout());	

		

		label = new JLabel("I show the button text");

		label.setFont(new Font("Verdana", Font.BOLD, 18));	

		frame.add(label);

		

		b1 = new JButton("The First Button");

		b1.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(b1);

		b1.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent ae)

			{   label.setText(b1.getText()+" is pressed!"); 	}

		});

		

		b2 = new JButton("The Second Button");

		b2.setFont(new Font("Verdana", Font.BOLD, 18));

		frame.add(b2);

		b2.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent ae)

			{   label.setText(b2.getText()+" is pressed!"); 	}

		});

				

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

	

	public static void main(String[] args)

	{   new ButtonDemo();

	}

}

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class LabelDemo

{   private JFrame frame;

    private JLabel label;

	 

	public LabelDemo()

	{

		frame = new JFrame("A Simple Swing App");

		Toolkit tk = frame.getToolkit();

		Dimension dim = tk.getScreenSize();

		int width = (int)dim.getWidth();

		int height = (int)dim.getHeight();

		frame.setSize(width, height);

		

		frame.setLayout(new FlowLayout());	

		

		ImageIcon ic = new ImageIcon("Animated_butterfly.gif");

		

		label = new JLabel("A Butterfly", ic, JLabel.CENTER);

		label.setFont(new Font("Verdana", Font.BOLD, 18));	

		label.setBackground(Color.yellow);

		frame.add(label);

				

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setVisible(true);

	}

		public static void main(String[] args)

	{   new LabelDemo();

	}

}
When preparing an interview for publication, please ensure the following types of content are edited out to maintain political correctness, inclusivity, and to avoid legal issues:

Offensive language, including profanity and derogatory terms.
Discriminatory remarks based on race, gender, sexuality, or other protected characteristics.
Unsubstantiated claims or potentially libelous statements.
Personal attacks or defamatory comments about individuals or organizations.
Confidential or sensitive information that breaches privacy laws.
Strong political opinions or endorsements that are not relevant to the publication.
Inappropriate jokes or comments that could be perceived as insensitive.
Negative comments about competitors or other professionals in the field.
Inflammatory statements that could incite violence or public outrage.
Unprofessional comments that reflect poorly on the interviewee or the publication.
Any content that could lead to legal action, such as defamatory statements or breaches of confidentiality.
Misleading information or factually incorrect statements.
Excessive self-promotion that detracts from the informative nature of the interview.
Ambiguous statements that are unclear or open to misinterpretation.
Sensitive cultural references that could be seen as disrespectful.
Please review and edit the interview content carefully to ensure it adheres to these guidelines.

This prompt can help journalists ensure their interviews are polished and safe for publication.
TextDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class TextDemo implements ActionListener
{
    private JFrame frame;
	private JTextField tf1, tf2, tf3;
	private JTextArea ta;
	private JLabel label, label2;
	private JButton b;

	public TextDemo()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		tf1 = new JTextField("Enter the name", 25); tf2 = new JTextField(20); tf3 = new JTextField("Enter a value");
		tf1.setFont(new Font("Verdana", Font.BOLD, 18));
		tf2.setFont(new Font("Verdana", Font.BOLD, 18));
		tf3.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(tf1); frame.add(tf2); frame.add(tf3);
		//tf1.addActionListener(this); tf2.addActionListener(this); tf3.addActionListener(this);

		ta = new JTextArea(20, 15);
		ta.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(ta);

		label = new JLabel();
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);

		label2 = new JLabel();
		label2.setFont(new Font("Verdana", Font.BOLD, 18));
		label2.setForeground(Color.green);
		frame.add(label2);

		b = new JButton("Display");
		b.addActionListener(this);
		frame.add(b);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{   String message ="";
		message += tf1.getText()+": ";
		message += tf2.getText()+": ";
		message += tf3.getText()+": ";
		label.setText(message);
		label2.setText(ta.getText());
	}

	public static void main(String[] args)
	{   new TextDemo();
	}
}
ListDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ListDemo implements ListSelectionListener
{
    private JFrame frame;
	private JList<String> list;
	private JLabel label;
	private JToolTip tip;

	public ListDemo()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		String[] months = {"January", "February", "March", "April", "May", "June", "July", "August",
		                   "September", "October", "November", "December"};
		list = new JList<String>(months);
		list.addListSelectionListener(this);
		frame.add(list);

		//JScrollPane sp = new JScrollPane(list);
		//frame.add(sp);

		label = new JLabel("I show the selected Date");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void valueChanged(ListSelectionEvent ae)
	{   String message = "";
	    for(String each: list.getSelectedValuesList())
			message += each +" ";
		label.setText(message);
	}

	public static void main(String[] args)
	{   new ListDemo();
	}
}
ComboBoxDemo2.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxDemo2 implements ActionListener
{
    private JFrame frame;
	private JComboBox cb1, cb2, cb3;
	private JLabel label;

	public ComboBoxDemo2()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		String[] months = {"January", "February", "March", "April", "May", "June", "July", "August",
		                   "September", "October", "November", "December"};
		cb1 = new JComboBox(); cb2 = new JComboBox(months); cb3 = new JComboBox();

		for(int i = 1; i<=31; i++){ cb1.addItem(i); }
		for(int i = 1970; i<2048; i++){ cb3.addItem(i); }

		cb1.addActionListener(this); cb2.addActionListener(this); cb3.addActionListener(this);
		frame.add(cb1); frame.add(cb2); frame.add(cb3);

		label = new JLabel("I show the selected Date");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{   String message = "";
	    message += (Integer)cb1.getSelectedItem()+", ";
		message += (String)cb2.getSelectedItem()+", ";
		message += (Integer)cb3.getSelectedItem();
		label.setText(message);
	}

	public static void main(String[] args)
	{   new ComboBoxDemo2();
	}
}
ComboBoxDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxDemo implements ActionListener
{
    private JFrame frame;
	private JComboBox cb;
	private JLabel label;

	public ComboBoxDemo()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		cb = new JComboBox();
		cb.addItem("Banana"); cb.addItem("Apple"); cb.addItem("Orange");
		cb.addItem("Grape");  cb.addItem("Mango"); cb.addItem("Pineapple");

		cb.addActionListener(this);
		frame.add(cb);

		label = new JLabel("I show the selected item");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{   label.setText((String)cb.getSelectedItem());
	}

	public static void main(String[] args)
	{   new ComboBoxDemo();
	}
}
RadioButtonDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class RadioButtonDemo implements ActionListener
{
    private JFrame frame;
	private JRadioButton c1, c2, c3, c4;
	private JLabel label;

	public RadioButtonDemo()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		c1 = new JRadioButton("Pizza");
		c1.addActionListener(this);
		c1.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c1);

		c2 = new JRadioButton("Burger");
		c2.addActionListener(this);
		c2.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c2);

		c3 = new JRadioButton("Rolls");
		c3.addActionListener(this);
		c3.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c3);

		c4 = new JRadioButton("Beverage");
		c4.addActionListener(this);
		c4.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c4);

		ButtonGroup bg = new ButtonGroup();
		bg.add(c1); bg.add(c2); bg.add(c3); bg.add(c4);

		label = new JLabel("I show the selected items");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{   label.setText(ae.getActionCommand());
	}

	public static void main(String[] args)
	{   new RadioButtonDemo();
	}
}
CheckBoxDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CheckBoxDemo implements ItemListener
{
private JFrame frame;
	private JCheckBox c1, c2, c3, c4;
	private JLabel label;
	private String message =" ";

	public CheckBoxDemo()
	{
		frame = new JFrame("A Simple Swing App");

		//frame.setSize(600, 400);
		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		c1 = new JCheckBox("Pizza");
		c1.addItemListener(this);
		c1.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c1);

		c2 = new JCheckBox("Burger");
		c2.addItemListener(this);
		c2.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c2);

		c3 = new JCheckBox("Rolls");
		c3.addItemListener(this);
		c3.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c3);

		c4 = new JCheckBox("Beverage");
		c4.addItemListener(this);
		c4.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(c4);

		label = new JLabel("I show the selected items");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setForeground(Color.RED);
		frame.add(label);


		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public void itemStateChanged(ItemEvent ie)
	{
		if(c1.isSelected())
			message += c1.getText() +" ";
		if(c2.isSelected())
			message += c2.getText() +" ";
		if(c3.isSelected())
			message += c3.getText() +" ";
		if(c4.isSelected())
			message += c4.getText() +" ";
		label.setText(message);

		message = " ";
	}

	public static void main(String[] args)
	{
		new CheckBoxDemo();
	}
}
ButtonDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonDemo  
{   private JFrame frame;
    private JLabel label;
	private JButton b1, b2;

	public ButtonDemo()
	{
		frame = new JFrame("A Simple Swing App");

		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		label = new JLabel("I show the button text");
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(label);

		b1 = new JButton("The First Button");
		b1.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(b1);
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{   label.setText(b1.getText()+" is pressed!"); 	}
		});

		b2 = new JButton("The Second Button");
		b2.setFont(new Font("Verdana", Font.BOLD, 18));
		frame.add(b2);
		b2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{   label.setText(b2.getText()+" is pressed!"); 	}
		});

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public static void main(String[] args)
	{   new ButtonDemo();
	}
}
LabelDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LabelDemo
{   private JFrame frame;
    private JLabel label;

	public LabelDemo()
	{
		frame = new JFrame("A Simple Swing App");

		Toolkit tk = frame.getToolkit();
		Dimension dim = tk.getScreenSize();
		int width = (int)dim.getWidth();
		int height = (int)dim.getHeight();
		frame.setSize(width, height);

		frame.setLayout(new FlowLayout());

		ImageIcon ic = new ImageIcon("Animated_butterfly.gif");

		label = new JLabel("A Butterfly", ic, JLabel.CENTER);
		label.setFont(new Font("Verdana", Font.BOLD, 18));
		label.setBackground(Color.yellow);
		frame.add(label);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public static void main(String[] args)
	{   new LabelDemo();
	}
}
import java.util.LinkedList;

class SharedResource {
    private LinkedList buffer = new LinkedList<>();
    private int capacity = 2;

    public void produce() throws InterruptedException {
        synchronized (this) {
            while (buffer.size() == capacity) {
                wait();
            }

            int item = (int) (Math.random() * 100);
            System.out.println("Produced: " + item);
            buffer.add(item);

            notify();
        }
    }

    public void consume() throws InterruptedException {
        synchronized (this) {
            while (buffer.isEmpty()) {
                wait();
            }

            int item = buffer.removeFirst();
            System.out.println("Consumed: " + item);

            notify();
        }
    }
}

class Producer extends Thread {
    private SharedResource sharedResource;

    public Producer(SharedResource sharedResource) {
        this.sharedResource = sharedResource;
    }

    @Override
    public void run() {
        try {
            while (true) {
                sharedResource.produce();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Consumer extends Thread {
    private SharedResource sharedResource;

    public Consumer(SharedResource sharedResource) {
        this.sharedResource = sharedResource;
    }

    @Override
    public void run() {
        try {
            while (true) {
                sharedResource.consume();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class ProducerConsumerExample {
    public static void main(String[] args) {
        SharedResource sharedResource = new SharedResource();

        Producer producer = new Producer(sharedResource);
        Consumer consumer = new Consumer(sharedResource);

        producer.start();
        consumer.start();
    }
}
class MyThread extends Thread {
    public void run() {
        System.out.println("run method");
        System.out.println("run method priority: " + Thread.currentThread().getPriority());
        Thread.currentThread().setPriority(4);
        System.out.println("run method priority after setting: " + Thread.currentThread().getPriority());
    }

    public static void main(String[] args) {
        System.out.println("main method");
        System.out.println("main method priority before setting: " + Thread.currentThread().getPriority());

        Thread.currentThread().setPriority(9);

        System.out.println("main method priority after setting: " + Thread.currentThread().getPriority());
    }
}
class MyThread implements Runnable {

    public void run() {
        System.out.println("Hello");
        System.out.println("DS");
    }

    public static void main(String[] args) {
        MyThread obj = new MyThread();
        Thread t = new Thread(obj);
        t.start();
    }
}
star

Mon Jul 08 2024 13:59:19 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:19:26 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:18:17 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:17:26 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:15:56 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:15:18 GMT+0000 (Coordinated Universal Time) https://maticz.com/medicine-delivery-app-development

@Ameliasebastian #medicinedeliveryapps

star

Mon Jul 08 2024 13:11:16 GMT+0000 (Coordinated Universal Time)

@emjumjunov

star

Mon Jul 08 2024 13:07:40 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:06:35 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:04:56 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:03:22 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:02:37 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:02:01 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 13:01:05 GMT+0000 (Coordinated Universal Time) https://maticz.com/cryptocurrency-payment-gateway-development

@Ameliasebastian #cryptopaymentgatewaydevelopmnent

star

Mon Jul 08 2024 12:59:30 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 12:58:44 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 12:57:07 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 12:56:22 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 12:35:57 GMT+0000 (Coordinated Universal Time) https://maticz.com/insurance-software-development

@Ameliasebastian #insurancesoftware

star

Mon Jul 08 2024 10:45:27 GMT+0000 (Coordinated Universal Time) https://maticz.com/adventure-game-development

@Ameliasebastian #adventuregamedevelopment

star

Mon Jul 08 2024 10:04:36 GMT+0000 (Coordinated Universal Time)

@NoFox420 #javascript

star

Mon Jul 08 2024 10:02:06 GMT+0000 (Coordinated Universal Time)

@user01

star

Mon Jul 08 2024 09:43:27 GMT+0000 (Coordinated Universal Time) https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal?hl

@Spsypg #python

star

Mon Jul 08 2024 09:43:18 GMT+0000 (Coordinated Universal Time) https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal?hl

@Spsypg #sh

star

Mon Jul 08 2024 09:43:08 GMT+0000 (Coordinated Universal Time) https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal?hl

@Spsypg #sh

star

Mon Jul 08 2024 08:17:41 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/python-programming/online-compiler/

@Ethan123

star

Mon Jul 08 2024 07:13:58 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:12:25 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:11:46 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:10:49 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:09:19 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:09:15 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/30208108/make-part-of-the-text-as-link-react-localization?answertab

@deepakm__ #javascript

star

Mon Jul 08 2024 07:08:16 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:07:10 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 07:06:27 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 06:40:09 GMT+0000 (Coordinated Universal Time)

@miskat80

star

Mon Jul 08 2024 06:31:43 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:31:00 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:30:23 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:29:42 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:28:59 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:28:09 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:27:24 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:26:42 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:21:34 GMT+0000 (Coordinated Universal Time)

@varuntej #java

star

Mon Jul 08 2024 06:20:52 GMT+0000 (Coordinated Universal Time)

@varuntej #java

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension