RSS feed [root] /weblog /java /hacks



title search:


Thu Apr 06 06:33:18 GMT 2023


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

Tue May 03 14:08:30 GMT 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 11:59:31 GMT 2021 From /weblog/java/hacks

corner case

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

(google search) (amazon search)

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


(google search) (amazon search)

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


Funny, using gcc preprocessor with java -

(google search) (amazon search)

Tue Sep 11 14:21:17 GMT 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)

Sat Oct 29 18:36:47 GMT 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)

Sun Jul 26 17:08:14 GMT 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)

Mon Mar 17 17:25:28 GMT 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 11:12:13 GMT 2007 From /weblog/java/hacks


of various java server -
of various java technology -

(google search) (amazon search)

Thu May 03 07:30:15 GMT 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 08:12:43 GMT 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 09:34:38 GMT 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)

Thu Nov 30 15:22:16 GMT 2006 From /weblog/java/hacks


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

(google search) (amazon search)

Sat Nov 11 10:03:05 GMT 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 05:11:24 GMT 2006 From /weblog/java/hacks


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

(google search) (amazon search)

Wed Jul 12 08:09:26 GMT 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 06:32:59 GMT 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 07:30:58 GMT 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 05:13:55 GMT 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 08:35:14 GMT 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 04:27:06 GMT 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)