Snippets Collections
Get-Job -Command "*Get-Process*"

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
3      Job3            BackgroundJob   Running       True            localhost            Get-Process
$j = Get-Job -Name Job1
$ID = $j.InstanceID
$ID

Guid
----
03c3232e-1d23-453b-a6f4-ed73c9e29d55

Stop-Job -InstanceId $ID
Get-Job

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      Job1            BackgroundJob   Completed     True            localhost             $env:COMPUTERNAME
Get-Job
   [-IncludeChildJob]
   [-ChildJobState <JobState>]
   [-HasMoreData <Boolean>]
   [-Before <DateTime>]
   [-After <DateTime>]
   [-Newest <Int32>]
   [-Command <String[]>]
   [<CommonParameters>]
Get-Job
   [-IncludeChildJob]
   [-ChildJobState <JobState>]
   [-HasMoreData <Boolean>]
   [-Before <DateTime>]
   [-After <DateTime>]
   [-Newest <Int32>]
   [-Command <String[]>]
   [<CommonParameters>]
Get-Job
   [-IncludeChildJob]
   [-ChildJobState <JobState>]
   [-HasMoreData <Boolean>]
   [-Before <DateTime>]
   [-After <DateTime>]
   [-Newest <Int32>]
   [[-Id] <Int32[]>]
   [<CommonParameters>]
Get-Command
   [[-Name] <String[]>]
   [-Module <String[]>]
   [-FullyQualifiedModule <ModuleSpecification[]>]
   [-CommandType <CommandTypes>]
   [-TotalCount <Int32>]
   [-Syntax]
   [-ShowCommandInfo]
   [[-ArgumentList] <Object[]>]
   [-All]
   [-ListImported]
   [-ParameterName <String[]>]
   [-ParameterType <PSTypeName[]>]
   [<CommonParameters>]
Get-Command
   [-Verb <String[]>]
   [-Noun <String[]>]
   [-Module <String[]>]
   [-FullyQualifiedModule <ModuleSpecification[]>]
   [-TotalCount <Int32>]
   [-Syntax]
   [-ShowCommandInfo]
   [[-ArgumentList] <Object[]>]
   [-All]
   [-ListImported]
   [-ParameterName <String[]>]
   [-ParameterType <PSTypeName[]>]
   [<CommonParameters>]
Get-Process -Name Explorer, Winlogon, Services
$cmd = Get-Command Get-Random
$cmd.ParameterSets |
    Select-Object Name, IsDefault, @{n='Parameters';e={$_.ToString()}} |
    Format-Table -Wrap
NAME
    Get-Command

SYNOPSIS
    Gets all commands.

SYNTAX

    Get-Command [[-Name] <System.String[]>] [[-ArgumentList] <System.Object[]>]
    [-All] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript |
    Application | Script | Workflow | Configuration | All}]
    [-FullyQualifiedModule <Microsoft.PowerShell.Commands.ModuleSpecification[]>]
    [-ListImported] [-Module <System.String[]>] [-ParameterName <System.String[]>]
    [-ParameterType <System.Management.Automation.PSTypeName[]>]
    [-ShowCommandInfo] [-Syntax] [-TotalCount <System.Int32>]
    [-UseAbbreviationExpansion] [-UseFuzzyMatching] [<CommonParameters>]

    Get-Command [[-ArgumentList] <System.Object[]>] [-All]
    [-FullyQualifiedModule <Microsoft.PowerShell.Commands.ModuleSpecification[]>]
    [-ListImported] [-Module <System.String[]>] [-Noun <System.String[]>]
    [-ParameterName <System.String[]>]
    [-ParameterType <System.Management.Automation.PSTypeName[]>]
    [-ShowCommandInfo] [-Syntax] [-TotalCount <System.Int32>]
    [-Verb <System.String[]>] [<CommonParameters>]
...
Get-Command [[-ArgumentList] <Object[]>] [-Verb <string[]>] [-Noun <string[]>]
 [-Module <string[]>] [-FullyQualifiedModule <ModuleSpecification[]>]
 [-TotalCount <int>] [-Syntax] [-ShowCommandInfo] [-All] [-ListImported]
 [-ParameterName <string[]>] [-ParameterType <PSTypeName[]>]
 [<CommonParameters>]

