220 pts.
 null v/s ” “(empty string) in Java
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)
ASKED: November 18, 2010  5:11 AM
UPDATED: November 22, 2010  11:38 AM

Answer Wiki:
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 !
Last Wiki Answer Submitted:  November 18, 2010  8:41 am  by  Subhendu Sen   22,035 pts.
All Answer Wiki Contributors:  Subhendu Sen   22,035 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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.

 63,535 pts.

 

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

 107,715 pts.

 

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 pts.