views:

458

answers:

14

I'm curious to know what other Java programmers feel is their favorite part of the language, why they feel that way, and why other programmers should want an intimate knowledge of it as well. I'm looking for reasons like simplicity, performance, etc. Thanks.

+18  A: 

My favourite Java API is the Collections Framework. I find myself using it all the time instead of rolling my own implementations, and it is highly enjoyable and simple to use. It consists of several useful and interchangeable implementations of high-performance data structures and algorithms, as well as several convenience methods for wrapping additional functionality around them.

A tutorial by Josh Bloch can be found here: http://java.sun.com/docs/books/tutorial/collections/index.html

Kamikaze Mercenary
I agree and the generics-based types only make it better.
Bob Cross
+2  A: 

I'm a huge fan of JPA in Java EE. It has reduced the amount of work I need to do for both large apps (which would be using EJBs) and small apps.

A close second is JAAS, the security API, here is the link for Java SE JAAS : http://java.sun.com/javase/technologies/security/

Hugh Buchanan
+2  A: 

java.util is very util. Why?

  • Collections. Lots of them!
  • Date and Time classes
  • Text scanner
  • Dependency injection utility (since Java 6)
  • A timer thread
  • Random numbers
  • The observer pattern is there
  • Java properties
Marcio Aguiar
Could you elaborate on "Dependency Injection" please?
OscarRyz
The Date API leaves a lot to be desired... next time I have to work with dates, I guess I will use Joda Time.
Germán
+3  A: 

javax.naming

http://java.sun.com/javase/6/docs/api/javax/naming/package-summary.html

Java is a great systems integration techonolgy because of its portability, and JNDI does a good job of abstracting away the complexities of getting first contact with a remote system.

Internet Friend
+7  A: 

My favorite part of the API is definitely java.lang. It has this class called String, which allows you to easily manipulate arrays of characters. Any programmer who is serious about writing good Java code should check it out.

Michael Angstadt
You've just made my morning!
RichH
+4  A: 

Definitely the Collections Framework. It is used all the time whether you are doing server side Java or client side, graphical or not. It's easy to use. Most data structure classes have both a non-generic and a generic version (best to use the second, but there's legacy code that uses heavily the first), but they are pretty much identical in terms of the API other than the class parameters. In .NET the two versions can have different names/API and it can get very confusing. I also like how the Java Collections Framework have algorithms as static methods (e.g. Collections.sort(collectionVar)) rather than as instance methods. In .NET they use instance methods and for some reason, not every data structure has a sort...the Collections Framework is also very rich and you can find both simple and specialized data structures (e.g. LinkedHashMap which preserves the insertion order).

One downside I've heard is that the framework does not perform well and some people write their own. I can't verify it as I don't deal with performance-critical stuff.

origin
+1  A: 

java.util.jar - Helps with loading .jar files into a class loader for my application plugins! I love it.

Richie_W
+1  A: 

java.util.regex

There are other packages I can't live without, but the regex package has to be in the top tier of "greatest additions to java" -- definitely right up there with Collections.

Chris Mazzola
+3  A: 

Reflection. Some of it is in java.lang.reflect and some in java.lang (mainly Class and ClassLoader).

John Meagher
+1  A: 

i agree with the Reflection comment. by far the most useful/powerful part of the Java API

Richard
+3  A: 

Streams. The streams in Java are much easier to grasp and implement than their counterparts in C++ (opinion) and it is usually easy to see, based on the names of the streams that come with the API, what a stream is going to do for you.

MetroidFan2002
+1  A: 

Thinking back to my Java days, the single most fun API to use was java.util.concurrent, simply because it provides well-thought-out and easy-to-use building blocks for parallel processing.

Torsten Marek
+7  A: 

java.util.concurrent is critical to my life. We do quite a lot of multicore programming and the idea of trying to implement all of our tasks using old-style raw Threads just makes me feel ill.

A good example of where the concurrency package really make our lives easier is the pool of specialized data structures that it provides. My personal favorite is the CopyOnWriteArrayList. We use the quite a lot in situations where the display task is reading from a cache of data to update the screen while another task is taking information from the network to update the cache. Normally, this would be an invitation for collisions, ConcurrentModificationExceptions and similar horrors. Using the CopyOnWriteArrayList, the writing task will create a new copy of the data if it needs to add data, thus ensuring that the reader will always have a valid (though potentially out of date) data set to display.

As the javadoc says,

This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads.

Java eliminates whole classes of bugs that I would normally introduce to solve this problem, enabling me to focus on the actual problems that I need to solve.

Bob Cross
A: 

InheritableThreadLocal all the way !!! Just so much opportunity to write obfuscated code and the reel of rope to hang yourself just never seems to run out.

Nicholas