views:

487

answers:

13
+10  Q: 

Java Time Savers

I find the nature of this question to be quite suited for the practical-minded people on Stackoverflow.

I'm setting out on making a rather large-scale project in Java. I'm not going to go into specifics, but it is going to involve data management, parsing of heterogenous formats, and need to have an appealing interface with editor semantics. I'm a undergraduate student and think it would evolve into a good project to show my skill for employment -- heck, ideally it would even be the grounds for a startup.

I write to ask you what shortcuts I might not be thinking about that will help with a complicated project in Java. Of course, I am planning to go at it in Eclipse, and will probably use SWT for the GUI. However, I know that Java has the unfortunately quality of overcomplicating everything, and I don't want to get stuck.

Before you tell me that I want to do it in Python, or the like, I just want to reiterate why I would choose Java:

  1. Lots more experience with algorithms in Java, and there will be quite a bit of those.
  2. Want a huge library of APIs to expand functionality. ANTLR, databases, libraries for dealing with certain formats
  3. Want to run it anywhere with decent performance

Thanks guys. I am open-minded to all technologies (most familiar with Java, perl, sql, a little functional)

EDIT: For the moment, I am giving it to djna (although the low votes). I think all of your answers are definitely helpful in some respect.

I think djna hit better the stuff I need to watch out for as novice programmer, recognizing that I'm not taking shortcuts but rather trying not to mess up. As for the suggestions of large frameworks, esp. J2EE, that is way too much in this situation. I am trying to offer the simplest solution and one in which my API can be extended by someone who is not a J2EE/JDBC expert.

Thanks for bringing up Apache Commons, although I was already aware. Still confused over SWT vs. Swing, but every Swing program I've used has been butt ugly. As I alluded to in the post, I am going to want to focus most on the file interchange and limited DB features that I have to implement myself (but will be cautious -- I am aware of the concurrency and ACID problems).

Still a community wiki to improve.

+6  A: 

Apache Commons has a lot of time saving code that will you most likely need and can reuse.

http://commons.apache.org/

John Wagenleitner
and a lot of other free libraries, see http://stackoverflow.com/questions/130095/most-useful-free-java-libraries
Peter Kofler
+6  A: 

Google-collections:

http://code.google.com/p/google-collections/

Cambium
-1 because a single library hardly helps in a complex project
Peter Kofler
+8  A: 

Learn/use Spring, and create your project so it will run without a Spring config (those things tend to run out of control), while retaining the possibility to configure the parameters of your environment in a later stage. You also get a uniform way to integrate other frameworks like Hibernate, Quartz, ...

And, in my experience, stay away from the GUI builders. It may seem like a good deal, but I like to retain control of my code all the time.

Ben
I guess I am a little weary about something so heavy as Spring. I'm working in a domain that has never heard of SQL or databases and won't have J2EE. In a sense this application would be very limited but simple DB for the unenlightened.In that light, is Spring too much? Or is it still valuable?
Overflown
It has changed the way I program - you can start off with a nice little core and plug in different blocks of code (using dependency injection). Those blocks are configurable (you can override your defaults) - very valuable when you deal with different customers. (design for change!) You could write for example a basic formatter, and extend it with classes you inject into your core program. You don't *have* to use spring everywhere, that's the beauty of it. Also, if you make a basic set of features that you interlink in your code (but is still configurable using spring) it won't be so heavy...
Ben
You could use Guice for dependency injection. its much smaller and easier to control.
01
+6  A: 
  • Joda Time for all date and time manipulations.

  • One of Hibernate or iBATIS to manipulate data in a database

  • Don't forget the IDE: Eclipse, Netbeans or IDEA if you have some cash and like it

Vinko Vrsalovic
IntelliJ is so nice...
Cambium
I love it too. But I've read here different opinions.
Vinko Vrsalovic
+5  A: 

A sensible build and configuration platform will help you along the way, Ant:

http://ant.apache.org/

or Maven (preferably):

http://maven.apache.org/

Especially as the size of the project, and the number of modules in the project increase.

Jon
+4  A: 

