views:

1071

answers:

30

After the series of Hidden feature posts, now is the time for listing down your favorite features. This thread will be used for listing Java specific features.

This is a community wiki. Please be specific.

Update : For .Net, please post your answers here: What’s your favorite feature in .NET?

A: 

Beans. Purely because of the name. Every time i hear it, i think of Bob & Ray. Or lame fart jokes. Name anything else, for any other language, that can inspire such thoughts. I dare you...

Shog9
Best reply evar.
Daddy Warbox
+15  A: 

The number one thing that as a C# guy makes me jealous is java.util.concurrent.

dpp
util.concurrent has been an awesome addition. I was even using the backport from Emory U's CS department, before I was *allowed* to use 1.5.
Spencer K
How was the package called again? EDU.oswego.util.concurrent or something like this...
dhiller
+20  A: 

Garbage collection!

questzen
+8  A: 

No #include,ifdef,undef,define. Building multifile projects is 100 times easier than in C/C++ because the order of the classes doesn't matter. I thinks this is pretty damn important for newbies to programming. No wrestling with Makefiles and weird compiler errors.

Dove
sometimes i still wish java had a preprocessor for conditional compilation.
luke
C# Does, and I use it all the time :)
FlySwat
+12  A: 

More of a meta-feature: The fact that we can work in an environment using Macs, Windows and Linux computers based a personal preference and deploy to other Unix (Solaris and AIX) environments while almost disregarding the platform.

Martin
+14  A: 

Collections! You youngsters probably don't remember what it was like not to have a bunch of different collection types provided. Having to constantly reinvent the wheel (and the list and the dictionary). Ugh. The memories make me shudder!

Skip Head
But how easy are they to customize? I have a bad habit of including very specific functionality in my ADTs, requiring either direct access to the structures or frustratingly minor tweaks to the methods they use. java.util. Yeah. One look at the source, and I rolled my own. Over and over again.
Ellery Newcomer
Ellery, sooner or later you discover that you can expand the Collections to do almost anything you want. In order to do that, you need to turn "Zen" and let the "control freak" in you go. Everything will be easier. You'll see.
Rolf
@Ellery Newcomer: Usually you just wrap a collection class with a class of your own. See e.g. http://en.wikipedia.org/wiki/Delegation_pattern
sleske
+9  A: 

From an enterprise developer of 20 years who's worked in C, C++, Basic, Assembly and Java with a diverse range of talents (mostly "un"), I may have a different view than some others.

Simplicity and the lack of surprises and the fact that it's hard for another programmer to hide subtle issues behind cool tricks.

By this I mean:

  • the fact that a class must be contained entirely in one source file, any references (includes) are clearly pointed out and easy to follow.
  • The fact that there aren't too many "Neat/fun" constructs and the language is fairly consistent.
  • The inability to change the effect of the programming language, the way it is always explicit--eliminating operator overloading and no macro type functionality.
  • Very explicit reflection--sometimes it's quite useful--but I'm really glad it's not easier.
Bill K
+4  A: 

That it is now Open Source!

It's nice to see the various Linux distributions having a fully functional Java out of the box. Not to mention that soon we don't have to rely on Apple for Java on OS X.

Steve K
+9  A: 

I like the strong static types in Java. It is a key component of the language and most people will look past it.

I've tried Python and Javascript. I don't much care for dynamic typing.

jjnguy
That's an odd position, since Java has one of the weakest type systems of all statically typed languages.
Apocalisp
@Apocalisp: Really? How so? I'm genuinely interested.
Joachim Sauer
+1 -- static typing and an IDE that uses it to show the relationships in code was a revelation to me.
Edmund
+15  A: 

Binary portability.

Everyone loves the vast multitude of free, 3rd party libraries available for Java. But what makes them particularly compelling is how easy they are to use. Almost no other free software out there is distributed in binary form. Almost all of it is in source code, save for Java.

Sure, you can get the source code for your favorite 3rd party libs and apps, but most folks go straight for the jar. Who here builds Tomcat from scratch? Unless you're a developer, there's basically no need to. (Which is a good thing, early Tomcat was a nightmare to build.) Rather, extract the zip file and fire it up -- Unix, Windows, Mac, whatever.

This portability and ease of use is a strong force in the Java world. You have a huge marketplace of users, they already "know" how to install your code with hardly a glance at the documentation. Heck, some libraries are a combination library and running application.

If we as Java coders had to build all of our software from scratch, playing "DLL Hell" that seems to permeate all of the popular platforms, we'd be doing a lot more reinvention instead of reuse, if for no other reason than to avoid the pain of getting some random library built.

