What does Sup Forums think of Java?

What does Sup Forums think of Java?

does not work 50% of the time
use something else please

What happened to her hair? Does she have cancer?

Could you help me out with my code?

yeah, whats up

Java isn't bad as far as features camelCase everything and multiplatform gc are what's killing it for sure. Plus c# has more features and supports more important platforms better than java does in some cases

Thanks.
Why do I get a runtime error when the scanner is closed (line 53)? For example if entering 2 and then 10, the program correctly returns and displays the volume, but then crashes after answering 'yes' when being prompted for more input. It seems to work fine when close() is not invoked (as it currently is in the following code)
hastebin DOT com SLASH evitufevez.cs

>camelCase and multiplatform gc are what's killing it
Why though? Yeah camelCase isn't very aesthetic but how are they killing it

You're closing the Scanner whether the user enters yes or no.
If they answer yes, you close the Scanner then try to get more input anyway.
The error actually occurs on line 19 when you try to read from a closed scanner on the next iteration.

Multiplatform GC because then they can't just optimize for one platform they have to make a generic GC system that works on all platforms. Which isn't going very well considering how slow GC is

I see. So creating a new scanner at the beginning of the loop doesn't work?
I guess I should elaborate: I'm trying to get into the habit of writing air-tight code - where user input can't break it or cause an error. The try-catch has helped, as well as the while loop on line 35, but I noticed the user can fuck things up if they enter enter extra tokens after saying 'yes' (line 32).
Is there anyway to clear the scanner's buffer?

very good assuming you have an assload of ram

Oh, I didn't realize you were doing that.
I don't know the gritty details of Scanner, but it seems like a bad idea to create a new one for every iteration.

Can you provide more detail on the situation you're trying to prevent regarding extra tokens?

Totally. As an example, say we run the program and the user enters
Radius: 2
Length: 10
The program calculates and displays the volume correctly, and then prompts the user to enter yes or no for more input. If we enter "yes blah blah", the yes gets fed to the string and it passes the while loop, but them scanner still has "blah blah" in its buffer, which the scanner then tries to give to radius. It doesn't cause an error, but I would like to flush or clear it just because I'm compulsive.

Okay, I kind of thought so.
How about using nextLine() on lines 32 and 39 and deleting line 38

This would change the behavior a bit, but as a user I wouldn't expect "yes blah blah" to mean yes.

That should work.
>but as a user I wouldn't expect "yes blah blah" to mean yes
Yeah, you're definitely right. What would you recommend as a software developer?

This is a university assignment, right?
As a former student, I recommend not worrying about it too much

As a software developer, I recommend keeping it simple

Heh well it was an assignment at one time. I got my degree (but not in cs, but took two semesters of introductory programming for my major) and now I'm trying to go back and practice doing old assignments, but by implementing what I now know and trying to improve.

With the disclaimer that I'm not exactly a professional and I'm a little drunk

But how do you make sure, in general, users can't crash your program with silly input? Thanks for all of the advice and help btw.

That's fine with me!

>I would like to flush or clear it
Been a while since I've used java but iirc, I had a similar problem once and used something like:
//flush
while myScanner.hasNext() myScanner.next();
//now get new input

I don't remember the exact syntax or know if it's the "right way", but it worked

That's a dude.

Not sure how to answer in general. I think it depends on how far you want to take it.
For example, if the user ends the input stream (Ctrl+D on linux) partway through the loop, your program will crash with a NoSuchElementException.

Then question, then, is: do you care?

I often take the user-hostile approach and say it's their own fault if things go wrong in such cases, just to make my life easier.
However, I write a lot of software for myself which influences how much error handling I do.

I think this code will loop forever until the user ends the program forcibly by closing the input stream or killing the process.

I was about to recommend it myself, though, so I definitely understand your thought process.

Dark roast or nothing.

Thanks, yeah i first tried something similar to this. It was method that went like tbis
public static void flush(Scanner input)
{
while (input.hasNext())
input.next();
}
but for some reason it didn't work.
This is very good advice. Besides a lot of software of course is GUI today, and I think it may be easier to handle such hostile input in text fields, no? What sort of things do you write for yourself?

In GUI apps, yes, it can be easier.
There is usually some separation between the input and the "business logic" so you can simply refuse to do anything with the input until it's valid.
Also, there's not necessarily a sequence to entering input - each field can be handled separately.

I write lots of command-line utilities, mostly in Python, and mostly to manage files in complicated ways.
I'm still working on the ultimate software to organize my porn collection...

Nice, what was your degree in? What do you do for work now if you don't mind me asking?

I have a CS degree, but I'm mostly self-taught. The degree is more of a formality to help get a job.
I got out of school a year ago and I'm still unemployed 'cause I'm a lazy fuck.

What was your degree?

Also, I must say I'm impressed by how much you care about writing good software.
It really bugs me when people don't take programming seriously.