Page 1 of 1

Are you kidding me, Java?

Posted: Wed May 15, 2013 5:30 pm
by TheBuzzSaw
Tell me what you think this program outputs. Do not cheat. When you do cheat, post your reaction in spoiler tags.

Code: Select all

package javaapplication6;

public class JavaApplication6
{
    public static void main(String[] args)
    {
        String s = null;
        s += "ASDF";
        System.out.println(s);
    }
}
I hate this language so much.

Re: Are you kidding me, Java?

Posted: Wed May 15, 2013 6:39 pm
by bbguimaraes
The single fact that, just to run the goddamn program, I have to create a folder named javaapplication6 with a file name JavaApplication6.java (both case sensitive), compile it and call it with "java -cp . javaapplication6.JavaApplication" makes me want to punch the language creators in the face.

No matter what people tell me about it, to me Java is bad design decision after bad design decision. I've used some decent software written in it (tomcat, weka) and the greatest memory I have is the complete pain the setup was.

Re: Are you kidding me, Java?

Posted: Wed May 15, 2013 9:06 pm
by Tim Wilson
It's "nullASDF," right?
:lol:

Re: Are you kidding me, Java?

Posted: Wed May 15, 2013 9:13 pm
by Falco Girgis
What, you think I have a Java environment set up and ready to go to test this? ;)

Re: Are you kidding me, Java?

Posted: Wed May 15, 2013 11:23 pm
by TheBuzzSaw
Tim Wilson wrote:It's "nullASDF," right?
:lol:
It

is

a

DISGRACE!

Re: Are you kidding me, Java?

Posted: Thu May 16, 2013 5:37 pm
by dandymcgee
I have no idea.. but it SHOULD throw an exception the moment you try to += anything to a null value. I doubt it does, but I've never had a reason to learn Java.

Re: Are you kidding me, Java?

Posted: Fri May 17, 2013 8:15 am
by gamenovice
for those of you who learned c# and c++ first, count your blessings

Re: Are you kidding me, Java?

Posted: Fri May 17, 2013 10:36 am
by TheBuzzSaw
dandymcgee wrote:I have no idea.. but it SHOULD throw an exception the moment you try to += anything to a null value. I doubt it does, but I've never had a reason to learn Java.
That is exactly what I thought. I can get past the fact that it allows it to happen... but I cannot get past what the actual result is.

Re: Are you kidding me, Java?

Posted: Fri May 17, 2013 12:09 pm
by bbguimaraes
Well, I just tried it in javascript and it seems it inherited other things besides its name...

Re: Are you kidding me, Java?

Posted: Fri May 17, 2013 5:26 pm
by Light-Dark
Image

Re: Are you kidding me, Java?

Posted: Fri May 17, 2013 6:35 pm
by dandymcgee
bbguimaraes wrote:Well, I just tried it in javascript and it seems it inherited other things besides its name...
Yeah.. but JavaScript breaks literally every existing language rule and paradigm. It's both extraordinarily flexible and ridiculously illogical at the same time.

Re: Are you kidding me, Java?

Posted: Sun May 19, 2013 10:48 am
by Falco Girgis
That is absolutely fucking bizarre... I mean, obviously any JIT language has to be pulling some behind-the-scenes bullshit to even implement the concept of a "null reference" (a reference is implemented as an autodereferenced pointer, so a "NULL" reference is technically impossible).

If you're interested in knowing what the fuck the JIT compiler is doing to let this happen, here it is:
http://stackoverflow.com/questions/4260 ... gs-in-java

Also, thanks for posting this, you bastard. Almost spit out my coffee.

Re: Are you kidding me, Java?

Posted: Sat Jun 01, 2013 7:07 pm
by Ginto8
It certainly looks insane, but the reason it is that way is so you can do something like:

Code: Select all

System.out.println("x = " + x);
and have it print out something sensible in all cases, including where x is null. There is no value of x other than null where that line ought to fail (all objects have a toString() method, and primitives have their own conversions), unless exceptions are thrown in x.toString(). So instead of making it cause a catastrophic program failure, it just converts it to a string value signifying its value: "null".


I still think it's less insane than PHP's false == "no" stuff.

Re: Are you kidding me, Java?

Posted: Mon Jun 03, 2013 4:41 pm
by TheBuzzSaw
Ginto8 wrote:I still think it's less insane than PHP's false == "no" stuff.
PHP isn't even worthy of being considered a language.

http://me.veekun.com/blog/2012/04/09/ph ... ad-design/

Re: Are you kidding me, Java?

Posted: Fri Jun 07, 2013 5:13 pm
by THe Floating Brain
Falco Girgis wrote:What, you think I have a Java environment set up and ready to go to test this? ;)
:lol:
Oh Java, what a terrible language XD