I have a Java project that I've been working on for a while. The design started out pretty good but slowly degraded as changes were made. I'm looking for some sort of tool that will analyze the project. It'd be really nice to have a map of the dependencies of different classes/methods. I feel like certain methods are only in there to fulfill a very specific goal. I'd like to eliminate unnecessary code and make my design better.
Any suggestions would be great! Thanks!
This is not a perfect answer, but it may be helpful for quick checks. If you are using Eclipse for your development, you can view the call graph for a method by selecting its name and pressing Ctrl-Alt-H (or right-click and select "Open Call Hierarchy"). You can use the view that opens to see what calls the method, and what methods are called by the method.
You may also want to try FindBugs. Helps a lot with these and many other issues.
You may want to check out JDepend. It was specifically developed to solve the problem you are facing.
Working as a consultant it is very common for me to be thrown in to a huge legacy code base. Typically the first thing I do is run JDepend on it to try to get my bearing on the code base and all of the dependencies.
Good luck.
There are several good analyzers for Java. I have been playing around with PMD so far and have had decent luck with it.
Many tools are available for this, depending on the size of your system. The grandaddy of them all is Structure101, a commercial product.
http://structure101.com
I've used this on some big projects - it's complex but easily the most comprehensive of all the tools I know. It can graph a huge architecture, and lets you untangle some complex stuff. It has a sister product called reStructure101 where you can do what-if scenarios.
A nice competitor is Stan4j. It's nowhere near as complete, but does some stuff better, particularly showing the dependency context at the class level.
http://www.stan4j.com
(I own both products, but have no commercial affiliation with either)
Another way of viewing complex dependencies, particularly at the project level, is a Dependency Structure Matrix (DSM). Although S101 can do a DSM, Lattix has more support - it can handle Spring and Hibernate dependencies:
http://lattix.com/
(I've not used lattix - they make it too hard to evaluate it, which is bizarre because I work on some very big systems)
If your software is fairly small, and you are more interested in the simple class level, then something like Architexa may help you understand the structure better:
http://www.architexa.com/
Finally, if you want to roll your own, you can easily do this with ASM. It even includes a dependency matrix tool which tracks at the package level:
http://asm.ow2.org/doc/tutorial-asm-2.0.html (see down the page for the nify dependency matrix)
Here's the source for it - it's very simple, but clever. It works off bytecodes. http://cvs.forge.objectweb.org/cgi-bin/viewcvs.cgi/asm/asm/examples/dependencies/src/org/objectweb/asm/depend/
Doxygen can help, especially with graphical representations of the dependencies between classes and methods.