for java i use the listings package with following style:
\definecolor{javakeyword}{rgb}{0,0,0.5}
\definecolor{javastring}{rgb}{0,0.5,0}
\definecolor{javacomment}{rgb}{0.5,0.5,0.5}
\lstdefinestyle{java}{
language=Java,
showspaces=false,
showstringspaces=false,
basicstyle=\ttfamily,
columns=flexible,
stringstyle=\color{javastring},
keywordstyle=\color{javakeyword}\ttfamily\textbf,
commentstyle=\color{javacomment}\ttfamily\textit
}
which i then use like
\begin{lstlisting}[float,style=Java,caption={Correct Logging example},label=lst:logging]
private static final Log log = LogFactory.getLog(MyClass.class);
public void doSomeStuff(Stuff stuff) throws StuffException {
checkNotNull(stuff,"stuff should not be null");
}
\end{listlisting}