RSS feed [root] /hacks /weblog /java



title search:


Wed May 04 00:08:30 AEST 2022


(google search) (amazon search)
download zip of files only

Wed May 04 00:08:30 AEST 2022 From /weblog/java/hacks


Hint to prevent blocking of loadClass by using Thread.getContextClassLoader() -[..]3/java-class-loading-performance-impact/

(google search) (amazon search)

Sun Oct 17 22:59:31 AEDT 2021 From /weblog/java/hacks

corner case

Corner case cheat sheet in Java -[..]cornerCaseCheatSheet/cheatSheetJava.html

(google search) (amazon search)

Wed Dec 18 18:53:04 AEDT 2013 From /weblog/java/hacks


(google search) (amazon search)

Thu Dec 05 16:16:04 AEDT 2013 From /weblog/java/hacks


Funny, using gcc preprocessor with java -

(google search) (amazon search)

Wed Sep 12 00:21:17 AEST 2012 From /weblog/java/hacks


How JVM optimzate the code by understanding the intentional of programmer -[..]/arithmetic-overflow-and-intrinsics.html

(google search) (amazon search)

Sun Oct 30 05:36:47 AEDT 2011 From /weblog/java/hacks

cracking java

"hi there".equals("cheers !") == true
This is because in the JDK 1.3 SUN is caching the hash code so if it once is calculated, it doesn't get recalculated, so if the value field changes, the hashcode stays the same.

How to Modifying an Application without Modifying Its Source Code, with {-Xbootclasspath/p:} -[..]M4OQSNDLPCKH0CJUNN2JVN?_requestid=186396

Override string! -

(google search) (amazon search)

Mon Jul 27 03:08:14 AEST 2009 From /weblog/java/hacks


How to get line number of specific stacktrace
private static void log(String prefix,
String message) {

StackTraceElement ste =
new Exception().getStackTrace()[2];

System.out.println("[" + prefix + "] " +
ste.getClassName() + "." +
ste.getMethodName() + "(" +
ste.getLineNumber() + "): " +

Annotation of using stacktrace -[..]m/news/thread.tss?thread_id=55238#312195

(google search) (amazon search)

Tue Mar 18 04:25:28 AEDT 2008 From /weblog/java/hacks


if you do a “kill -3? of the java process id, it dumps a stack trace of every thread, including what locks it’s holding, to stdout. -[..]ie-says-kill-3-pid-is-my-new-best-friend

At windows, it is ctrl-break

(google search) (amazon search)

Sun May 13 21:12:13 AEST 2007 From /weblog/java/hacks


of various java server -
of various java technology -

(google search) (amazon search)

Thu May 03 17:30:15 AEST 2007 From /weblog/java/hacks


This should not really matter for deployment case, but for development which keep on restarting may be useful

Edit JAR in code -[..]og/java-se/how-to-modify-a-jar-file.html

(google search) (amazon search)

Fri Apr 27 18:12:43 AEST 2007 From /weblog/java/hacks

Throws NULL

We can just

throw null;

in java, but probably not a good idea for most case[..]hrowing-null-with-different-jvm-options/

(google search) (amazon search)

Thu Feb 15 20:34:38 AEDT 2007 From /weblog/java/hacks

Interesting and useless trick

change intern String:

limitation of string size, parameter list length, ... etc:[..]ive/ and
Related is Size limitation of Java String -

generating nullpointerexception from throw NULL:

When no nullpointerexception when object is null:

(google search) (amazon search)

Fri Dec 01 02:22:16 AEDT 2006 From /weblog/java/hacks


optimizing java class for j2me, look like just break all OO principle...

(google search) (amazon search)

Sat Nov 11 21:03:05 AEDT 2006 From /weblog/java/hacks

bitwise operation on boolean

bitwise operation on boolean

The solution to the puzzle is given in the Java Language Specification, chapter 15.22.2:
15.22.2 Boolean Logical Operators &, ^, and |
When both operands of a &, ^, or | operator are of type boolean, then the type of the bitwise operator expression is boolean.
For &, the result value is true if both operand values are true; otherwise, the result is false.
For ^, the result value is true if the operand values are different; otherwise, the result is false.
For |, the result value is false if both operand values are false; otherwise, the result is true.

Someone mentioned that there is no boolean, byte and short in byte code level, all just integer

(google search) (amazon search)

Tue Nov 07 16:11:24 AEDT 2006 From /weblog/java/hacks


Prevent System.exit() being call - Usually security manager forbid it

(google search) (amazon search)

Wed Jul 12 18:09:26 AEST 2006 From /weblog/java/hacks

Cracking class files

No sure if that still valid, but look like encrypt class file don't help on protecting class.[..]ld/javaqa/2003-05/01-qa-0509-jcrypt.html

(google search) (amazon search)

Mon Jun 26 16:32:59 AEST 2006 From /weblog/java/hacks

trick for java 5

New look of resultset, WebRowSet, , but I personally don't think this is something useful

Some information how using jmxagent:[..]nus/archive/2006/06/going_beyond_jd.html

Just come across a nice article that discuss about various new features of 1.5 and provide tips on how to use them:

Create collection quick

List programmingLanguages = CollectionUtils.newList("Java", "C++", "Ruby");

Or this:

Map langs = new HashMap(3) {{
put("Java", "Wicked");
put("C++", "Ok");
put("Ruby", "Interesting");

(google search) (amazon search)

Tue May 16 17:30:58 AEST 2006 From /weblog/java/hacks

equals() at proxy generated instance

At least need to test on the interface level. And more complicate if you don't want to expose the internal structure to interface

(google search) (amazon search)

Fri Apr 07 15:13:55 AEST 2006 From /weblog/java/hacks


I don't know this before, and I don't know if this is the behaviour of all Calendar implementation or it is only GregorianCalendar do this...

Every time you call set, Calendar sets a flag internally which indicates that something has changed. For performance reasons, the time is not actually computed until a call to getTime() (and variants).

The problem is that you are setting two conflicting states before computing the time:

thisMonth.set(Calendar.DAY_OF_MONTH, 1);
thisMonth.set(Calendar.DAY_OF_WEEK, 1);

According to the JavaDoc:
"If fields conflict, the calendar will give preference to fields set more recently."

Thus, in the second case, the call to set DAY_OF_MONTH is ignored.

(google search) (amazon search)

Wed Dec 14 19:35:14 AEDT 2005 From /weblog/java/hacks

beware of java inline

Usually java inline constant , this work fine most likely but sometime you will have surprise about this

(google search) (amazon search)

Tue Jul 12 14:27:06 AEST 2005 From /weblog/java/hacks

find file in classpath

This is kind of useful to have a quick way to find file in classpath, see if some day really deploy to system I work on:

(google search) (amazon search)