Slashdot Mirror


What are Some Essential Java Libraries?

rleclerc writes "I would like to ask those 'Javaniers' in the Slashdot community what they thought were essential non-standard libraries that every Java coder should have. Normally I roll my own when it comes to that type of thing and simply build on whats available in the foundation classes. However, recent work has pushed me toward looking at some scientific libraries and I thought I would find out what libraries others in the Java community would consider an essential weapon in their Java arsenal. A few that I am looking at are the Cern scientific libraries and the Apache Commons Collections libraries. To avoid extra libraries I have opted to use the Java logging rather than the Apache one. Anyone like to add anything to the list?"

25 of 77 comments (clear)

  1. Libraries by thatjavaguy · · Score: 2

    For server based applications JMX is a must.
    Don't write off log4j.

    Spring is very good indeed.

  2. List (and reasons) by sameb · · Score: 4, Informative

    In no particular order...

    Commons Logging. Yeah, you said you wanted to avoid extra libraries, but the overhead of commons logging is so incredibly small, and the extra libraries you'll want to otherwise use are going to require it anyway. It's a measly 28KB last I checked, and well worth it.

    HttpClient If you want to do any form of HTTP transfers, avoid HttpUrlConnection (built in to Java) at all costs. The HttpUrlConnection code is broken in many ways (too many to list), so you'll need another library. HttpClient does a good job of hiding the HTTP transfer behind the scenes, and has easy ways of letting you extend/change what you need.

    JGoodies Looks Swing is getting better every day, but for that extra polish, you'll want to use the JGoodies Looks library. It does a great job of making Metal look just that much better, and also helps out the Windows L&F in some places.

    Xerces I'm not sure if the bulk of this is included in the latter versions of Java, but Xerces is definitely a must-have for any XML parsing.

    Other goodies...

    For rendevous (multicast DNS) support, use jmDNS. It just works.

    If you need i18n handling (normalization, etc..), IBM's icu4j does a great job.

    1. Re:List (and reasons) by sameb · · Score: 2, Insightful

      It's a tough question. Many of the built-in Java classes work wonders, and by building them in, it lets other built-in classes make use of them instead of having to build their own versions. One example is the Collections API. Sure, there could be things added/removed/changed with the API and things like ArrayList, LinkedList, HashMap, TreeSet, etc... but by including them, other necessary stuff can be simpler because they don't have to worry about a simple list or queue.

      The remaining object-oriented problem with most OO languages is that object construction is not easily object-oriented. Java's gotten around this by using service providers (for things like crypto and other places), but most SPI interfaces are bulky and difficult to use. Unless all classes use the SPI for object creation, the largest benefit is lost. A way of having 'new ArrayList()' return my ArrayList instead of Java's ArrayList would allow pre-existing classes to make use of later optimizations in different libraries.

      What I've found with many of the Java classes is that they're good for the designed scenario. HttpUrlConnection, for example, breaks if the server accepts the connection and disco's without sending any data (the connection just hangs in this instance) -- but in the vast majority of Java apps, this is never going to happen. Any robust implementation, though, needs to handle this scenario. Things like StringTokenizer are also great for simple & quick manipulation of string tokens, but are terribly inefficient.

      IMHO, Java's done an excellent job of providing an API that gets the job done 90% of the time. For that other 10%, you need external libraries.

  3. My top 5 by jacoberrol · · Score: 4, Informative
    These are my top 5
    • Logging - log4j (I agree with the previous poster. Don't write log4j off)
    • Unit Test - junit
    • Xml Serialization - xstream (very light-weight and easy to use object->xml serialization )
    • Data access - iBATIS (a beautifully simple data access layer)
    • App framework - Spring (not just for the web controller... the IoC and AOP stuff is quite nice.)
  4. JDOM.org by zhenga · · Score: 2

    JDOM for processing and manipulating XML, real easy to use.

    1. Re:JDOM.org by chazman00 · · Score: 2, Interesting

      XOM is even easier.

  5. My last couple... by (H)elix1 · · Score: 3, Insightful

    The last several projects have included jakarta-regexp-1.3.jar. Yes, if you are lucky enough to be able to count on using JDK 1.4 you have another option. One jar and you are golden for regular expressions.

    The other is import org.apache.xpath.XPathAPI; My god is it nice to be able to say

    NodeList nl = XPathAPI.selectNodeList(doc, "config/adapter/config/property[@name='foo']");

    than the normal horking about with SAX or DOM parsers.

  6. A few I use a lot by eyeball · · Score: 2, Informative
    --

    _______
    2B1ASK1
  7. Before any project... by Pengo · · Score: 2, Interesting


    First, make a plan of what your trying to do.. then go browse apache Commons.

    There have been many times I got through a project, or part way into it.. and realized I could of saved a TON of time by using a tool from that resource.

    If your doing anything with XML, it's worth taking a look at JDom.

    Make sure your using Eclipse, and if your doing web based projects.. I highly recomend http://myeclipseide.com. I have been a subscribe for a while, and have really enjoyed the enhancements that their modules bring for web development.

    1. Re:Before any project... by Earlybird · · Score: 3, Informative
      • Unfortunately, the project never gained critical mass, so it was deemed best to close it (in August, 2004).

      Wrong Commons. It's called Jakarta Commons and is alive and, despite a certain tendency to include crappy, hastily-thought-out and sloppily-designed implementations, generally considered well.

    2. Re:Before any project... by zorkmid · · Score: 2, Informative

      Maybe he meant Jakarta Commons.

      http://jakarta.apache.org/commons/index.html

  8. cglib and more by Earlybird · · Score: 3, Interesting
    cglib, a library that lets you do metaclass programming efficiently in Java; it's similar to java.lang.reflect.Proxy, but more flexible and compiled to bytecode. Cglib is commonly used to create decorators -- for example, Hibernate uses it to generate proxies, to transparently track whether persistent objects have changed in memory and must be re-saved to the database -- but there are other uses, such as mimicking the mixin pattern.

    Xalan for XSLT and XPath processing. Here's a tip: Never, ever use SAX for XML parsing of application-specific data structures. SAX is a nice low-level interface for building upon, but unless you're programmatically emitting a document from scratch, it's painful to use -- you always end up writing a stack-based content handler to keep nesting state. XPath makes parsing a breeze.

    JGroups (formerly JavaGroups) is a protocol stack for building reliable, fairly efficient network communications based on, among other things, multicast IP. The entire stack is user-defineable, so you can pick and choose the level of reliability and which features you want (TCP support, pinging, group membership management etc.).

    Lucene is a text-indexing engine. It's actually pretty crap, and does not scale very far (we're talking a few seconds for result sets of only a few thousand documents), and the code is pure spaghetti (abstract base classes! Inheritance!), but if you need a little indexing engine or some decent text tokenization classes, and your performance requirements are modest, it works well enough.

    SableCC is a good BNF-based parser generator that generates type-safe parse trees that can navigated at runtime. Unlike the more well-known JavaCC, it's easy to get started, not least because the BNF-like grammar is so simple.

    1. Re:cglib and more by DreamTheater · · Score: 3, Informative

      What's wrong with abstract base classes and inheritance? These are fundamental concepts of OO. Spaghetti code can be written in any language, regardless of these features.

  9. Usefull libraries by Anonymous Coward · · Score: 3, Informative
    We've found that the below libraries usually suit most applications:
    • log4j - Killer logging tool
    • ant - Killer build tool
    • junit - Killer unit test tool
    • xerces - XML parser
  10. Yajul by utahjazz · · Score: 2, Informative

    Yajul has all the the little things you normally have to write and test yourself.

    It has lots of obvious classes that you'd almost expect in the JDK like TeeOutputStream, ByteCountingOutputStream, Cache, and StringUtil.

  11. My Favorites by 2starr · · Score: 4, Informative
    GlazedLists - UI List/Table Manipulation

    Doug Lea's Concurrency Utilities - If you haven't yet made the plunge to Java 5.0, this is indispensable for anything thread related.

    Trove4J - High performance collections that work with primitives. We do wire-speed packet capture and flow analysis with this stuff. 'nuf said.

    --

    "Let your heart soar as high as it will. Refuse to be average." - A. W. Tozer

  12. My most favourite by Lao-Tzu · · Score: 3, Interesting

    I'm currently building a variety of petroleum engineering tools in Java. Here are the libraries I've found most useful:

    JFreeChart - for all your plotting needs. Robust, quick, and fairly bug free. Not perfect, but hackable.

    iText - a free Java PDF library. My preferred method for creating reports, especially since a lot of my output needs to be e-mailed or submitted to the government, not printed out.

    JAMA - a Java Matrix package. The fact that this library has a working singular value decomposition has saved me bunches of time programming a boring and tricky algorithm. I guess it has other stuff, too.

  13. Re:Commons Logging is crap by michaelggreer · · Score: 2, Interesting

    However, in the most common case YOU are the developer using the library. Only use commons logging if you plan to redistribute your work as a library for others. If you are building an app, _do not use it_. The dev who designed it said so himself.

  14. Re:Commons Logging is crap by sameb · · Score: 2, Informative

    This rationale makes sense, but ignores the plight of client apps (as opposed to server apps). When writing a client app, you want as low an overhead and as much compatability as possible. Commons Logging lets the developer have zero runtime or compile-time dependencies on heavy-weight logging systems (like log4j) or newer Java versions (like 1.4's logging system). The developers can instruct the logging to use log4j or 1.4's logger while developing, and set the layer to use a NoOpLog for shipping. Total logging overhead: 28KB (which would have been required anyway from using a library that used commons logging) and zero extra dependencies.

  15. I'll see that quote, and raise you another by dark404 · · Score: 2, Insightful

    C++: As powerful as assembly, and as easy to use as... assembly.

  16. Apache is your one stop shop by LadyLucky · · Score: 2, Insightful
    If it comes from apache, use it. There's so much!
    • Log4j (really, reconsider using it, it's the industry standard even with the 1.4 logging stuff, that should tell you something)
    • Tomcat for servlets, it's great
    • Velocity for a templating engine
    • Commons for your utility junk
    • Ant for building stuff
    I would also recomment as another poster has Doug Lea's concurrency utilities. If you have *anywhere* written an Object.wait() or a Object.notify[all](), then replace it with these libraries.

    Junit is indespensible and these days with the IDEs indistinguishable from the core java libraries themselves.

    Don't write SQL, use hibernate.

    For security, you cant go past the legion of the bouncy castle (I'm serious)

    Use cruise control to set up a continuous build

    And the *only* piece of closed source code we rely on is Clover coverage. It's simply fantastic. You'll love it if you adopt unit testing as your quality mechanism.

    --
    dominionrd.blogspot.com - Restaurants on
  17. Fastutil by BoxedFlame · · Score: 2, Interesting

    fastutil is what Jakarta Commons Collection should've been: an actually competent implementation of truly type safe containers.

    MG4J from the same place is pretty interesting too.

  18. jdbc, snmp, by speculatrix · · Score: 2, Informative

    stating the obvious, no server-side java is complete without a DB!

    JDBC - mysql or postgresql or oracle-classes.jar

    we, an ISP, do lots of networky stuff with SNMP; Jonathan Sevy has a nice easy to use class library:
    http://edge.mcs.drexel.edu/GICL/people/s evy/snmp/s nmp_package.html

  19. crypto - Re:jdbc, snmp, by speculatrix · · Score: 2, Informative

    oops, I forgot. we're on /. right, so crypto is a must-have:

    these guys know what they're doing, winning awards in a david-vs-goliath arena:

    http://www.bouncycastle.org/

  20. XOM! by CraigoFL · · Score: 2, Informative
    XOM is an excellent XML-handling library. It makes XML parsing, interpretation, and generation a breeze, and goes to great lengths to ensure that what you do is correct according to the XML specs. It's an absolute pleasure to use, especially compared to the "standard" SAX and DOM libraries.

    It's created by Elliotte Rusty Harold, who is one of the bigwigs in both the XML and Java arenas. XOM is at the intersection of those two sets.

    Technically it's still in "beta", but the API hasn't changed at all since the Alpha releases, and all the bugs fixed in the beta stages have been for performance boosts or to fix bugs dealing with the very fringes of XML.

    Probably the best part of the library isn't the code itself; it's the design process that went into making it. Check out the Design Principles for a good read.

    Craig