• 516052 (unregistered)

    Java is like the Lebel Model 1886. A good idea slightly ahead of its time and thus implemented poorly. We had to wait until C# to see it done right.

  • (nodebb)

    This reminds me of the people who take the fizzbuzz interview question and add 30 unasked-for features.

    IANA Java dev, but the answer the newbie needed was something close to

    String string = System.in.readline();

    Everything else depends on what needs to be done once that string is in hand.

    Addendum 2026-10-07 07:54: Dammit Markdown; there was supposed to be a newline between the prose and code

  • Hmmmm 🤨 (unregistered)

    This seems like a bad compromise between teaching about keypress detect and reading from stdin...

  • no (unregistered)

    i am of the opinion that languages shouldn’t do what c++ does, using a generic std::pair for everything that is an ordered pair, and that they should have more specific purpose‐made types instead.

    today i learned there are people of the opinion that a specific purpose‐made type like java’s java.util.Map.Entry is fine to use as a generic ordered pair, even for things that aren’t even remotely map entries.

  • 516052 (unregistered)

    I agree with no here. To me pair implies that there is a relationship between the two values that goes beyond just tuple. Like key-value or such. Better to make your own struct.

  • Rob (unregistered)

    Calling Scanner a wrecking ball goes too far, considering there are only two real alternatives - using Console (not available unless actually called from the CLI) or wrapping System.in in an InputStreamReader wrapped in a BufferedReader. In fact, wrapping System.in in a Scanner is the third example on Scanner's own Javadoc page.

  • Brian (unregistered)

    So what happens if the input parser needs to actually do something useful for the different inputs, like setting a flag or calling a function, not just writing a line of text? I guess you could shoehorn a function pointer (or whatever Java calls them) into your bizarro-tuple.

    If only there was some convenient way to switch between several predefined options, handling each case individually...

  • Officer Johnny Holzkopf (unregistered)

    The code presented here starts with "public static void main(String[] args)", but then does nothing with args, which is the command line arguments array. You could import commons.cli and use its "Options" object and methods to declare, check, and process the command line. Or maybe do a little string processing if it's just something simple (like "-a" or "-b", then do this, else do that, or else print an error). Allow me to repeat the initial question: "in Java, how do I correctly read user input from the CLI and act on it?" The suggested solution does not answer this question AT ALL. From the CLI. The Command Line Interface. Not from standard input, not from terminal input, not from anything else pressing keys somewhere... or... maybe it was the wrong question?

  • A Human (unregistered)

    Don't diss my boy Scanner, that's the first java class we learned about in high school IT.

  • (nodebb)

    Can't have been a very experienced senior developer then if he didn't know that you do this with (in C, since I don't know Java):

    char command[100];

    gets(buffer); system(buffer);

    Any experienced senior developer would know that.

  • 516052 (unregistered) in reply to Officer Johnny Holzkopf

    From what I remember, and it's been years since I did Java, you just make a program designed to be run from a terminal and only from a terminal and than that terminal is your input and output. And you just use Console.

  • e (unregistered)

    100% an intentional ageist attempt to drive the youth out of the industry

  • xtal256 (unregistered) in reply to 516052

    "slightly ahead of its time"

    Ha ha, no. It was behind it's time. Smalltalk had existed for over a decade and did it better. Java was an attempt to cram those ideas into a C/C++ like language.

  • 516052 (unregistered) in reply to xtal256

    The point of Java is not in any sort of set of ideas, concepts or whatever.

    It's point is to be the next COBOL. Java is fundamentally an enterprise programming language designed to be easy to pick up, just powerful enough to get the job done and restricted enough to stop snuffy the unpaid intern who manages your system migration since Methuselah the admin died of old age and took the source code with him can't make too much of a mess of it.

    And C# just does that same thing, only good.

    The whole OPP thing is just the tool they choose to get that job done. But it was newer about the tool but the task.

  • 516052 (unregistered)

    Also, I realize that my last post has a text error. That should be "restricted enough to stop snuffy... from making too much of a mess of it."

    Don't post before you had your morning coffee and heart medication.

  • Haitham (unregistered)

    Is it creating a new Scanner object for every nextCharacter() ?!!! OMG

Leave a comment on “A Tool for You”

Log In or post as a guest

Replying to comment #705118:

« Return to Article