Get lock on all objects with in a collection or list


if(list.stream().allMatch(object -> lock.writeLock().tryLock())) {
    // code that works on all objects
}

How to set JFrame to appear centered, regardless of monitor resolution?

This method has a special effect when you pass it a null. According to the Javadoc:
If the component is null, or the GraphicsConfiguration associated with this component is null, the window is placed in the center of the screen.
This should be done after setting the size or calling pack(), but before setting it visible, like this:
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

All permutations of string

public static void permutation(String str) { 
    permutation("", str); 
}

private static void permutation(String prefix, String str) {
    int n = str.length();
    if (n == 0) System.out.println(prefix);
    else {
        for (int i = 0; i < n; i++)
            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
    }
}

how to handle data:image/gif;base64,

"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'; img-src: 'self' data:"

Lot more coming in this line. Stay tuned...

Where is Java Installed on Mac OS X?

Use /usr/libexec/java_home -v 1.7 command on a terminal shell to figure out where is your java 1.7 home directory

Find if a string is a integer or not in Java

public static boolean isInteger(String s) {
    return isInteger(s,10);
}

public static boolean isInteger(String s, int radix) {
    if(s.isEmpty()) return false;
    for(int i = 0; i < s.length(); i++) {
        if(i == 0 && s.charAt(i) == '-') {
            if(s.length() == 1) return false;
            else continue;
        }
        if(Character.digit(s.charAt(i),radix) < 0) return false;
    }
    return true;
}

Changing Tomcat default web application

Add below line in server.xml in Host entry for localhost in server.xml.

<Context path="" docBase="whatsapp-direct" />


Result:


<Host name="localhost">

                <!-- SingleSignOn valve, share authentication between web applications 
                    Documentation at: /docs/config/valve.html -->
                <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" 
                    /> -->

                <!-- Access log processes all example. Documentation at: /docs/config/valve.html 
                    Note: The pattern used is equivalent to using pattern="common" -->
                <Valve className="org.apache.catalina.valves.AccessLogValve"
                    directory="logs" prefix="localhost_access_log." suffix=".txt"
                    pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />

                <Context path="" docBase="/usr/local/tomcat/mywebapps/myapplication">
                    <WatchedResource>WEB-INF/web.xml</WatchedResource>
                </Context>

            </Host>