RSS feed [root] /hacks /weblog /java




login:

password:

title search:




 


Wed May 04 00:08:30 AEST 2022

hacks



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

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

classloading


Hint to prevent blocking of loadClass by using Thread.getContextClassLoader() - https://blog.fastthread.io[..]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 - https://ge0ffrey.github.io[..]cornerCaseCheatSheet/cheatSheetJava.html

(google search) (amazon search)


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

cglib


http://www.jroller.com[..]/20050506#java_dynamic_proxies_and_cglib

http://mydailyjava.blogspot.com.au[..]com.au/2013/11/cglib-missing-manual.html

(google search) (amazon search)


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

preprocessor


Funny, using gcc preprocessor with java - https://gist.github.com/anonymous/7797380

(google search) (amazon search)


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

Intrinsics


How JVM optimzate the code by understanding the intentional of programmer - http://bad-concurrency.blogspot.com.au[..]/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.

http://www.artima.com/forums/flat.jsp?forum=106&thread=4864

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

Override string! - http://www.javacodegeeks.com/2011/10/weird-funny-java.html

(google search) (amazon search)


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

exception


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() + "): " +
message);
}

http://jroller.com[..]0602#abusing_java_for_debugging_purposes

Annotation of using stacktrace - http://www.theserverside.com[..]m/news/thread.tss?thread_id=55238#312195

(google search) (amazon search)


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

kill


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. - http://blog.xcski.com[..]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

quickstart


of various java server - http://www.learntechnology.net/content/main.jsp
of various java technology - http://www.javapassion.com/j2ee/index.html

(google search) (amazon search)


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

jar


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

http://ant.apache.org/manual/CoreTasks/jar.html#indexjars

Edit JAR in code - http://www.java-tips.org[..]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

http://beanman.wordpress.com[..]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: http://cretesoft.com/archive/newsletter.do?issue=014

limitation of string size, parameter list length, ... etc: http://javaspecialists.co.za[..]ive/newsletter.do?issue=059&locale=en_US and http://www.javaspecialists.co.za/archive/newsletter.do?issue=121
Related is Size limitation of Java String - http://www.oreillynet.com/lpt/wlg/6303

generating nullpointerexception from throw NULL: http://fishbowl.pastiche.org/2003/04/30/throwing_null

When no nullpointerexception when object is null: http://fishbowl.pastiche.org/2006/01/17/random_java_trivia

(google search) (amazon search)


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

j2me


optimizing java class for j2me, look like just break all OO principle... http://blog.javia.org/?p=31

(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.

http://beust.com/weblog/archives/000350.html

Someone mentioned that there is no boolean, byte and short in byte code level, all just integer
http://oddjava.com/?q=node/8

(google search) (amazon search)


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

security


Prevent System.exit() being call - http://jroller.com/page/ethdsy?entry=disabling_system_exit 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.

http://www.javaworld.com[..]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, http://www.onjava.com/lpt/a/6633 , but I personally don't think this is something useful

Some information how using jmxagent: http://weblogs.java.net[..]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: http://java.sys-con.com/read/171487_p.htm

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");
}};

http://www.theserverside.com/blogs/thread.tss?thread_id=37839

(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

http://www.javaspecialists.co.za/archive/newsletter.do?issue=126

(google search) (amazon search)


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

java.util.Calendar


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.


http://discuss.joelonsoftware.com/default.asp?joel.3.328034

(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

http://www.cretesoft.com/archive/newsletter.do?issue=114
http://jroller.com/page/ee?entry=dependency_checking_of_javac
http://jroller.com/page/ee?entry=javac_s_inlining_revisited

(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: http://jroller.com/page/mlconnor/20050708#code_to_find_files_on

(google search) (amazon search)