views:

212

answers:

12

I am browsing some of the Java software packages (Guice, GWT, JAX-RS, etc.) and my head is spinning quite a bit because I don't really know the use cases when these particular software packages shine. The tutorials seem to show you how to do something with their package, but not why you would want to use their package (or in which cases you would not).

So I'm wondering if people could post some use cases (or "don't use cases") for Java libraries for which this may not be obvious, to complement the canonical what-are-good-free-Java-libraries question. I have a particular interest regarding Guice but it's kind of a more general question.

edit: if you are aware of a really good webpage that answers this question for a particular package (e.g. explains use cases for Hibernate or JAXB or whatever), please link to it.

+1  A: 

If you want to persist stuff in a database, use some kind of persistence framework rather than handcrafted SQL on naked JDBC; you'll avoid loads of hassle.

Hibernate is a popular choice, but anything implementing JPA will do.

sleske
A: 

First define your problem and then go searching for a solution via FOSS if that helps. There are just too many libraries out there and it would not be practical to go crazy and list lots of them.

mP
+1  A: 

Build Systems

Ant is a Java build system, whereby you can build deploy and run your Java application (and a whole lot more besides) via a configuration file which you define in XML.

Maven is another build system which exists because it tries to solve the problem of projects with multiple dependencies and inter-dependencies (which can get ugly using only ant).

oxbow_lakes
+1  A: 

GlazedLists: a GUI adapter framework for viewing/editing/navigating/filtering/sorting/binding lists of objects with a JTable or JTree. (e.g. if you have a list of MP3 objects with various fields like Artist, Title, Album, Genre, etc. it makes it very easy to map the fields of the MP3 object to the columns of a JTable, formatted the way you want, without having to write much code.)

Good for small-to-moderately-large lists of objects stored in memory: you have to use GlazedLists' BasicEventList and other associated classes as the collection implementations, rather than your own arbitrary List<>, unless you want to implement all of the methods of the EventList interface... so this makes it hard to encapsulate preexisting storage mechanisms (like a database, for instance). I've used it on List<>s of items in the 5000- to 50000-count range and it is fairly fast.

Jason S
+3  A: 

Application Configuration

Guice is a library which aids in application configuration. That is; your application will be written as a bunch of interacting classes which communicate with one another via interfaces they export (which is good programming practice as it aids in testing and maintenance). Guice helps you wire and configure these classes together to make a real, running configuration.

Spring also solves the same problem but started from an XML perspective whereas guice is annotation-driven. Spring is so much more than this, however, and contains much that makes integration of Open Source software simple. It is well worth exploring.

There are other solutions in this space, however, like PicoContainer and NanoContainer (which caught on much less, probably due to their lack of documentation)

oxbow_lakes
is there a case when you would not want to use dependency injection or application configuration or whatever? e.g. if I have 25 concrete public classes, does that mean I should also have 25 interfaces?
Jason S
In general it's a good idea to understand what classes within your application are providing *services* to other classes (e.g. PersistenceService, AnalyticsService, AlertService) and then extract interfaces from these. Your data classes don't necessarily have to be interfaces but I've found that it's a good idea for this also. It gives you much more flexibility later on. Also, with interfaces you can always resort to the java Proxy framework to hack around in an emergency!
oxbow_lakes
Although I've known people to passionately disagree with me about making data classes interfaces. They were wrong, of course ;-p
oxbow_lakes
+1  A: 

Web Development

GWT is a google toolkit which allows you to write Java user interface code (albeit a restricted subset) which GWT then compiles into javascript so that it is viewable via a web-browser. This makes it easy (ish) to develop rich internet applications (RIAs).

oxbow_lakes
+2  A: 

Apache Commons

There's a ton of stuff from Apache but most obvious are the commons libraries, which contain some (mostly useless) collections, the Digester which makes it easier to integrate custom XML config into your application, the net networking toolkit (for FTP and things like that).

oxbow_lakes
A: 

JGoodies Forms: Provides a powerful layout manager for Swing (FormLayout) that remains easy to understand.

Swing provides a number of layout managers with the JDK but creating complex layouts can be difficult. Either you end up using a really large number of JPanels each with different layout managers or you spend hours trying to understand GridBagLayout. FormLayout provides a simple way to create complex layouts by using a simple language to describe the layout. This language makes it easy to mock up you forms on paper and then convert it to code.

Mark
A: 

Workflow Software

OSWorkflow is an open-source project for the definition of bespoke workflows (via XML). These workflows can be persistent and hook into your Java code

oxbow_lakes
+1  A: 

Scheduling Software

Quartz is an open source scheduling library which allows you to do complex cron-like (or even bespoke) scheduling of jobs, persist job state etc

oxbow_lakes
+1  A: 

JUnit, TestNG and EasyMock for testing (there are many others, those are the ones we use).

JUnit allows you to easily create methods that run as part of a test, EasyMock allows you to create "Mock" (or fake) objects to pass in that will respond in very specific ways which you can use to test a method that relies on a framework or running environment that isn't there during testing.

Bill K
A: 

List of good numerical Java libraries:

http://commons.apache.org/math/

http://dsd.lbl.gov/~hoschek/colt/

http://gams.nist.gov/javanumerics/jama/

Useful for numerics, obviously :)

quant_dev
please elaborate: when would you use one over the other?
Jason S
Colt and Apache Commons Math are largely complementary. JAMA has a subset of Colt's features, but you may like it's interface or license better.
quant_dev