Get-Command [[-Name] <string[]>] [[-ArgumentList] <Object[]>]
 [-Module <string[]>] [-FullyQualifiedModule <ModuleSpecification[]>]
 [-CommandType <CommandTypes>] [-TotalCount <int>] [-Syntax] [-ShowCommandInfo]
 [-All] [-ListImported] [-ParameterName <string[]>]
 [-ParameterType <PSTypeName[]>] [-UseFuzzyMatching]
 [-FuzzyMinimumDistance <uint>] [-UseAbbreviationExpansion]
 [<CommonParameters>]
Get-Help
   [[-Name] <String>]
   [-Path <String>]
   [-Category <String[]>]
   [-Component <String[]>]
   [-Functionality <String[]>]
   [-Role <String[]>]
   -ShowWindow
   [<CommonParameters>]
// Ensure object exists
currentAccount ||= {};

// Ensure movementsDates exists if currentAccount already has it defined
currentAccount.movementsDates ||= [];

// Add the current date in ISO format to the movementsDates array
currentAccount.movementsDates.push(new Date().toISOString());

console.log(currentAccount.movementsDates);
$category = CategoryModel::query()->whereJsonContains('slug->' . app()->getLocale(), $category)->first();
dd($category->toArray());
'policy' => Rule::requiredIf(function ()  {
                return request()->status == 1 && request()->is_single == 1;
            }),



  public function messages()
    {
        return [
            'policy.required' => 'Please select Policy if you select "Single" Option',
        ];
    }
dependencies:
  dartz: ^0.10.1
class Animal {

    // Method in the superclass

    void sound() {

        System.out.println("Animal makes a sound");

    }

}

class Dog extends Animal {

    // Overriding the sound method in the subclass

    @Override

    void sound() {

        System.out.println("Dog barks");

    }

}

class Cat extends Animal {

    // Overriding the sound method in the subclass

    @Override

    void sound() {

        System.out.println("Cat meows");

    }

}

public class Main {

    public static void main(String[] args) {

        Animal myDog = new Dog();

        Animal myCat = new Cat();

        myDog.sound(); // Outputs: Dog barks

        myCat.sound(); // Outputs: Cat meows

    }

}

<!DOCTYPE html>
<html>
 <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>My Mobile-First Approach</title>
   <style>
     /* Default styles for mobile */
     .grid-container-flex {
       display: flex;
       flex-direction: column;
       background-color: purple;
       font-size: 0.9rem;
       color: white;
       margin-top: 1rem;
       height: 9em;
     }

     .grid-container-grid {
       display: grid;
       grid-template-columns: 20em;
       height: 8em;
       font-size: 1.1rem;
     }

     /* Media query for tablets */
     @media (min-width: 768px) {
       .grid-container-flex {
         font-size: 1.3rem;
       }

       .grid-container-grid {
         grid-template-columns: none;
         height: 10em;
       }
     }

     /* Media query for desktops */
     @media (min-width: 1024px) {
       .grid-container-flex {
         font-size: 2rem;
       }

       .grid-container-grid {
         grid-template-columns: none;
         height: 12em;
       }
     }
   </style>
 </head>
 <body>
   <header>
     <h1>My Mobile-First Approach HTML Structuring</h1>
     <nav>
       <a href="">Home</a>
       <a href="">Shop</a>
       <a href="">Contact</a>
       <a href="">Store</a>
     </nav>
   </header>

   <main>
     <section class="grid-container-flex">
       <h2>About Us</h2>
       <p>We work with skilled artisans and select premium materials to craft footwear that stands the test of time</p>
     </section>

     <section class="grid-container-grid">
       <h2>Our Products</h2>
       <ul>
         <li>Men's shoes</li>
         <li>Women's Shoes</li>
         <li>Kid's Shoes</li>
       </ul>
     </section>

     <section>
       <h2>Contact Us</h2>
       <form>
         <label for="name">Name:</label>
         <input type="text" id="name" name="name">

         <label for="email">Email:</label>
         <input type="email" id="email" name="email">

         <label for="message">Message:</label>
         <textarea id="message" name="message"></textarea>

         <input type="submit" value="Send Message">
       </form>
     </section>
   </main>

   <footer>
     <p>&copy; 2023 My Mobile-First Approach Example. All rights reserved.</p>
   </footer>
 </body>
