I am looking for a free Java code analysis/metrics tool that I can use to see class dependencies, method execution times, etc, and possibly to print out a diagram that shows them. I am currently using a jdepend task in ANT to achieve this, but I'm thinking there must be a better tool for that sort of thing. I would also prefer if it was integrated with Netbeans, since I'd rather not port all my projects to Eclipse for the task of analyzing. I have tried to play with the community version of Visual Paradigm, but I got sick of it really fast when it didn't offer code synchronization in the community edition. Although I can give it another shot if that is indeed the way to go. I also tried BOUML, but it seems to be more of a UML design tool than an existing code analyzer. So, my question is, what do you guys use for Java code analysis? Thanks!
EDIT: For instance, JDepend measures a few metrics and can draw a nice little dependency graph, but it doesn't exactly have a UI or anything. I guess I'm looking for a tool that can draw out all my classes and their dependencies on each other (jdepend only does packages AFAIK) as well as the methods that are called between the classes and provides a metric number of "how good the code structure is". I apologize if the question is vague, I'm just looking for a variety of options and I don't exactly have a lot of experience with code metrics tools...
As #Victor has mentioned Sonar is a very good tool for static code analysis. It produces graphs, charts, and generally allows you to slice and dice your Java code analysis in multiple ways.
However, it does run as a server, which can require privileges on your machine/network that you might not have. I use it myself, and I recommend it, but it's not always practical. So let's take a look at some of the tools that it uses underneath the hood.
First, there's FindBugs. As the name implies, it helps you find bugs in your Java source code.
Next, there's PMD. It helps find bugs in different ways from FindBugs.
Third, there's CheckStyle. It helps ensure that your code conforms to certain style guidelines.
Finally, there's Cobertura, which instruments your Java bytecodes and analyzes which source code lines are exercised by your unit tests (you do have unit tests, right?)
This is not an exhaustive list of the tools that Sonar employs, but it covers what seem to be the highlights. Inside Sonar, these are all 100% configurable. Outside Sonar, they're still configurable, but you better like XML.
Sonar. Though, personally I've never used it, so I can't answer questions about details. However, I know that our conitnuos building tool is integrated with it to make pretty pictures :)
Are there resources on going about trying to understand a large java code base. Like for example, a graph persistence implementation. If there is minimal / missing documentation, what kinds of approaches do you take ? Are there any books that deal with this ? I know one called Brownfield App Development in .NET.
Perhaps something similar ?
There are number of ways to tackle such a problem and most of the times it will be your personal preference and style of coding and solving problems... for ex:
Start with any documentation/TDD if available.
Use some design/UML tool like EA Architect to generate the UML/Class diagram to understand the class structure.
If the project has some test cases, start by executing and understanding the code behind it.
Try running the application and you can set some debug points and try understanding the flow.
End of the day it all depends on the project, how well the code is documented and your personal style of solving problems.
My suggestions would be:
Get the code building. If there is no build script, write one.
Get the code running.
If there are no tests, start picking off bits of the system to write tests for. You're not really testing, you're learning about the system's behaviour.
Use a modern IDE (Eclipse, Netbeans, etc.) to start tracing the declarations and references to methods and classes.
Good luck!
Ian.
It all depends on how the project is organized. Some ideas off the top of my head:
Look for the core / domain knowledge:
See if domain knowledge is isolated and start from understanding it.
See how the code is split into projects, modules (e.g. jars) and packages. If there is at least some organization, look for the "core" and start learning from there.
Look for other traces of this knowledge: diagrams, tests, documents, samples.
Try running the application. Analyze what happens from the entry points down.
Learn the basic architecture. Look for the familiar ground (frameworks and solutions you know) and see how it is used.
If you want to trace the execution of your Java code to get a feel for the flow of control you can use a tool called InTrace.
NOTE: InTrace is a free and open source tool which I have written.
Other than learning java, spring, hibernate, servlets, jsp's, how to use eclipse/netbeans, databases like mysql/oracle/postgresql, JMS, JUnit, etc.
What other skills are essential?
Coming from a MS background, and I am just a little overwhelmed by all the things going on in the java world! (btw, you guys have TONS of dlls also, a big eye-opener for me in my java pursuits)
Other things I can come up with so far are solid linux skills, maybe how to use a mac.
Other than that, there are so many of these tools that I see referenced, which so far I am pretty much clueless how to use:
ant
maven
what else is there that are common or important to know?
Debugging techniques
XML technologies (SAX, DOM, XPath)
How to find libraries that do what you're attempting to accomplish, rather than writing them yourself.
The number #1 tip for you:
How to research.
Debugging techniques
How to learn a new API/framework
Java concurrency API
The standard tools (JConsole, jmap, VisualVM, etc.)
Profiling techniques
GC tunning
The Java memory model.
As well written/well thought Java code to read and learn from I would suggest Google-collections (or Guava) and maybe Functional Java and Guice.
It depends. When you are experienced with the foundations (automated testing, design, know how to 'learn' generally, modeling, working well with other programmers, etc.) you are lucky :) Technologies change often but you can adapt extremely quickly if you have the much less changing concepts in your head and fingers.
Still the frameworks + techs are different. So get used to new tools (Java has different tool-set and IDEs as MS-tools), this also includes build-envs like maven or ant. For getting used with new tools find a little private project (with small scope). And then step by step puzzle together + solve your technology todo-list.
Parallel to that download a little open-source project based on Java and see how they did the stuff. And read a lot of code done by others!
how about documentation - javadoc
My question is broader than merely expanding language specific skills. I'm wondering what sort of advice anyone might offer to someone with a desire for knowledge, but a lack of direction. Feel free to skip down to the question.
Background: I've taken a single computer science course in java at my University, but i'm planning on majoring in Computer Science and Electrical Computer Engineering (ECE). My java class was quite rudimentary. We were provided with a framework and merely edited/created a few methods and classes to perform a simple task. We made a version of Breakout, and created an AI for a simple connect-four game. Although I'm somewhat familiar with big O notation, I haven't actually studied it in class (My next CS class covers this). In my introductory ECE course we also programmed BOE-Bots in PBASIC to compete in an obstacle course of sorts. As an engineering student, I was also introduced to matlab, although I've only used it for linear algebra homework. In summary, I don't have much programming background, but I've loved pretty much everything I've done so far, and I'm looking for ways to build a more valuable skill set.
Steps Taken: After paying more attention to the programming section of reddit, I found a link to Project Euler. This summer I've been hacking away at those problems (finished my 42nd solution yesterday), but I'm looking for some more direction. I've been reading blog entries and SO heavily. I'd like to learn something about php, and perhaps create a dynamic webpage, but fundamentally I want to do anything in my power do to improve myself and prepare for the working world.
Question: What would direction would you recommend for me? Should I learn a new language? Keep attacking Project Euler? Read some books on programming? Start a coding project(I wouldn't even know where to begin)? Wait until school? Learn about more fundamental programming principles?
I guess with all the paths available, I'm just a little overwhelmed, and I don't want to fall into a path that might be detrimental to my career opportunities. I'm also really bad at making decisions. Your advice would be greatly appreciated!
The word quickly worries me... I suggest you read Teach Yourself Programming in Ten Years - Why is everyone in such a rush?
~~ Peter Norvig
Forgive yourself if you're not setting the world on fire three weeks after sitting down at the keyboard... maybe you're destined to be a late bloomer?
;-)
Most everyone is suggesting doing more programming. Whilst that's obviously important, I think it's important to understand the environments that your programs work in.
I would investigate how operating system work (how they allocate resources for you, how they schedule programs and threads), how networks work (routing, TCP/UDP behaviours and limitations etc.), and some database theory.
I see a lot of junior programmers with great language knowledge, but beyond the sandbox of their program they don't have a clue how the computer/network enables their stuff to run.
Knowing something of the above will make you a better programmer in terms of how you write your programs, and how you understand how they'll work (and indeed, how to debug them or analyse their failures)
There is only one thing that can improve your skills as a programmer: Program.
Reading books about programming is akin to reading books about cycling. It's not going to turn you into a cyclist.
Program something that you'll use and have a vested interest in. Then just put your head down and do it - reading any supporting information as you go.
Programming skills are just a small part of what makes a successful programmer, IMHO. Being able to read specifications, ask questions and interact with other people to extract the information you need to program are very important too. Pay attention to your 'soft' skills, they will help you a lot in being a successful programmer in a commercial setting.
I'd reccomend you take a multi-pronged approach. Reading books can only take you so far, since they don't provide you with practical experience in developing an application from scratch. Programming is much more now about writing code; you have to be able to design applications, read documentation, and know how to solve the needs of a customer who doesn't know how to tell you what to write.
If you're still in college, try to find an internship with a development firm. You'll get access to people and resources who already have this experience. If you for some reason can't do an internship, find and make a friend who is a developer. The impact of having someone who knows what they're doing to bounce ideas off of is immeasurable.
In addition to surrounding yourself with people with knowledge, you should also take on writing an application all your own. Pick something that interests you, but at the same time try not to make it too complicated, you don't want to frustrate yourself by writing a boring application, or choosing something that has too steep of a learning curve. Remember that the application is at it's core, a tool to assist you in learning, so it's OK if it turns out to be less complex then you imagined, or if the code you're practicing doesn't apply within the scope of what you're trying to write.
You definitely need to write code in order to become a better programmer. If you don't have a particular idea for a program to write, pick an open-source program (ideally one that you use), contact them and find out what they need done; contribute something. Fix a bug, implement a feature... start small and work your way up. This will help you learn about working on a team, writing maintainable code, preventing problems, and working on useful tasks. Much of what people write while learning to program is just exercise code, and not actually useful or representative of anything realistic. That is why a real, useful program is the best thing to do.
I saw an interesting link for a site called CodeKata that might help you. The important thing to get your skills going quickly is to actually code for practical problems that you will be likely to encounter in any real job.
Besides picking an interesting project and implementing it from scratch, reading others' code can also be valuable in improving your skills. Scott Hanselman has a good series on reading code: Weekly Source Code
Since you already know the fundamentals of programming, and obviously have the desire to learn I would start a pet project.
Nothing has forced me to learn great deals about a technology, language or idea more than having a fairly challenging pet project to throw my self into.
I would recommend, like rein mentioned, picking a project you really have a true interest in. Other wise it will get boring pretty fast and you'll have no idea why you are working on it. I think it would be wise to make the project fairly non-trivial. I always found the less trivial a project I was working on, the more I learned and took away from it.
Also If you live near a college/university research labs on campus are pretty much always looking for summer interns to work on code in one shape or form. Some will even pay you. I did this for 4-5 years through high school and some university and it was a great learning experience.
Obviously participating in an open source project is a great way to gain experience at working with other developers. Check out stuff on github, sourceforge, bitbucket.
I'd only caution you to ask for help and bother the core developers of a project you are very interested in and you are going to stick with. Generally open source developers dedicated to there project are few and far between. Their time is really valuable to the community and to waste it on someone who is just going to fly by night and never be seen again is kind of a shame.
It sounds like you are writing programs happily, and are a decent java programmer. So writing more might not be your most productive way of learning new things.
As a result, I'd say learn a new language - knowing more than 1 always exposes you to new concepts. As a java programmer I'd suggest C/C++ as they've immensely popular but they fill areas that the 'managed high level' languages don't go, the low-level high-performance, to-the-metal applications. If you learn C# (for example) you'll find you're just doing a different dialect of java (roughly) and you won't learn too much.
If you don't like the idea of C/C++, get into a scripting language instead - bash, VBScript/WMI, or perl or python. they'll be sufficiently different to teach you some good stuff.
Or do both!
You already know how to program; in order to prepare yourself for a real life job, the most important thing is probably not how to program better, but to learn the things you'll have to do that aren't programming.
In your workplace, you most likely won't be asked to write line "fire and forget" programs, but work in a team on large applications. In order to do that effectively, you need to learn:
How to communicate effectively with analysts, customers, managers and your fellow programmers
How to plan and coordinate work: using source control systems and bug tracking systems, working with written specifications, following a development process - "software engineering"
Perhaps most importantly: get used to working with other people's code - third party libraries, frameworks, and of course colleagues' code.
This, too, can most effectively be learned through hands-on experience in a real project. For me, the big eye-opener was working in a group of about 10 students in an experimental project organized by university with some industry support. Perhaps you can find or organize something similar at your university? If it has a chair dealing with software engineering, they should be happy to do something like that if they aren't already. Failing that, joining an open source project is good too.
Write programs to automate things that you do manually on a daily basis.
Like, todo lists, keeping accounts, checking RSS feeds.. the list could be endless. If you do some business on the side, write some simple code to assist you in that.
The essence is: to improve your programming, do programing! :D
Contributing to open source projects has a surprisingly high impact on your ability to develop software, as opposed to the ability of writing code:
you get to work on code written by others, which is sometimes brilliant and sometimes abysmal;
collaborate within a geographically distributed team;
get introduced to team politics ( yay! );
understand what it means to have actual users.
to quote just a few. Some good places to look:
Codehaus
Sourceforge
Google code
Find out about best practices (for example training videos on windowsclient.net). Get any problem and solve it using database as input and database as output. Start over several times. That's as close as you can get to the real world scenario. Read books recommended by Joel.
Here's my multi-prong suggestion:
1) Big picture work - Look at various Software Development methodologies and see how when you program you follow one of these approaches. You did some Java work, was that web, windows application, console application, or something else? Learning a little about the other types may also prove useful
2) Medium picture work - Have you looked at Refactoring and Design Patterns? These can be very useful but may require a bit more coding experience to see how they can be useful.
3) Small picture work - Study various algorithms and understand various trade offs one can make in choosing various implementations of a data structure, e.g. linked lists vs. arrays. There is a big white book about Algorithms that some use when studying them.
My multi-advise:
Keep training, and write code. Participate in small open source project.
Read standard book (here is the Jeff's list)
Learn from your mistakes, or better from the mistakes of others by reading site like www.badprogramming.com
From 99 ways to become a better developer:
Program! and try to diversify your work as much as possible
Find a mentor
Be a mentor
Learn about the different aspect of software development other than code (business of software etc.)