Will Hartung
Jar version hell still exists (I've seen apps with five different versions of log4j in use inside...) but tools to help manage this sort of thing exist. For example, maven has `<dependencyManagement>` and `dependency:tree` (and m2eclipse makes it even better).
Donal Fellows
+4  A: 
Shimi Bandiel
+2  A: 
  1. The advanced refactoring you can do with certainty across a large codebase: rename variables, methods, classes, packages. Push/pull members/methods up or down a class hierarchy. Extract constants.

  2. Reflection allows frameworks to handle unknown code at runtime, a very powerful concept.

  3. Customizable class loading. Data == code.

Dov Wasserman
+7  A: 

Very IDE-friendly. Most of the cool stuff Eclipse is helped by the language- no preprocessor, static typing, etc.

Runner-ups:

  1. Fantastic API. Flexible, complete and well thought of. The major problem it has, it does not accomodate the learning programmer. Some shortcuts would be helpful for the "simple stuff"; i.e. parsing XML without dealing with too many factories and the like. You can write these shortcuts yourself if you have some experience, but doing simple stuff can be too baffling for newbies. Most other problems would be solved if they actually read the Java Tutorial.
  2. GC
  3. Anonymous classes. Too verbose, but very handy.
  4. Reflection and proxies.

I'm not counting here the ecosystem. For some reason or other, there's lot of high quality Java code out there, and it's easy to find.

alex
Eclipse doesn't seem cool anymore once I've gotten used to IntelliJ IDEA. Too bad I'm too cheap to buy a license for personal use :(
TM
There are no anonymous functions (yet? and alas). Only anonymous classes with one or more functions in them.I agree with the API, on both remarks: it is too "hard" to do a simple task like reading/writing a simple text file. Flexibility has a cost.
PhiLho
@PhiLho: you're right, I meant anonymous classes; corrected!
alex
+5  A: 

My favourite "feature" in Java is IntelliJ IDEA :)

Pavel Feldman
I wouldn't call it a feature of the language, but I do love IntelliJ!
TM
+1  A: 

Being able to run languages other than Java on it.

madlep
A: 

Cross platform of course. Develop in PC deploy in HP-UX or AIX mosters!!! with absolutely no changes.

OscarRyz
+1  A: 

I thought annotations were a really neat feature in 1.5. I like how it simplifies code while improving code readability. Hibernate and Web Servies are two examples I can think of that have benefited strongly from annotations.

spelchec
A: 

My favourite Java feature is Scala.

Apocalisp
+7  A: 

The number of opensource libraries available.

Also, call me sick, but I love the way java code looks.

alex
I'm with you. I just feel comfortable with how Java code looks.
aitor
You're not sick. Java code readability and writability are very balanced. Most of it, inherited from C.
mrrtnn
+1  A: 

The for-each loop from Java 1.5. An awesome improvement in terms of readability, by hiding the index or iterator variables .

Vijay Dev
+1  A: 

Annotations (.NET: Attributes).

EricSchaefer
+3  A: 

the synchronized keyword. Thread safety is so much easier...

Jason S
Synchronized does not guarantee thread safety. That is a lesson that everyone who writes a multi-user app soon finds out.
WolfmanDragon
true but it's easier.
Jason S
+3  A: 

Choice.

There are several IDEs (Eclipse, NetBeans, and the best of all, IntelliJ). You can use EJBs using several app servers or pass and use Spring POJO development. There are lots of persistence technologies: Hibernate, iBatis, TopLink, OpenJDO. There are literally HUNDREDS of web MVC frameworks: JSF, Struts, Wicket. There are several DI engines: Spring, Guice, PicoContainer. There are different aspect-oriented implementations: Spring aspects or AspectJ.

Some people think this is confusing and a drawback. It's certainly easier to simply point to whatever Microsoft is offering and say, "We'll use that."

But I like the choice.

duffymo
A: 

Pre-Java 5 lack of templates. I am sorry, but I've read every argument as to what to include them, and it still does not justify having to write monstrosities like

for(Iterator i = myCollectioon.iterator(); (MyTargetType)i.next(); )
{
///
}

And so on and so on.

I wrote a large program in 2001-2002 that did a lot of set theory processing, and it was gruesome.

Uri
+1  A: 

I know it may be like giving a crazy monkey a loaded gun, but I love reflection. Every time I have to do something, my brains try to think a reflection-wise way to do it. A pity I currently work with C++ (don't hit me please!)

aitor
+1  A: 

java enum is better than c#. you can write inner class in enum class to do your business logic. in c#,enum is just a data list.

liya
A: 

parent Classes, i really would like to have this in c++ as well:(

Christoferw
What are "parent classes" ?
OscarRyz
C++ can do inheritance.....
The Elite Gentleman
Perhaps he means a single-rooted inheritance hierarchy. I know why C++ doesn't do it, but it's still one of the big decisions that Java got right.
Donal Fellows
+1  A: 

Generics. Now, I don't have to worry about writing returning or passing Object. Instead I can parameterize it. It's very effective when done well (mostly with inheritance). :-)

The Elite Gentleman
A: 

It's simplicity, yet extreme depth. Someone can learn Java quickly, but it can take a lifetime to become an expert in every bit of Java. It can do so much, and can continually surprise you with what it (or a new library) can do.

A lot of this simplicity is down to it's inheritance model, no need for pointers and it's garbage collection.

Codemwnci
A: 
  • Strong typing, checked Exceptions: no surprises at runtime.
  • Neat java.io library design.
  • Neat collections framework design.
  • Dynamic classloading mechanisms (you can load even bytecode).
  • Threads/Monitors as part of the language.
  • Reflection API.
  • Garbage collection. Weak references.
mrrtnn