There's getting the "project" completed efficiently and there are "short cuts". I suspect the following may fall into the "avoiding wasted effort" category rather be truly short cuts but if any of them get you to then end more quickly then I perhaps they help.

1). Decomposition and separation of concerns. You've already identified high-level chunks (UI, persistence layer, parser etc.). Define the interfaces for the provider classes as soon as possible and have all dependent classes work against those interfaces. Pay a lot of attention to the usability of those interfaces, make them easy to understand - names matter. Even something as simple as the difference between setShutdownFlag(true) and requestShutdown(), the second has explicit meaning and hence I prefer it.

Benefits: Easier maintenance. Even during initial development "maintenance" happens. You will want to change code you've already written. Make it easy to get that right by strong encapsulation.

2). Expect iterative development, to be refining and redesigning. Don't expect to "finish" any one component in isolation before you use it. In other words don't take a purely bottom up approach to developing your componenets. As you use them you find out more information, as you implement them you find out more about what's possible.

So enable development of higher level components especially the UI by mocking and stubbing low level components. Something such as JMock is a short-cut.

3). Test early, test often. Use JUnit (or equivalent). You've got mocks for your low level components so you can test them.

Subjectively, I feel that I write better code when I've got a "test hat" on.

4). Define your error handling strategy up front. Produce good diagnostics when errors are detected.

Benefits: Much easier to get the bugs out.

5). Following on from error handling - use diagostic debugging statements. Sprinkle them liberally throughout your code. Don't use System.out.println(), instead use the debugging facilities of your logging library - use java.util.logging. Interactive debuggers are useful but not the only way of analysing problems.

djna
+1  A: 

Use logging framework (i.e. Log4J) and plan for it. Reliable logging system saves a lot of time during bug fixing.

Endi
+3  A: 

Don't discount Swing for the GUI. There are a lot of good 3rd party Swing libraries available (open source and commercial) depending on your needs e.g.

Mark
I would add this wizard-library: https://wizard.dev.java.net/
Mnementh
A: 

For data persistency, if you're not certain that you must use SQL, you should take a look at alternate data-storage libraries:

  • Prevayler: an in memory database systems, using developing ideas like "crash only components", that make it easy to use and very performatic. May be used even for simple applications where you just need to save some state. It has a BSD License.
  • BerkleyDB Java Edition: a storage system with different layers of abstraction, so one can use it as a basic key-value storage (almost an in-disk hashtable) to a fully transactional ACID system. Take a look at it's licensing information because even some commercial software may use it for free.

Be aware that they have trade-offs when compared with each other or with a standard SQL database! And, of course, there may be other similar options around, but these are the ones I know and like. :)

PS: I was not allowed to post the respective links because I'm a new user. Just google for them; first hits are the right ones.

Chuim
A: 

You can save time between restarts by using JavaRebel (commercial). Briefly, this tool allows you to write your code in Eclipse and have the code changes picked up instantly.

Robert Munteanu
+1  A: 

For me big time-savers are:

  • use version-control (Subversion/Git)
  • use automatic builds (Ant/Make/Maven)
  • use Continuous-integration (Hudson/CruiseControl)
  • the apache-commons-libraries are very useful
Mnementh
+1  A: 

Test Driven Development

Figure out the functionality you want and write tests to demonstrate the functionality. Then write just enough code to pass the tests. This will have some great side effects:

  1. By writing just enough code to satisfy your requirements you will not be tempted to overbuild, which should reduce complexity and make your code cleaner.
  2. Having tests will allow you to "refactor with confidence" and make changes to the code knowing you're not breaking another part of the system.
  3. You're building quality in. Not only will you have assurance that you code "works, but if you really want to use this code as a sort of "resume" for potential employers, this will show them that you place a lot of value on code quality. This alone will set you apart from the majority of the developers out there.

Aside from that, I would agree that other big time savers are Spring, having an automated build (Maven), and using some form of source control.

Vinnie
A: 

Wonder why nobody suggest the ORM tool for the database.

My list will be:

  • Hibernate
  • Spring Framework (or another IoC-container)
  • The Paper Prototyping
  • Various libraries specific for your domain (java has a lot of them, so keep in mind the general practise to code reuse)
iobit