0

A java app I have been writing for the last few years has now become quite bloated and I am conscious of including unused code etc… I know for css and javascript you perform code cleanups and compact the code etc.. does anything like this exist for java?

1
  • As a programmer you should always be aware of minimizing code and reusing your code so you dont have to repeat yourself. Java allows a programmer to reuse methods and classes, so there should be little repetition if you plan out how your app will work Commented Apr 14, 2011 at 16:49

4 Answers 4

3

For some reason developers always dismiss the importance of the java garbage collector.

This should help: http://www.devdaily.com/java/edu/pj/pj010008

Linda

Sign up to request clarification or add additional context in comments.

2 Comments

i'll give it a whirl, I totally forgot about the garbage collector
@KBertelsen, try running with -verbosegc to see when you have GC delays and how long they are.
2

The fact that you are quoting css as an example for an language that enables code cleanup, tells me that you are probably new to java.

Java has one of the Richest set of tools for performing code cleanup (or general re-factoring). There are two ways to perform code cleanups. One is to use Static code analyzer and other way is to have an instrumentation support to monitor your running programs.

There are many static code analyzer in the market and the some of the best ones are open source. If you are a serious Java developer then you cannot get a better IDE than Intellij ( no, I do not get paid by them..). They have one of the best code analyzer tools integrated with an IDE. This link should help you.

You do not have to use Intellij to get the same kind of code Analysis. You can use PMD and FindBugs plugins for any leading IDE. Among all the code analyzers, I believe these two are the best to dig out deep problems in the code and not just superficial mistakes. ( like formatting Issue).

These tools will help you clean up dead codes, find probably bugs and unclosed objects. You should also customize the tools based on your requirements, but that comes later.

Once you have identified and fixed all the problems identified by your static analyzer, then you need to monitor your program for potential problems like Memory Leak. Some problems are only found during runtime.Java had an inbuild instrumentation mechanism called JMX and almost all major Server Vendors have exposed it. You could also use Jconsole, that could act as an abstraction layer over JMX.

Comments

0

Have you considered using any code coverage tools to determine exactly what portions of your code are getting executed? Take a look at EMMA:

http://emma.sourceforge.net/

Comments

0

Optimizing and cleaning up are two separate issues. You can start on both using Eclipse.

Take a look at these sections of your Eclipse configuration:

Window > Preferences > Java > Code Style > Clean up / Code Templates / Formatter

And:

Window > preferences > Java > Compiler > Errors/Warnings

You'll find a lot of handy features for flagging and even automatically fixing things that are commonly considered to be bad code.

For performance optimization, you might try the Eclipse Test & Performance Tools Platform Project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.