</html>
public class SumAvg {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6};
        int sum = 0;
        
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        
        double avg = (double) sum / array.length;
        
        System.out.println("Sum: " + sum);
        System.out.println("Average: " + avg);
    }
}
public class Command {
    public static void main(String[] args) {
        if (args.length > 0) {
            // Loop through each command-line argument
            for (int i = 0; i < args.length; i++) {
                // Print each argument along with its length
                System.out.println(args[i] + " " + args[i].length());
            }

            // Print the total number of arguments
            System.out.println("Total number of arguments: " + args.length);
        }
    }
}
// Custom exception class extending Exception

class CustomException extends Exception {

    public CustomException(String message) {

        super(message);

    }

}

// Custom error class extending Error

class CustomError extends Error {

    public CustomError(String message) {

        super(message);

    }

}

public class ThrowableAndExceptionDemo {

    public static void main(String[] args) {

        try {

            // Triggering custom exception

            triggerCustomException();

        } catch (CustomException e) {

            System.out.println("Caught custom exception: " + e.getMessage());

        } catch (Exception e) {

            System.out.println("Caught general exception: " + e.getMessage());

        }

        try {

            // Triggering custom error

            triggerCustomError();

        } catch (CustomError e) {

            System.out.println("Caught custom error: " + e.getMessage());

        } catch (Error e) {

            System.out.println("Caught general error: " + e.getMessage());

        }

        System.out.println("Program completed.");

    }

    // Method to trigger custom exception

    public static void triggerCustomException() throws CustomException {

        throw new CustomException("This is a custom exception.");

    }

    // Method to trigger custom error

    public static void triggerCustomError() {

        throw new CustomError("This is a custom error.");

    }

}

public class String_Builder {
    public static void main(String[] args) {
        StringBuilder s = new StringBuilder("hellooooooo");
        System.out.println(s);

        // Deleting characters from index 0 to 2 (exclusive)
        System.out.println(s.delete(0, 3));

        // Deleting the character at index 5
        System.out.println(s.deleteCharAt(5));

        // Inserting "Raghu" at index 3
        System.out.println(s.insert(3, "Varshith"));

        // Printing the length of the StringBuilder
        System.out.println(s.length());

        // Finding the last index of the string "oo"
        System.out.println(s.lastIndexOf("oo"));
    }
}
public class StringMethodsExample {
    public static void main(String[] args) {
        String str = "Hello, World!";

        // Length of the string
        int length = str.length();
        System.out.println("Length of the string: " + length);

        // Concatenation
        String newStr = str.concat(" How are you?");
        System.out.println("Concatenated string: " + newStr);

        // Substring
        String substring = str.substring(7);
        System.out.println("Substring from index 7: " + substring);

        // Character at a specific index
        char charAtIndex = str.charAt(0);
        System.out.println("Character at index 0: " + charAtIndex);

        // Index of a specific character
        int indexOfComma = str.indexOf(",");
        System.out.println("Index of comma: " + indexOfComma);

        // Conversion to lowercase and uppercase
        String lowercase = str.toLowerCase();
        String uppercase = str.toUpperCase();
        System.out.println("Lowercase: " + lowercase);
        System.out.println("Uppercase: " + uppercase);

        // Checking for presence of a substring
        boolean containsHello = str.contains("Hello");
        System.out.println("Contains 'Hello': " + containsHello);

        // Removing leading and trailing whitespaces
        String stringWithSpaces = "   Trim me   ";
        String trimmedString = stringWithSpaces.trim();
        System.out.println("Trimmed string: " + trimmedString);
    }
}
public class Student
{
	private String name;
	private String rollno;
	private int age;
	
	//Constructor
	public Student(String name,String rollno,int age)
	{
		this.name=name;
		this.rollno=rollno;
		this.age=age;
	}
	
	//Method
	public void display()
	{
		System.out.println("Name: "+this.name);
		System.out.println("Roll No: "+this.rollno);
		System.out.println("Age: "+this.age);
		
	}	
}
////////////////////////////////////////////////////////////////
public class StudentTest
{
	public static void main(String[] args)
	{
		Student s1= new Student("John","A100",22);
		Student s2= new Student("Abhi","5S0",18);
		
		s1.display();
		s2.display();
	}
}
public class MyMath{
    public static int add(int a, int b){
        return a+b;
    }
    public static double add(double a, double b){
        return a+b;

    }
    public static long add(long a,long b){
        return a+b;

    }
    public static float add(float a,float b){
        return a+b;
    }

}

///

public class MyMathTest{
    public static void main(String[] args){
        System.out.println(MyMath.add(1,2));
        System.out.println(MyMath.add(1234L,1432L));
        System.out.println(MyMath.add(1.27,24.8));
        System.out.println(MyMath.add(1.23F,1.45F));

    }
}
public class ExceptionHandlingDemo {

    public static void main(String[] args) {

        try {

            // Attempt to divide by zero

            int result = divide(10, 0);

            System.out.println("Result: " + result);

        } catch (ArithmeticException e) {

            // This block will execute when an ArithmeticException is caught

            System.out.println("Error: Division by zero is not allowed.");

        } finally {

            // This block will always execute

            System.out.println("This is the finally block, it always executes.");

        }

        try {

            // Attempt to access an invalid array index

            int[] array = {1, 2, 3};

            System.out.println("Array element: " + array[5]);

        } catch (ArrayIndexOutOfBoundsException e) {

            // This block will execute when an ArrayIndexOutOfBoundsException is caught

            System.out.println("Error: Array index out of bounds.");

        } finally {

            // This block will always execute

            System.out.println("This is the finally block for array access, it always executes.");

        }

        try {

            // Manually throwing an exception

            throwException();

        } catch (Exception e) {

            // This block will execute when a general Exception is caught

            System.out.println("Caught an exception: " + e.getMessage());

        } finally {

            // This block will always execute

            System.out.println("This is the finally block for throwException, it always executes.");

        }

    }

    // Method to demonstrate exception handling

    public static int divide(int a, int b) throws ArithmeticException {

        return a / b;

    }

    // Method to demonstrate manually throwing an exception

    public static void throwException() throws Exception {

        throw new Exception("This is a manually thrown exception.");

    }

}

public class StringBuilderDemo {

    public static void main(String[] args) {

        // Creating a StringBuilder object

        StringBuilder sb = new StringBuilder("Hello");

        // 1. append()

        sb.append(" World");

        System.out.println("After append: " + sb);

        // 2. insert()

        sb.insert(5, ",");

        System.out.println("After insert: " + sb);

        // 3. replace()

        sb.replace(5, 6, "!");

        System.out.println("After replace: " + sb);

        // 4. delete()

        sb.delete(5, 6);

        System.out.println("After delete: " + sb);

        // 5. deleteCharAt()

        sb.deleteCharAt(5);

        System.out.println("After deleteCharAt: " + sb);

        // 6. reverse()

        sb.reverse();

        System.out.println("After reverse: " + sb);

        

        // Reversing back to original for further operations

        sb.reverse();

        // 7. setCharAt()

        sb.setCharAt(5, '-');

        System.out.println("After setCharAt: " + sb);

        // 8. substring()

        String subStr = sb.substring(0, 5);

        System.out.println("Substring (0, 5): " + subStr);

        // 9. length()

        int length = sb.length();

        System.out.println("Length of StringBuilder: " + length);

        // 10. capacity()

        int capacity = sb.capacity();

        System.out.println("Capacity of StringBuilder: " + capacity);

        // Additional methods for better understanding

        // Ensure Capacity

        sb.ensureCapacity(50);

        System.out.println("New Capacity after ensureCapacity(50): " + sb.capacity());

        // Trim to Size

        sb.trimToSize();

        System.out.println("Capacity after trimToSize: " + sb.capacity());

    }

}
public class StringBufferDemo {

    public static void main(String[] args) {

        // Creating a StringBuffer object

        StringBuffer sb = new StringBuffer("Hello");

        // 1. append()

        sb.append(" World");

        System.out.println("After append: " + sb);

        // 2. insert()

        sb.insert(5, ",");

        System.out.println("After insert: " + sb);

        // 3. replace()

        sb.replace(5, 6, "!");

        System.out.println("After replace: " + sb);

        // 4. delete()

        sb.delete(5, 6);

        System.out.println("After delete: " + sb);

        // 5. deleteCharAt()

        sb.deleteCharAt(5);

        System.out.println("After deleteCharAt: " + sb);

        // 6. reverse()

        sb.reverse();

        System.out.println("After reverse: " + sb);

        

        // Reversing back to original for further operations

        sb.reverse();

        // 7. setCharAt()

        sb.setCharAt(5, '-');

        System.out.println("After setCharAt: " + sb);

        // 8. substring()

        String subStr = sb.substring(0, 5);

        System.out.println("Substring (0, 5): " + subStr);

        // 9. length()

        int length = sb.length();

        System.out.println("Length of StringBuffer: " + length);

        // 10. capacity()

        int capacity = sb.capacity();

        System.out.println("Capacity of StringBuffer: " + capacity);

        // Additional methods for better understanding

        // Ensure Capacity

        sb.ensureCapacity(50);

        System.out.println("New Capacity after ensureCapacity(50): " + sb.capacity());

        // Trim to Size

        sb.trimToSize();

        System.out.println("Capacity after trimToSize: " + sb.capacity());

    }

}
//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();
		}
		
	}
}

import java.io.*;
public class OutputStreamDemo{
	public static void main(String[] args){
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try{
			fis = new FileInputStream("input.txt");
			fos = new FileOutputStream("output.txt");
			System.out.println("Available data "+fis.available()+" data");
			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 InputStreamDemo{
	public static void main(String[] args){
	FileInputStream fis = null;
	try{
		fis = new FileInputStream("InputStreamDemo.java");
		System.out.println("Available data: "+fis.available()+" bytes");
		int c = fis.read();
		while(c!=-1){
			System.out.println((char)c);
			c = fis.read();
		}
	}
	catch(IOException ie){
		ie.printStackTrace();
	}
	finally{
		try{
			if(fis!=null)
				fis.close();
		}
		catch(IOException ie){
			ie.printStackTrace();
		}
	}
	}
}
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();
		}
	}
}
star

Tue Jul 09 2024 01:33:35 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:33:25 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:33:15 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:32:42 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:32:17 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:32:06 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-job?view

@Dewaldt

star

Tue Jul 09 2024 01:31:43 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-command?view

@Dewaldt

star

Tue Jul 09 2024 01:31:28 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-command?view

@Dewaldt

star

Tue Jul 09 2024 01:30:37 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:30:24 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:30:03 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:29:57 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:29:36 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:29:27 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:28:35 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:28:07 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:26:52 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:26:30 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:26:21 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/about/about_command_syntax?view

@Dewaldt

star

Tue Jul 09 2024 01:25:37 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-za/powershell/module/microsoft.powershell.core/get-help?view

@Dewaldt

star

Mon Jul 08 2024 22:54:44 GMT+0000 (Coordinated Universal Time)

@davidmchale #checking #object

star

Mon Jul 08 2024 19:47:45 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/66080731/laravel-8-x-where-json-search-in-array

@xsirlalo

star

Mon Jul 08 2024 19:30:30 GMT+0000 (Coordinated Universal Time) https://laracasts.com/discuss/channels/laravel/laravel-request-validation-rule-based-on-two-values

@xsirlalo

star

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

@Hussein

star

Mon Jul 08 2024 17:45:51 GMT+0000 (Coordinated Universal Time) https://www.blackbox.ai/playground?action

@j3d1n00b

star

Mon Jul 08 2024 17:40:56 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 16:43:52 GMT+0000 (Coordinated Universal Time) https://blog.openreplay.com/mobile-first-approach-with-html-and-css/

@Black_Shadow

star

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

@signup

star

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

@signup

star

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

@projectrock

star

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

@signup

star

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

@signup

star

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

@signup

star

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

@signup

star

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

@projectrock

star

Mon Jul 08 2024 15:45:55 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 15:45:11 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 15:19:46 GMT+0000 (Coordinated Universal Time)

@signup

star

Mon Jul 08 2024 14:51:56 GMT+0000 (Coordinated Universal Time)

@projectrock

star

Mon Jul 08 2024 14:50:56 GMT+0000 (Coordinated Universal Time)

@projectrock

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

Save snippets that work with our extensions

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