Java

Netbeans
<#assign licenseFirst = "/*"> <#assign licensePrefix = " * "> <#assign licenseLast = " */"> <#include "../Licenses/license-${project.license}.txt">

Encryption

 * http://code.google.com/p/winzipaes/source/browse/winzipaes/src/de/idyl/crypto/zip/AesZipFileEncrypter.java?spec=svn4&r=4
 * http://www.codestrider.com/BlogRead.aspx?b=d147ff4f-65e0-47f5-a39b-40ae07a42005

Memory Leaks
"Sun's official JVM, the garbage collector will be able to detect these cycles and free the memory as soon as there are no longer any references from the outside." "Yes. In C++ you have memory leaks when you lose all pointers to a block of memory and you have not yet freed the block. In java this can't happen, because an unreachable block of memory is eligible for garbage collection. In java you can have the reverse, where you have references to 'dead' objects that you don't use but that still be reached from the root set of pointers, so they can't be GCed." "The problem with this font manager class was that while the code put the font vector into the hashtable when the form was created, no provision was ever made to remove the vector when the form was deleted. Therefore, this static hashtable, which essentially existed for the life of the application itself, was never removing the keys that referenced each form. Consequently, the form and all of its associated classes were left dangling in memo" int *pi; void foo { pi = (int*) malloc(8*sizeof(int)); // oops, memory leak of 4 ints // use pi   free(pi); // foo is done with pi } void main { pi = (int*) malloc(4*sizeof(int)); foo; pi[0] = 10; // oops, pi is now a dangling pointer } "In Java, you will never have a dangling pointer or an unreferenced address because GC will reclaim the heap chunk if there is not reference to it. Instead, in Java, if a program holds a reference to a heap chunk that is not used during the rest of its life." import java.io.IOException; import java.util.HashSet; import java.util.Random; import java.util.Vector;
 * Garbage Collection: Algorithms for Automatic Dynamic Memory Management
 * The Truth About Garbage Collection
 * http://stackoverflow.com/questions/176745/circular-references-in-java
 * http://www.velocityreviews.com/forums/t132863-how-memory-leaks-in-java.html
 * http://www.informit.com/articles/article.aspx?p=706207
 * Java may not leak - but programs can
 * allocate a large array in broad (static, class, global) scope and never use it after the first time ... possibly reallocate it on subsequent needs
 * http://www.ibm.com/developerworks/library/j-leaks/
 * http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/

public class LeakExample { static Vector myVector = new Vector; static HashSet pendingRequests = new HashSet;

public void slowlyLeakingVector(int iter, int count) { for (int i=0; i0; n--) { // Oops, it should be n>=0 myVector.removeElementAt(n); }		}	}

public void leakingRequestLog(int iter) { Random requestQueue = new Random; for (int i=0; i<iter; i++) { int newRequest = requestQueue.nextInt; pendingRequests.add(new Integer(newRequest)); // processed request, but forgot to remove it			// from pending requests }	}

public void noLeak(int size) { HashSet tmpStore = new HashSet; for (int i=0; i<size; ++i) { String leakingUnit = new String("Object: " + i); tmpStore.add(leakingUnit); }		// Though highest memory allocation happens in this // function, but all these objects get garbage // collected at the end of this method, so no leak. }

public static void main(String[] args) throws IOException { LeakExample javaLeaks = new LeakExample; for (int i=0; true; i++) { try { // sleep to slow down leaking process Thread.sleep(1000); } catch (InterruptedException e) { /* do nothing */ } System.out.println("Iteration: " + i); javaLeaks.slowlyLeakingVector(1000,10); javaLeaks.leakingRequestLog(5000); javaLeaks.noLeak(100000); }	} }
 * I guess I'd call these examples Logical leaks. The slowlyLeakingVector has a typo and never counts all the way back down. The intent was there but there is a syntax error. LeakingRequestLog also has a logical error - but in this case, the pending requests are never removed - and over the lifetime of an application, were that queue backed with a hashmap, it may grow to significant size all the while, older data not being used.
 * http://elliottback.com/wp/java-memory-leaks-w-finalize-examples/

- the finalizer could cause a leak if it didn't return public class finalizer { @Override protected void finalize throws Throwable { while (true) { Thread.yield; }	}

public static void main(String[] args) { while (true) { for (int i = 0; i < 100000; i++) { finalizer f = new finalizer; }

System.out.println("" + Runtime.getRuntime.freeMemory + " bytes free!"); }	} } - the finalizer could cause a leak if it threw an exception public class finalizer { @Override protected void finalize throws Throwable { throw new Exception("x"); }

public static void main(String[] args) { while (true) { for (int i = 0; i < 100000; i++) new finalizer;

System.out.println("" + Runtime.getRuntime.freeMemory + " bytes free!"); }	} }

Singleton
public class Singleton { // Private constructor prevents instantiation from other classes private Singleton { }  /**    * SingletonHolder is loaded on the first execution of Singleton.getInstance * or the first access to SingletonHolder.INSTANCE, not before. */  private static class SingletonHolder { public static final Singleton INSTANCE = new Singleton; }  public static Singleton getInstance { return SingletonHolder.INSTANCE; } }
 * http://en.wikipedia.org/wiki/Singleton_pattern

Clone

 * Avoid Clone
 * http://javapapers.com/core-java/java-clone-shallow-copy-and-deep-copy/
 * http://stackoverflow.com/questions/2326758/how-to-properly-override-clone-method
 * http://www.artima.com/intv/bloch13.html
 * http://adtmag.com/articles/2000/03/14/effective-javasolutions-for-implementing-dependable-clone-methods.aspx
 * http://www.javapractices.com/topic/TopicAction.do?Id=15

Concurrency

 * http://download.oracle.com/javase/tutorial/essential/concurrency/index.html

Netbeans
netbeans/project.properties project.license=apache20
 * http://wiki.netbeans.org/Java_EditorUsersGuide
 * http://netbeans.org/competition/win-with-netbeans/customize-java-template.html
 * http://platform.netbeans.org/tutorials/nbm-filetemplates.html

JSTL

 * JSTL SQL

Swing

 * http://www.miglayout.com/

Contracts
interface Time { ...
 * http://en.wikipedia.org/wiki/Eiffel_%28programming_language%29
 * http://google-opensource.blogspot.com/2011/02/contracts-for-java.html
 * http://www.polyglotprogramming.com/contract4j/
 * http://code.google.com/p/cofoja/

@Ensures({   "result >= 0",    "result <= 23"  }) int getHour;

@Requires({   "h >= 0",    "h <= 23"  }) @Ensures("getHour == h") void setHour(int h);

... }

Decompiler

 * http://www.varaneckas.com/jad

Security
use keytool -list -keystore C:\bea\JROCKI~1.5-3\jre\lib\security\cacerts to find the alias of that cert then keytool -delete -alias ... -keystore C:\bea\JROCKI~1.5-3\jre\lib\security\cacerts
 * http://webadm1n.blogspot.com/2010/04/oracle-jrockit-jdk-recent-cacerts.html
 * http://forums.oracle.com/forums/thread.jspa?threadID=1005269&tstart=30
 * InstallCert
 * SSLPoke
 * http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services

Resource Bundle

 * http://viralpatel.net/blogs/2009/10/loading-java-properties-files.html

Options
-DUseSunHttpHandler=true
 * weblogic and sun https collision?

Enterprise

 * JEE
 * Weblogic
 * JBoss
 * Security

Libraries

 * Hibernate
 * HSQLDB
 * Spring
 * Wicket

Apps

 * JGet

Tools

 * Jar
 * Eclipse
 * Maven

Effective Java

 * Equals

XML

 * http://stackoverflow.com/questions/831865/what-java-xml-library-do-you-recommend-to-replace-dom4j
 * http://www.xom.nu/
 * http://www.jdom.org/
 * http://atif-razzaq.blogspot.com/2009/01/jdom-vs-dom4j.html
 * http://www.rgagnon.com/javadetails/java-0408.html
 * http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
 * http://onjava.com/pub/a/onjava/2002/06/26/xml.html