Java
Using Glassfish Eclipse Bundle for JavaDB, JPA and JSP
Have you ever wondered how quickly one could get from installing a J2EE server to running a JSP page that fetches data from DB using modern persistency technology like JPA? To find out we (me and Ivar) did a little test-drive using recently announced Glassfish Eclipse Bundle that contains Eclipse IDE with bundled Glassfish J2EE [...]
Can you guess the output? junit and initialization
Can you guess the output without running the code? The relation to Eclipse is simply the fact that big part of eclipse.org is a great example of good test coverage built on top of jUnit. Plus, it was literally pulling my hair out in one of the eclipse-related testing-suites. I stepped into this a few [...]
Java Quiz of The Day – same private field instance for two classes
What is the smallest change to main method that makes it sysout “true”? You are allowed to change ONLY the main method! Of course changing sysout line is out of question. You can leave your answer in comments and I’ll publish/approve them together with the solution. [java] public class InstanceDemo { public static void main(String[] [...]
SimpleDateFormat is not thread-safe
How many of you use java.text.SimpleDateFormat as static field? I have seen this to be pretty standard practice (and have done this myself too). Be aware that SimpleDateFormat#format(..) is not thread-safe and thereby for most of the cases you should not use this as a static field in server, Eclipse RPC or any other multi-threaded [...]
Getting unsigned bytes in java
Welcome back after long overwork and vacation period Let’s start small, it’s still almost summer. Bytes in java are always signed and are quite horrible to use because of the casting and weird side-effects (or I’m just stupid enough to call it weird). But we need unsigned bytes quite a lot. Most of the time [...]
Avoid useless Plugin Initialization and/or Class Loading
Here’s a tip for initializing your plugins or any other singleton-like repository only when needed. Consider a code like this: if (isConfigurable()) { Bundle bundleCopy = bundle; Preferences[] preferencesCopy = new Preferences[1]; preferencesCopy[0] = new org.eclipse.core.internal. preferences.legacy.PreferenceForwarder( this, bundleCopy.getSymbolicName()); return preferencesCopy; } return null; Do you see what’s wrong there? The problem is that if [...]
Reason to serialVersionUID your serializable classes
Quoting Eclipse FAQ: “When classes compiled in Eclipse are written to an object stream, you may not be able to read them back in a program that was compiled elsewhere. Many people blame this on the Eclipse compiler, assuming that it is somehow not conforming properly to spec. In fact, this can be a problem [...]
Welcome back, dear word-wrap
At first sorry about those who have been checking for an update of this blog for a month. Regardless of this inactivity there have been quite a lot visitors. I’m glad to see that people like what I’m doing. Thank you! There have been busy days and let’s admit – weather in Estonia has been [...]
Lazy-init variables are not always safe
Have you ever used following to lazy-initialize your variable? If you have then don’t. Just to remind or introduce, it looks OK but it isn’t – this is a pretty serious bug you can easily make. And it’s called Double-Checked Locking. Very good and easy-to-understand explanation is here


RSS
LinkedIn
Facebook