• (cs) in reply to ip-guru
    ip-guru:
    Bananas:
    ip-guru:
    Land of Hope and Glory:
    Good Ridance Day we call it!
    Actually the USA wasn't granted independence until 3rd December 1783 so they haven't even got their holiday correct ;-)
    Not trying to start the war up all over again, but A's independence from B does sort of have, as its fundamental basis, that A doesn't need permission from B.

    :-)

    Good point, I will declare myself independent form the UK & Tel HMRC where to go with their tax bill, How far will i get.

    seriously though you guys can have your Holiday whenever you want & goo luck with it (+ the weather is better in July)

    The weather is very nice in most of the USA in September, which is when the Treaty of Paris was actually signed. Of course, the States did not ratify it until January 14, 1784 so the weather thing might still be an issue.

    It's a shame the peace treaty didn't address petty, insulting, and ignorant Brits on the internet.

  • azurefrog (unregistered) in reply to SeySayux
    SeySayux:
    Java and C++ are both relatively good languages, but their application domain is rather different. (Although I personally advocate for C# to replace Java).

    Java is great for your common "business logic" application. It's simple (don't need to hire smart programmers), has good IDE support, pretty easy to deploy, comes with a vast library and has even more third-party libraries available.

    However, as soon as keywords such as "performance" (now less), "memory usage" (still a huge issue), or "integrates well with the underlying OS" are mentioned... Well, C++ suddenly becomes a pretty good choice.

    Basic C++ isn't more difficult than Java, but C++ offers a lot more features (for one thing, the template system in C++ dwarfs Java's generics implementation -- which consists basically of automated casts from/to Object) for library developers. In return for this deal you'll get less IDE support and more complicated error messages (although projects like Clang attempt to fix both). If you apply the proper patterns, memory management is as easy if not easier than with a GC.

    If you want to see a case study where a C++ implementation might have increased performance by allowing stack-allocated objects and decreasing memory usage, look up a game called "Minecraft".

    Also, Java is ludicrously verbose. Some have called it "COBOL of the 21st century": so simple (as in featureless) even a chimp could use it, extremely verbose, and managers tend to love it.

    Take, for example, the task "open a text file, read it line by line and store it in an array". I'll give you the Perl code:

    open(my $file, "<", "in.txt") or die;
    my @list = <$file>;
    

    Java programmers: please show me the Java code for this without looking it up or using your IDE.

    Well, I would just

        List<String> lines = IOUtils.readLines(new FileReader("in.txt"));
    

    But since you want it as an array, you'd have to convert it thusly

        String[] lines = (String[]) IOUtils.readLines(new FileReader("in.txt")).toArray();
    
  • instigator (unregistered) in reply to azurefrog
    azurefrog:

    Well, I would just

        List<String> lines = IOUtils.readLines(new FileReader("in.txt"));
    

    But since you want it as an array, you'd have to convert it thusly

        String[] lines = (String[]) IOUtils.readLines(new FileReader("in.txt")).toArray();
    
    Don't you have to close that FileReader?
  • azurefrog (unregistered) in reply to instigator
    instigator:
    azurefrog:

    Well, I would just

        List<String> lines = IOUtils.readLines(new FileReader("in.txt"));
    

    But since you want it as an array, you'd have to convert it thusly

        String[] lines = (String[]) IOUtils.readLines(new FileReader("in.txt")).toArray();
    
    Don't you have to close that FileReader?

    Sure. In a real program I would worry about closing my file when I'm done with it. I would also have to worry about handling the IOException if it didn't open cleanly, and logging, etc.

    But this is just a code fragment to show the method by which I would "open a text file, read it line by line and store it in an array".

  • Queen Elizabeth (unregistered)

    TRWTF is American independence.

  • Foo (unregistered) in reply to jay
    jay:
    ip-guru:
    Good point, I will declare myself independent form the UK & Tel HMRC where to go with their tax bill, How far will i get.

    If Britain had won the war, then we wouldn't be debating when the U.S. became independent. July 4 would probably not be remembered as an interesting day at all. Or it might be remembered in Britain today pretty much the same way they remember November 5.

    It is: a largely irrelevant date, except as an excuse to use fireworks.

  • (cs)

    Java is way too fast to be consider as slow.

  • (cs) in reply to Nagesh
    Nagesh:
    Java is way too fast to be consider as slow.

    He replied six days later, using Java-based technology.

  • Haakon (unregistered) in reply to SeySayux

    String slurpedFile = new Scanner(new File("in.txt")).setDelimiter("\Z").next();

    It's not as many lines as perl, but it's simple enough.

  • Haakon (unregistered) in reply to Haakon

    Oh, you wanted it as an array? And with stuff closed? Scanner sc = new Scanner(new File("in.txt")).setDelimiter("\Z"); String[] = sc.next().split("\n"); sc.close();

    There. Now it's 50% longer than the perl code. Oh my. Of course, this is not the fastest way of doing things, but we're just slurping a textfile. We'll just cross our legs, hum to ourselves and pretend that the file will fit in RAM. Besides, it's going to run on a java server, and we'll have 64 gigs of RAM to draw from anyway, so who cares?

Leave a comment on “Classic WTF: Java is Slow!”

Log In or post as a guest

Replying to comment #:

« Return to Article