Take the 2-minute tour ×

Today I was returning a JSON String from Java to Objective-c. It outputted a null. To check for the Java null in objective-c I can use KCFNULL which is a typdef to some struct (as far as I can remember).

The question here is how to map Java's null to Objective-C's KCFNULL?

share|improve this question
you better to find where you read that! –  sidyll Sep 14 '11 at 22:25
@Muhammad: I reformulated the question. Tell me if it fits what you're looking for. –  James Poulson Sep 14 '11 at 22:38
I've found more than one post useful.. Although, I cannot find one that 100% answer me... so I cannot decide which one to choose –  Muhammad Hewedy Sep 15 '11 at 13:01
add comment

5 Answers

There is none.

null is null -- it is the only value of Object which represents "no object". This differs from C/C++ where NULL is a #define for (void*)0 (which generally means 0) or similar.

In addition, Java strings are not NUL-terminated (note NUL, the NULL character -- and not "NULL"!). Rather, they are stored with an explicit length like C++'s std::string. (NUL is 0 in ASCII and Unicode, thus (char)0 represents NUL.)

Happy coding.

share|improve this answer
Well, I am agree with you.. but Today I was returning a json string from Java to Objective-c which contains null and to check for the java null in objective-c I used KCFNULL which is a typdef to something else, the question here how Objc represents the KCFULL??? –  Muhammad Hewedy Sep 14 '11 at 22:18
@Muhammad See CFNull. Note that is a special object (not nil!) that represents "no value". .NET has a similar DbNull type which represents "no value" in a specific context. Consider updating the question with code that pertains to what is actually being done. Note that any mapping of null to CFNull (or nil or whatever it may be) is done in said language-binding layer. Perhaps you mean to have Objective-C load JSON's "null" as kCFNull? –  user166390 Sep 14 '11 at 22:21
really confused! –  Muhammad Hewedy Sep 14 '11 at 22:24
@Muhammad I am too! Consider updating the post with sample code showing the exact problem :) –  user166390 Sep 14 '11 at 22:25
thanks I'll try... –  Muhammad Hewedy Sep 14 '11 at 22:30
add comment

The null value in Java has nothing to do with ASCII or any character set.

If you're trying to represent the ASCII null character in Java, it's '\u0000'

share|improve this answer
Maybe he's talking about the C Null-character, \0? –  FrustratedWithFormsDesigner Sep 14 '11 at 22:12
could be. i'll update. –  Jason S Sep 14 '11 at 22:12
add comment

Are you perhaps thinking of the null character "like\0this" in a string constant (which has nothing to do with the null keyword, just to prevent misunderstandings)?

That one is really zero, also known as U+0000 or (char)0, and identical to ASCII's NUL.

What you may be remembering is that the internal representation of string constants inside a .class file uses a "modified UTF-8" encoding which represents all ASCII characters as bytes with the ASCII value -- except the null character, which is represented as the two-byte combination 0xC0 0x80. That is, however an implementation detail, solely a matter between the bytecode compiler and the JVM, and it should not be visible to the programmer at all.

share|improve this answer
So, can I consider 0xC0 0x80 is the null jvm-internal representation? –  Muhammad Hewedy Sep 14 '11 at 22:22
@Muhammad, I'm don't really understand what you're doing, but probably it doesn't mean whatever you think it means. It is simply a feature of the file format, and for all intents and purposes has no significance at all for how a program behaves. In particular, it has absolutely nothing to do with JSON serialization. –  Henning Makholm Sep 14 '11 at 22:25
really confused! can you point me where to start to understand this topic? –  Muhammad Hewedy Sep 14 '11 at 22:27
It now sounds to me like your problem has nothing at all to do with Java (and nothing to do with ASCII either), but is purely a question of how your JSON parser on the Objective-C side represents JSON's "null" construct. –  Henning Makholm Sep 14 '11 at 22:30
@Muhammad: Read this article en.wikipedia.org/wiki/Java_bytecode. Henning Makholm is talking about the binary contents of a class file. In other words the bytecode that has been produced after compilation. –  James Poulson Sep 14 '11 at 22:31
add comment

Null is not an object in that represents the absence of the latter. It will print out as null in the console despite the lack of a toString method. However to get an ASCII value you'd need to cast it to char/Character first and the chances are that the compiler will refuse this. So the short answer is that there is no ASCII equivalent for null in Java.

share|improve this answer
add comment

In Objective-C, we have "Nil", "nil, and "null". They are all zero, but their types differ. Nil is a Class pointer, nilis an object pointer, and null is a void *. There is also the NSNull class, which can represent a null value in collections like NSArray.

share|improve this answer
add comment

Your Answer


