views:

167

answers:

7

I recently got into Java. I have a background in dynamic languages and I'm finally figuring out why people complain about Java's verbosity. Are there any class libraries out there that address this issue? I'd much rather type something like "String text = someClass.stdin()" instead of the 8 or so lines it takes to get user input in Java.

+4  A: 

Some of the Apache Commons libraries (particularly Lang, IO and Collections) are designed to hide the verbosity of certain core Java APIs. The verbosity of the Java language, however, we're all stuck with.

skaffman
this looks like exactly what I need.
Goose Bumper
+2  A: 

Sure there are several JPython, JRuby, Clojure, Scala...

stonemetal
+2  A: 

Google has also released a number of libraries that complement sections of the standard library, like the collections library. Guice is also a nice lightweight DI framework that, IMHO, is easier to learn that spring.

The standard library is so large I don't think you'll find a single library that replaces everything. You're best bet is to look for libraries that solve individual problems (i.e. I don't like the Collections API, I need an object pool, etc.)

Dan
+5  A: 

In Java 5:

import java.util.Scanner;
...
System.out.print("Enter your name: ");
String userName = new Scanner(System.in).nextLine();

Or, in Java 6:

String userName = System.console().readLine("Enter your name: ");
Andrew Coleson
+1 Great point, make sure the latest on the standard library doesn't already address it.
Yishai
Upgrading to Java 6 now. Thanks for the zen-like insight: sometimes what you're looking for is already there.
Goose Bumper
+1  A: 

I'd be interested in seeing these 8 lines to get user input in Java.

I personally think that Java's verbosity becomes an asset as your program becomes larger. Unlike C and C++, everything is done in a more object oriented way. You get the object representing your output, then you issue an operation on it, and so on. Much easier to understand and maintain in the long run.

Is this as quick as a nice printf() here and there? No. Is it as convenient as scripting in Python? Of course not. But that's part of the cost of using a language like Java, just like the lack of Lambdas is annoying.

As an engineer your role is to pick the best tool for the job. I do most of my coding in Java, and some in Python, accepting the tradeoffs of each.

While you can't change the language, you could use libraries that simplify some operations (e.g., Google's or Apache's IO libraries). You could also write your own classes for the things that annoy you the most.

I also think you're confusing the verbosity of the language and of the standard library. The library contains a lot of stuff, most of it you'll never need. I find the existing division fairly straightforward and have never found myself in areas I didn't care about.

If you really can't stand Java, you might want to use hybrid languages like Scala.

Uri
A: 

I'm a big fan of leaning on my IDE's live templating features. (IntelliJ IDEA) I can't remember the last time I spelled out StringBuffer or System.out.println("...").

Alex Feinman
A: 

If you think Java is bad, just wait until you start with Cobol....

Thorbjørn Ravn Andersen