so lately Apple has been blocking the java plugin, this is due to some of those crazy java exploits out there. but for those that NEED to have Safari work with the java plugin, here is a little hack that fixes that.

Apple writes out to a file in:
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist

to block minimum java plugin versions. I attempted to use the one provided by Oracle, but still had issues, so to temporary hack is to change the version.

here is a script that does that (must run as sudo):

#!/bin/bash

echo "default is java version: 1.7.11.22"

JPLUGIN_VERSION="1.7.11.22"
JPLUGIN_NEW_VERSION="1.7.11.1"

if [ -n "$1" ]; then
JPLUGIN_VERSION="$1"
fi

echo "search for: $JPLUGIN_VERSION"

#cd /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources
cp XProtect.meta.plist XProtect.meta.plist.bak
sed 's/$JPLUGIN_VERSION/$JPLUGIN_NEW_VERSION/g' XProtect.meta.plist.bak > XProtect.meta.plist

echo "modified to: $JPLUGIN_NEW_VERSION"

download here:
java_version.sh

usage:

$ sudo ./java_version.sh


$ sudo ./java_version.sh 1.7.11.22

the smart way to do a redirect to something more permanent is not to do:

 
//standard re-direct
httpServletResponse.sendRedirect(newTargetUrl);

but do this instead:

//set to 301
httpServletResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
httpServletResponse.setHeader("Location", newTargetUrl);
httpServletResponse.setHeader("Connection", "close");

the difference is that instead of sending a default 302, we are sending a 301, which is more seo and bot friendly. i would suspect that you would only use this in a case where the origination url is always going to goto the new target url, otherwise keep using the regular way.

This is probably an old topic, but I still find others including myself making these mistakes, so I thought I would write about it.

Everyone should know what a singleton is, usually used when you need one instantiation of an object across the system.

The incorrect way

public class BadSingleton
{
	private static BadSingleton _instance;
	
	public static BadSingleton getInstance()
	{
		if(_instance==null)
		{
			_instance = new BadSingleton();
		}
		
		return _instance;
	}
	
	private BadSingleton()
	{
		//do initializations here
	}
}

The double checked locking way

This came about as an optimization for early JVMs, in the modern world – this is a bad practice.

public class VeryBadSingleton
{
	private static VeryBadSingleton _instance;
	
	public static VeryBadSingleton getInstance()
	{
		if(_instance==null)
		{
			synchronized(VeryBadSingleton.class)
			{
				if(_instance==null)
				{
					_instance = new VeryBadSingleton();
				}
			}
		}
		
		return _instance;
	}
	
	private VeryBadSingleton()
	{
		//do initializations here
	}
}

The correct way

public class CorrectSingleton
{
	private static CorrectSingleton _instance;
	
	public synchronized static CorrectSingleton getInstance()
	{
		if(_instance==null)
		{
			_instance = new CorrectSingleton();
		}
		
		return _instance;
	}
	
	private CorrectSingleton()
	{
		//do initializations here
	}
}