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:
String a="anjof";
char[] b=a.toCharArray();
b[2]='\\0';
String n=new String(b);
System.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.