Posts

Showing posts from December, 2009

Eclipse project explorer label decorations - Type Icons

There is a simple way to see decorations for Interfaces, Abstract Classes, Enums, etc in the Project Explorer. Goto Window : Preferences Search for decorations Click on General : Appearance : Label Decorations Check Java Type Indicator on and apply You will now see the decorations in the Project Explorer

Is the API RESTful

REST APIs must be hypertext-driven RESTful URI design

Eclipse JBoss/WebLogic debugging and hotswap

How to configure Eclipse debugging and hotswap for JBoss and WebLogic Excerpt: Lastly, tell Eclipse not to erase other files in the output folder every time it builds the project. While still in Preferences navigate to Java | Compiler | Building and uncheck Scrub output folders when cleaning projects. That's it. Now every time you save a Java file, Eclipse will recompile it and JBoss will reload it. WebLogic hot swap

Terracotta vs. Hibernate

After a side-by-side implementation comparison, where ACID Transactions and persistence were not strictly required, utilizing Terracotta required ~1/4 the LOC implementation of a Hibernate implementation. Terracotta required ~5 implementaion files vs. ~14 implementation files for Hibernate - several were related to DDL. Hibernate required DDL, mapping files or annotations, DAOs, dbUnit test data, and integration tests. Terracotta required POJOs and plain unit tests instead of the integration tests necessary for Hibernate. To avoid surprises, it is generally good practice to thoroughly test all Hibernate mappings and test against the target database. Also significant, is the fact that the Terracotta implementation doesn't unnecessarily tax the least scalable component of the system; the database.

Remote windows shutdown/restart

c:> shutdown -? c:> shutdown -r -f -m \\<Computer> -t 1 -c "some message" Restart in 1 second forcing applications to close

Windows Tools

Cygwin howto OpenSSH and X VNC is almost always the wrong solution for connecting to a Linux box. $ ssh -X -C -c blowfish username@linuxbox gnome-panel cygwin sshd install cygwin ssh install RKTools - alternative to cygwin TCPView - Sysinternals Windows Telnet server Telnet client - Java Applet The Java Telnet Application

Favor composition over inheritance

I have take Josh Bloch’s recommendations to heart: • Item 15 minimize mutability • Item 16 favor composition over inheritance • Close/limit the API as much as possible and open/expose it only as necessary • Design for inheritance and document it or disallow it I have created very few class inheritance hierarchies over the years – except when I was heavily doing swing/UI work. I used to create lots of abstract classes for common behavior; however, I have since switched to creating interface inheritance hierarchies and utilizing composition. While it is slightly more work except for testing, I can’t recall any particular situation where composition hasn’t worked. However, there are certainly situations where a class inheritance hierarchy is more ideal and I would still favor it over composition. I have specifically found composition to be excellent for TDD. I can test the parent class fully. Later when I compose, I use a mock and just test the pass-through methods and the new behavior...

Exception best practices

Favor RuntimeExceptions over checked exceptions – follow Hibernate’s example. This allows clients to choose what to do. Always declare throws on methods even for runtime exceptions - for clarity, not necessary in tests Always include @throws in the JavaDoc for each exception and state under what circumstances it throws the exceptions Always include the details (state) related to the cause of the exception in the message - this will help others debug the issue (it isn’t really for us the developers, it’s for the poor guys/gals on the front line who have to debug our broken s$*t) – utilize String.format and include what was being processed and all state that might be helpful in understanding the issue – beware of possible NPEs in String.format arg method calls. And yes this takes time and requires thought on how to clearly convey the information; however it is incredibly useful, sometimes even for us developers. Always remember to wrap any source exceptions in your own exception processi...

Avoid method chaining

When to use it Just don't!

Use final modifer liberally

The Final Word on the Final Modifier Using final: • Prevents bugs • Ensures thread-safety • Ensures security • Generally improves performance • Enforces better design/implementation - favoring composition over inheritance Final modifier