- A Concurrent Affair - https://www.concurrentaffair.org -

Dumb Email of the Day

We just received the following email on our mailing list:

[DRJAVA-L] Hi, I am a user of JAVA. I found a big bug!

HI,
I am a student in CWRU. Now, I am studying JAVA. Compared to
Program C. I found that java have more changing. however, it is
something no good. Just like the code here:

1
2
3
4
5
 String [1] a="anjof";
 char[] b=a.toCharArray();
 b[2]='\\0';
 String [1] n=new String [1](b);
 System [2].out.println(n);

what do you think it will print out? Actually, it print “an of”! I am
very shocked of this? Do the java maker know the difference
between ‘\0’ and ‘ ‘? I think this is a serious problem.

Why are we even getting this email? My response:

Java does not use null-terminated strings like C does. This is the
expected behavior in Java, and in C++ too, if you are using C++
std::string. The behavior is dependent on the language you are using.
Java is not C.

Furthermore, we are the developers of DrJava, not Java itself. Java is
developed by Sun. If you feel like you have discovered a bug in Java,
please contact Sun.

[3] [4]Share [5]