You may assign '\u0000' (or 0). For this purpose, use Character.MIN_VALUE.

Character ch = Character.MIN_VALUE;
Answer from KV Prajapati on Stack Overflow
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 730461 โ€บ java โ€บ null-null-character
null? null character? (Beginning Java forum at Coderanch)
May 14, 2020 - The null character is \u0000, as you say. However it isn't called that in Java, in fact it doesn't have a special name because there's nothing special about it. But null? It isn't a character so you can't ask what's its Unicode value. (Not ASCII, please, Java has supported Unicode since its ...
Discussions

Null character '\0' & null terminated strings
should the strings be terminated by NUL in that character set, or by a character whose value is zero? The character '\0' is guaranteed to be a byte with all bits zero, and to have a numeric value equal to zero. A string in C always ends with this character. Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. No, in standard UTF-8 the code point with value zero is encoded in a single zero byte. You may have been reading something about "modified UTF-8", which appears to be a rather Java-centric external encoding for strings. It deliberately uses an "overlong" encoding of Java '\u0000' so that the resulting byte sequence does not contain a zero byte. One reason for this is because the length of strings in Java is not defined by use of a terminating character โ€” a Java string can contain arbitrary '\u0000' characters โ€” and you might need some way to round-trip such strings between Java and a language like C that does use a zero byte as a terminator. More on reddit.com
๐ŸŒ r/C_Programming
14
17
September 8, 2022
C - why can't we store the null character at the beginning of a string?
Sure you can. What makes you think you can't? By definition, C strings are terminated by a null character, so saying the null character is at the beginning of a string is just another way of saying the string is empty. More on reddit.com
๐ŸŒ r/learnprogramming
12
2
February 28, 2023
What does '\0' mean in java?
It's zero, not null :) It's a char with ascii value zero, as opposed to the number zero. More on reddit.com
๐ŸŒ r/learnjava
7
2
February 10, 2021
Is a null character really the most efficient way to mark the end of a string in memory?
What do you mean by "one byte represent multiple separations"? I'm confused what your string would actually look like in memory. Modern languages for the most part do not use the null character to mark the end of a string. It is generally recommended to explicitly keep track of string length, avoiding unexpected string truncations or accidental buffer overflows. It comes from a time where memory was very limited, so the single byte to mark the end of a string was more efficient than potentially using multiple bytes to store the length. Because C is so ubiquitous we can't actually stop doing it entirely, but it's become pretty normal to both keep the string null-terminated for compatibility reasons, and also explicitly keep track of its length. More on reddit.com
๐ŸŒ r/computerscience
20
29
February 2, 2023
๐ŸŒ
Medium
medium.com โ€บ @javacharter โ€บ can-you-check-if-char-is-null-or-not-in-java-9f5adcc51f77
Can you check if char is null or not in Java ? | by Javacharter | Medium
April 12, 2023 - Simplest approach I could think ... the code, I have put one condition if(ch!=0) ! Yes that is true! A char in Java cannot be null as it is a primitive ....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ does-java-define-string-as-null-terminated
Does Java Define String as Null Terminated? - GeeksforGeeks
July 23, 2025 - String: Hello Length: 5 Java strings do not have a null terminator! In Java, strings are represented as immutable object i.e., they cannot be modified after creation. They are handled by the JVM (Java Virtual Machine), and internally represented ...
๐ŸŒ
Blogger
javahungry.blogspot.com โ€บ 2021 โ€บ 11 โ€บ null-character-java.html
null character java | Java Hungry
There are 3 ways through which we can represent the null or empty character in Java. 1. Using Character.MIN_VALUE 2. Using '\u0000' 3.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-set-a-character-array-to-null-in-Java-Or-empty-it
How to set a character array to null in Java? Or empty it - Quora
Answer (1 of 6): [code]class EmptyCharArray{ public static void main(string[] args) { char namearray[6] = {'a', 'n', 'm', 'o', 'l'}; for(int i=0;i
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ null character '\0' & null terminated strings
r/C_Programming on Reddit: Null character '\0' & null terminated strings
September 8, 2022 -

Hello everyone!
In C, strings (character arrays) are terminated by null character '\0' - character with value zero.
In ASCII, the NUL control code has value 0 (0x00). Now, if we were working in different character set (say the machine's character set wouldn't be ASCII but different one), should the strings be terminated by NUL in that character set, or by a character whose value is zero?

For example, if the machine's character set would be UTF-16, the in C, byte would be 16bits and strings would be terminated by \0 character with value 0x00 00, which is also NUL in UTF-16.
But, what if the machine's character set would be modified UTF-8 (or UTF-7, ...). Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. How would be strings terminated in that case? By the byte with value 0 or by the null character.

I guess my question could be rephrased as: Are null terminated strings terminated by the NUL character (which in that character set might be represented by a nonzero value) or by a character whose value is zero (which in that character set might not represent the NUL character).

Thank you all very much and I'm sorry for all mistakes and errors as english is not my first language.

Thanks again.

Top answer
1 of 3
31
should the strings be terminated by NUL in that character set, or by a character whose value is zero? The character '\0' is guaranteed to be a byte with all bits zero, and to have a numeric value equal to zero. A string in C always ends with this character. Then, according to Wikipedia, the null character is encoded as two bytes 0xC0, 0x80. No, in standard UTF-8 the code point with value zero is encoded in a single zero byte. You may have been reading something about "modified UTF-8", which appears to be a rather Java-centric external encoding for strings. It deliberately uses an "overlong" encoding of Java '\u0000' so that the resulting byte sequence does not contain a zero byte. One reason for this is because the length of strings in Java is not defined by use of a terminating character โ€” a Java string can contain arbitrary '\u0000' characters โ€” and you might need some way to round-trip such strings between Java and a language like C that does use a zero byte as a terminator.
2 of 3
17
C11 states: 5.2 Environmental considerations 5.2.1 Character sets 2. In a character constant or string literal, members of the execution character set shall be represented by corresponding members of the source character set or by escape sequences consisting of the backslash \ followed by one or more characters. A byte with all bits set to 0, called the null character, shall exist in the basic execution character set; it is used to terminate a character string. Emphasis is mine From that we can understand that the terminating null character is always completely 0. Then, there's: 5.2.1.2 Multibyte characters A byte with all bits zero shall be interpreted as a null character independent of shift state. Such a byte shall not occur as part of any other multibyte character. 7.1.1 Definitions of terms A string is a contiguous sequence of characters terminated by and including the first null character. The term multibyte string is sometimes used instead to emphasize special processing given to multibyte characters contained in the string or to avoid confusion with a wide string. A pointer to a string is a pointer to its initial (lowest addressed) character. The length of a string is the number of bytes preceding the null character and the value of a string is the sequence of the values of the contained characters, in order.
๐ŸŒ
MojoAuth
mojoauth.com โ€บ special-characters โ€บ null-0-in-java
Null (\0) in Java | Understanding Special Characters in Programming
The null character \0 in Java is treated as a regular character that can be included in strings. It is commonly used to represent a terminating character in various programming scenarios, especially when dealing with byte streams or raw data.
Find elsewhere
๐ŸŒ
LinuxQuestions.org
linuxquestions.org โ€บ questions โ€บ programming-9 โ€บ empty-char-in-java-95407
empty char in java
September 22, 2003 - Hi everyone, I want to initialize an empty char in java, but I just found out that isn't as simple as I thought. I tried Code: char ch = ''; But that
๐ŸŒ
SSOJet
ssojet.com โ€บ special-characters โ€บ null-0-in-java
Null (\0) in Java | Special Characters in Programming Languages
You'll learn how to use Optional to avoid NullPointerExceptions, express intent more clearly, and write more robust, readable Java code. The null character, denoted by \0, is a control character with an ASCII value of 0.
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 425629 โ€บ how-to-check-null-character-in-an-array
java - How to check NULL character in an array [SOLVED] | DaniWeb
June 14, 2012 - I think the OP is referring to the C convention of representing strings as arrays of characters with a zero at the end. ... There's no such entity as NULL in Java. There is null, but that is not a valid value for a char variable.
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ java-pathfinder โ€บ c โ€บ MiQymYoQy9Y
Identifying null characters in strings
I'm not aware of any special treatment of \u0000 char values in Strings, and jpf-aprop executes antlr as part of the MethodTester. Can you give me a (preferably short) example of what fails? ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... String test = "\u0000"; System.err.println(test.length()); char ch = test.charAt(0); System.err.println(Character.isISOControl(ch)); ... When being executed within Java Pathfinder (version v6.0).
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ what does '\0' mean in java?
What does '\0' mean in java? : r/learnjava
February 10, 2021 - It's the 0th position in the ASCII table which is called NUL. You'll notice that the first 32 characters are control characters for reasons of ancient history. \0 represents null in pretty much every language I have used. For Java characters you can also use the Unicode '\u0000' and Java's ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-how-to-check-if-a-character-object-is-null-in-java-559940
How to Check If a Character Object Is Null in Java | LabEx
In this lab, we will explore how to handle potential null values when working with Java's Character wrapper class. Unlike the primitive char type, the Character object can be null, and failing to handle this can lead to NullPointerException errors.
๐ŸŒ
ScienceDirect
sciencedirect.com โ€บ topics โ€บ computer-science โ€บ null-character
Null Character - an overview | ScienceDirect Topics
Using URL shorteners to perform the JAR-inclusion attack has been useful to prevent browsers from double-encoding content. So, to prevent this type of attack, Web sites only accept valid UTF-8 encoded content (note that UTF-16 allows null bytes) or other charsets that disallow null bytes. There are other cases we need to take care of while conducting this attack, such as the fact that the content can only be reflected once; if the JAR is echoed two or more times, Java will consider it invalid.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null_character
Null character - Wikipedia
January 7, 2026 - The null character is a control character with the value zero. Many character sets include a code point for a null character โ€“ including Unicode (Universal Coded Character Set), ASCII (ISO/IEC 646), Baudot, ITA2 codes, the C0 control code, ...
๐ŸŒ
Upwork
upwork.com โ€บ resources โ€บ articles โ€บ {name}
Null in Java: Understanding the Basics - Upwork
August 5, 2024 - Hoare introduced null to signify a reference that does not point to any object, believing it would be a convenient way to handle uninitialized variables or missing data. However, he later referred to it as his "billion-dollar mistake" due to the numerous bugs and issues it has caused in software development over the years. Java's creators included null to provide a standard way to represent the absence of a value in object-oriented programming.