null v/s ” “(empty string) in Java

220 pts.
Java development
String name
what is the difference between null string and emty string(" " ) in java?
String name;
if(name == null || name == "")
wat is the meaning of the abouve if statement?

Software/Hardware used:
null v/s " "(empty string)

Answer Wiki

Thanks. We'll let you know when a new response is added.

Null has no bounds, it can be used for string, integer, date, etc. fields in a database. Empty string is just regarding a string; it’s a string like ‘hgjko0p’ is, but is just has no length. If you have no value for a field, use null, not an empty string. Null is an absence of a value. An empty string is a value, but is just empty. Null is special to a database. null contains no reference data, so basically it doesn’t exist at all. Empty string contains no characters, but is still a reference.

Null is the database’s determination of an absense of a value logically. U can query like: where Remarks is NULL.

From the view of Database, for eg let’s take Oralce, An empty string is treated as a null value in Oracle. See the below that creates a table called Student :

create table student
( student _id number,
student_name varchar2(100));

Now insert two records into this table…

insert into student (student_id, student_name )
values ( 10565, null );

insert into student (student_id, student_name )
values ( 10567, ” );

The first statement inserts a record with a student_name that is null, while the second statement inserts a record with an empty string as a student_name

Is this help u !

Discuss This Question: 3  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    The question is not related to databases at all, but the answer might still help. You might want to take a look at this: null : Java Glossary Experimenting is usually a good way to learn.
    77,180 pointsBadges:
  • TomLiotta
    wat is the meaning of the abouve if statement? (name == null) says that no assignment has been made yet. (name == "") says that an assignment has been made; its value is "". Tom
    125,585 pointsBadges:
  • Chippy088
    Just for information only, don't know if it will help with Java, but, NULL is also used within a batch file. It is actually defined in the OS as a virtual device, I like to think of it as a black hole. Anything written to it is swallowed up and never to be retrieved. I have used it, in batch files,when a calling a command, which returns a status value/error code to the calling prog, and I have not wanted it to be displayed on screen. It is a pointer to a 'void', so the return value/error code gets dropped. Your 'emty string(" " )' actually isn't empty, it contains a space (chr$32) and empty string is indicated by "" (no space between the quotes.) so if you are having problems with empty strings, this may be the reason. I am not conversant with java, but in C, C++, VB (and many other high level languages,) it is an indication that the variable hasn't been used, (but it has been declared, and a pointer has been allocated for any value it recieves) or, it has been emptied, so it can be re-used as a clean container.
    4,625 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: