Bukkit inventory set name

public static void setPlayerInventory(Player p) { Inventory teamselector = Bukkit.createInventory(null, 9*1, “Name of the inventory”); }

Detect operating system in java

class TestJava { public static void main(String[] args) { String operatingSystem = System.getProperty(“os.name”).toLowerCase(); if (operatingSystem.contains(“win”)){ System.out.println(“Operating system is Windows”); } else if (operatingSystem.contains(“osx”)){ System.out.println(“Operating system is OSX”); } else if (operatingSystem.contains(“nix”)){ System.out.println(“Operating system is NIX”); } else if (operatingSystem.contains(“nux”)){ System.out.println(“Operating system is NUX”); } else if (operatingSystem.contains(“aix”)){ System.out.println(“Operating system is *AIX”); } } } Output: … Read more

Show dialog fragment from adapter

public class TestPagerAdapter extends PagerAdapter{ private Context context; public YourPagerAdapter(Context c) { this.context = c; } @Override public void onClick(View v) { FragmentActivity fragmentActivity = (FragmentActivity)(context); FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager(); TestPagerAdapter alertDialog = new YourDialogFragment(); alertDialog.show(fragmentManager, “Fragment Alert Text”); } }

Upgrade java 8 to 11 in ubuntu

sudo apt-get install openjdk-11-jdk $ sudo update-alternatives –config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status * 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1500 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1500 manual mode 2 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1500 manual mode

Copy to clipboard java

import java.awt.datatransfer.StringSelection; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; String testString = “Text that needs to be copied into clipboard”; StringSelection stringSelectionObj = new StringSelection(testString); Clipboard clipboardObj = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboardObj.setContents(stringSelectionObj, null);

Java execution time

long startTime = System.nanoTime(); someProcessing(); long endTime = System.nanoTime(); //timeDuration will be in milliseconds, Divide by 1000000 to get milliseconds. long timeDuration = (endTime – startTime);