How to put codes nicely in Blog Using SyntaxHighlighter

Link

Change template is one time thing. After that, whenever you need put codes into blog, in HTML mode, put codes between

<pre class="brush:java"> ... </pre>

<script type="syntaxhighlighter" class="brush:xml">
</script>

You have the option to change the type of language, just as we are using java here, here is the list of the supported languages.

class='brush:java'
class='brush:as3'   //action script 3
class='brush:bash'
class='brush:css'
class='brush:groovy'
class='brush:js'    //java script
class='brush:py'
class='brush:sql'
class='brush:xml' //xml, xslt, html

My Template: add before </head>

Faster Copy Files

 
public static void copyFile(File sourceFile, File destFile) throws IOException 
{
  if (!destFile.exists()) 
  {
    destFile.createNewFile();
  }

  FileChannel source = null;
  FileChannel destination = null;
  try 
  {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    destination.transferFrom(source, 0, source.size());
  } 
  finally 
  {
    if (source != null) 
    {
      source.close();
    }
    if (destination != null) 
    {
      destination.close();
    }
  }
}
    
Link

XStream

http://xstream.codehaus.org/
http://www.ibm.com/developerworks/xml/library/x-xstream/
Library of serializing object to XML and deserializing object back from XML
1) Example of converting a list of object into a XML file:
public boolean XStream2XML(List importEntryList, String strOutXMLFilePath) 
{
  XStream xs = new XStream();

  //by default, xstream will use class's full name
  //you could use alias to avoid that
  xs.alias("entryList", List.class);
  xs.alias("importentry", ImportEntry.class);
  xs.alias("attribute", Attribute.class);

  try 
  {
    FileOutputStream fs = new FileOutputStream(strOutXMLFilePath);
    xs.toXML(importEntryList, fs);
    //a simpler version
    //String xml = xs.toXML(importEntryList);
    fs.close();
  } 
  catch (Exception e1) 
  {
    //e1.printStackTrace();
    return false;
  }

  return true;
}
2) Example of converting XML back to Java Object
String xml = "......";
Person newJoe = (Person)xstream.fromXML(xml);

Create Symbolic Link

ln -s source_file link_name

Java Preferences

Here is the situation, you want to save some user preferences, for example, I like certain columns for a given table, I don't want to customize it every time, I'd like to save it. Originally, I thought I might need a configuration file to achieve this, but soon I realize that it would be a pain, first of all, where to put this file? if my application is achieved, I don't even have the access the application folder. Secondly, every time I update the file, I need search this file and remove the old entry. I think there got to be a better way to do this.

Link
Link

In windows, it's stored under
HKEY_CURRENT_USER\Software\JavaSoft\Prefs

Just so we know, that we could import and export part of Registry, in this way, if we change our machine, we could just export/import and go.