Difference b/n null and ""

hi all
can any one tell me the difference between,
String a = "";
String a = null;
Which one is better to use ???

Strings are unimmutable but it is wrong to say that
Strings are final.True.
They are both different things. final is a
visibilty modifier Nope. Final has nothing to do with visibility.
however Strings are
objects.What is more, if you attempt to change a
String object , you create a new String object.Not really. There is no "attempting to change" a String because there is no means to do so. str = someOtheString; isn't an attemp to change a String object. It just assigns a different reference to the variable, exactly like it would for any other object, mutable or not.
Maybe, it is better to say that Strings are some
different properties than other objects.
Because they are unimmutable.Strings are different than other objects in some ways, but none that are relevant to this discusion. And there are plenty of other classes that are immutable as well. Immutability really isn't relevant for the difference between null and an "empty" object though.

Similar Messages

  • Difference between IS NULL and = NULL

    Hello Guys,
    In 10gR2 what is the difference between IS NULL and = NULL
    Thanks,
    Imran

    Just don't use the second, because the comparison operator = cannot deal with NULLs as you (probably) hope it can:
    SQL> create table t1 as select rownum as id, 'test' as word from dual connect by level<=2;
    Table created.
    SQL> update t1 set word=null where id=1;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL> select * from t1;
            ID WORD
             1
             2 test
    SQL> select * from t1 where word is null;
            ID WORD
             1
    SQL> select * from t1 where word = null;
    no rows selectedKind regards
    Uwe Hesse
    http://uhesse.wordpress.com

  • Whats the difference between arrayCollection = null and arrayCollection.removeAll()?

    Whats the difference between arrayCollection = null and
    arrayCollection.removeAll()?

    In arrayCollection = null; statement you're setting this
    reference to null and potentially making it available for garbage
    collection. I say 'this reference' and potentially because, as you
    may know, there might be other references to this array collection
    object that won't be affected by this statement and hence it won't
    be GC'ed.
    arrayCollection.removeAll() says that I want to empty this
    array collection for all the reference that we pointing to it. That
    is, remove all the objects from the collection -- and of course
    make them 'potentially' available for the GC -- the size of the
    array collection would be reduced down to zero and all the
    references would be pointing to a valid but empty collection.
    Hope this helps.
    ATTA

  • Difference between Not Null and Null..

    Hi All,
    In Conditional Region portion i would like to know the difference between
    Value of item in Expression 1 is not null and we will assign the text filed name in expression.
    Value of item in Expression 1 is null
    When we have use the above two scenerio's ..
    Not null means what it has some value in text filed or not.
    pls help me out.
    Anoo..

    Hello Anoo,
    Validations check the input and will return an error message if the validation is not met (like 'Field is required').
    Conditions can be used to run a Process (or render an item) when some condition is met - or not- (like do this only when field is not null).
    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    http://www.bloggingaboutoracle.org/
    http://www.logica.com/

  • Difference between MySQL null and JAVA null

    When I create a new record in my MySQL db and some of the values are not intered, MySQL thinks of them as null. Java makes an error when the variable is used. But when I set the values to ' ' (blank) java sees it as null and makes no error.
    Is there a way around that??????
    BR Soren

    "" and null is totally different thing.
    you can try checking for null instead of "".

  • Difference between connection = null and connection.close()

    is it correct
    connection = null means connection object is eligible for garbage collection and does not return to connection pool
    and f or
    connection.close() means the connection object return to the
    connection pool
    is there any other difference between this ....?????

    "connection = null;" is just like any other similar Java statement, it removes that reference to the object. If that was the last reference to the object, then it becomes eligible for finalization and garbage collection, with no guarantee that either will actually occur. However, normal connection pool implementation will have a seperate reference to the connection and if the connection has not been returned, will most likely consider the connection to be "leaked" - allocated but never returned, and unusable.
    connection.close(); is a normal JDBC connection method; it (usually) closes the associated objects and releases the connection; it's not uncommon to explicitly close statements and resultsets instead of depending on connection.close(). A connection pooling implementation that works by extending the Connection class MIGHT change the meaning of close() and instead of actually closing, return it to the pool instead. Personally, I would consider such an implementation to be evil and a blight on good programming practices; changing the action of such standard methods is bound to cause trouble, IMHO. More normally, if you were using connection pooling, you would NOT close the connection, but rather call some special method to return the connection to the pool.

  • DB Diagram: Modality Difference between NOT NULL and check constraint

    Hi,
    I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there are two ways NOT null can be defined on a table (right click on the db object to edit it; a) under column definitions there is a check box for not null, b) there is a check constraint that one can add to do not null.
    I am confused and was wondering whether I must I have check constraints on the database in order to display modality (optional versus mandatory). Logically speaking it does not make any sense though.

    Hi Susan,
    Thanks for your email. I understand that in order to show modality under
    UML notation, one must define a COLUMN being NOT NULL instead of defining a check constraint.
    I still do not understand how modality (optional versus mandatory) is shown in ERD notation in JDev. I tried flipping ERD/UML notations and made sure icons for tables were showing, but no MODALITY is shown in ERD notation ( an '0" icon or a "|" icon for optional and mandatory). Is it the solid line versus dotted line in the ERD diagram? I am confused because generally under Crawfoot ERD notation '0" icon or a "|" icon is shown for modality.
    Modality gets picked up in jdev diagram when COLUMN not null is specified and UML notation is used
    ALTER TABLE DETAILAJ MODIFY EMPID not null;
    Modality does not get picked up in jdev db diagram when check constraint is specified and UML notation is used
    ALTER TABLE DETAILAJ
    ADD CONSTRAINT CK_NN_DETAILAJ__EMPID CHECK(EMPID IS NOT NULL) ;
    Another question i have related to the matter mentioned above is as follows. Since I want to see modality in db diagram, it follows that I must define a column as not null instead of a check constraint. I must also use NO VALIDATE on NOT NULL column because i have prior data that does not meet the new restriction. I noticed that if i use the following syntax to define a NOT NULL column, two things happen.
    a) A constraint is defined as not null automatically and a system generated name is given to the constraint.
    b) DB diagram in Jdev does not show the modality.
    My question is whether there is a way to see modality in this case.
         alter table DETAILAJ
         MODIFY EMPID NOT NULL ENABLE NOVALIDATE ;
    Edited by: user11219846 on Nov 19, 2009 11:07 AM

  • Connection ==null and Connection is closed, difference

    Hi experts,
    I wonder what are the differences between "Connection==null" and "Connection is closed"?
    I closed a connection on one JSP page after a bean has retrieved data. Then, on the same page I call another bean to connect to the database. Because the Connection object has been created earlier, therefore Connection is not NULL, but it is closed. So, the second bean has to initiate another connection(if I knew how to test the "closed" status)
    Is it true that if the Connection is closed, then it should become null?
    I think I must have make quite a few mistakes in above statement:). Please help. Thanks a lot.

    connection.isClosed() will tell you if the connection object is closed or not. If it is closed, then the connection object can be dropped because you will not be able to create any new statements from that connection object. Just recreate another connection to use when this occurs.

  • Null and no data in field value

    I transferring sql from MS Access to Oracle 9i.
    In Access I have this
    select * from tableOne where firstname <> ''
    and firstname & '' = ''The firstname field can be edited where it could have data and the data could be deleted so I am trying to select records where firstname is not null and it has no data in it.

    I transferring sql from MS Access to Oracle 9i.
    In Access I have this
    select * from tableOne where firstname <> ''
    and firstname & '' = ''
    select * from tableOne where firstname IS NULL;
    - or -
    select * from tableOne where firstname IS NOT NULL;
    as appropriate.
    In Oracle there is no difference betwen being NULL and having data of length '0'

  • Difference between Null and null?

    What is the difference between null and NULL?
    When is each used?
    Thanks,

    veryConfused wrote:
    There is a null in java, but no NULL. null means no value. However, when assigning value, the following is different:Although the empty String has no special role. Null means, the referential type is not assigned (doesn't refer) to a specific object. The empty String is just another object though, so seeing it or pointing it out as something special when it actually isn't at all (no more special than new Integer(0) or new Object[0]) just adds to the confusion.

  • Difference in Null and Empty String

    Hi,
    I have been wondering about the difference between Null and Empty String in Java. So I wrote a small program like this:
    public class CompareEmptyAndNullString {
         public static void main(String args[]) {
              String sNull = null;
              String sEmpty = "";
              try {
                   if (sNull.equalsIgnoreCase(sEmpty)) {
                        System.out.println("Null and Empty Strings are Equal");
                   } else {
                        System.out.println("Null and Empty Strings are Equal");
              } catch (Exception e) {
                   e.printStackTrace();
    This program throws Exception: java.lang.NullPointerException
         at practice.programs.CompareEmptyAndNullString.main(CompareEmptyAndNullString.java:10)
    Now if I change the IF Clause to if (sEmpty.equalsIgnoreCase(sNull)) then the Program outputs this: Null and Empty Strings are Equal
    Can anyone explain why this would happen ?
    Thanks in Advance !!

    JavaProwler wrote:
    Saish,
    Whether you do any of the following code, the JUnit Test always passes: I mean he NOT Sign doesnt make a difference ...
    assert (! "".equals(null));
    assert ("".equals(null));
    You probably have assertions turned off. Note the the assert keyword has nothing to do with JUnit tests.
    I think that older versions of JUnit, before assert was a language keyword (which started in 1.4 or 1.5), had a method called assert. Thus, if you have old-style JUnit tests, they might still compile, but the behavior is completely different from what it was in JUnit, and has nothing to do with JUnit at all.
    If you turn assertions on (-ea flag in the JVM command line, I think), the second one will throw AssertionError.

  • Difference between cancel_flag IS NULL and cancel_flag ='N'

    Hi ,
    Please clarify Difference between cancel_flag IS NULL and cancel_flag ='N' in PO Headers .
    Because from front end cancel check box is unchecked in abobe both the cases . We can see cancel check box status only in Help>Diagnostics>Examine .
    Thanks in Advance
    Kiran

    Hi Kiran,
    The is no difference between cancel_flag with 'null' and 'N' but cancel field contain Null if it is generated through auto create and it contains 'N' if Purchase order raised without PR .
    I hope you understand.
    Regards,
    Sravani.M
    Edited by: 855855 on Nov 9, 2012 5:49 AM

  • What is the difference between "= NULL" and "IS NULL" in SQL?

    Hi,
    I believe there is a difference between "= NULL" and "IS NULL" comparsion, but I couldn't find it. Anyone knows the difference?
    Thanks,
    Denny

    Aha, thanks:
    SQL> create table william_test_tab (col binary_double);
    Table created.
    SQL> insert into william_test_tab
      2  select rownum / (rownum - 1) from user_tables where rownum < 4;
    select rownum / (rownum - 1) from user_tables where rownum < 4
    ERROR at line 2:
    ORA-01476: divisor is equal to zero
    SQL> insert into william_test_tab
      2  select 1d * rownum / (rownum - 1) from user_tables where rownum < 4;
    3 rows created.
    SQL> select * from william_test_tab;
           COL
           Inf
      2.0E+000
      1.5E+000
    3 rows selected.
    SQL> select * from william_test_tab where col is infinite;
           COL
           Inf
    1 row selected.
    SQL>

  • What's difference between JPanel.remove(); and JPanel = null

    nice day,
    how can remove JPanel (including its JComponents), safe way, can you explain the difference between JPanel.remove () and JPanel = null,
    1/ because if JPanel does not contain any static JComponents
    2/ or any reference to static objects,
    then works as well as JPanel.remove or JPanel = null,
    or what and why preferred to avoid some action (to avoid to remove or to avoid to null)

    mKorbel wrote:
    nice day,
    how can remove JPanel (including its JComponents), safe way, can you explain the difference between JPanel.remove () and JPanel = null, Remove the JPanel from the container it was part of and make sure you do not keep any references to it from your own classes. Don't make it any more difficult than it has to be.

  • What is the difference between string != null and null !=string ?

    Hi,
    what is the difference between string != null and null != string ?
    which is the best option ?
    Thanks
    user8729783

    Like you've presented it, nothing.  There is no difference and neither is the "better option".

Maybe you are looking for

  • "A disk on [computer] is in use and could not be ejected."

    Yesterday I was doing a few things and needed to connect to my desktop iMac (running Tiger). When I did I was surfing through the applications folder on that computr when I accidentally opened iTunes. It did open, so I quit it. Anyway, then I ejected

  • BKPF-BKTXT (Doc header text source) for RV doc

    Does anyone know if the doc header text for RV doc can be maintained anywhere in the source SD doc, so that it can be transfered to the RV accounting doc? Thanks

  • Date column selection

    Hi , I have one requirement in my project for example i selected sysdate today ,this sysdate is between march last week----> Saturday to Oct first week then its want to give display 1 or else display 0. please any knows about this please give inputs

  • Disk Tracker files are no more opened

    Hi, After installing 10.4.2 in one of our new G5s, we are not able to open our disk tracker files which is created with Disk tracker 2.2.2. But we are able open them in panther. The icons of those files are shown as terminal files (unix). Though I ch

  • I can't download apps from the store with my ipad2 anymore

    I can't download apps from the store with my ipad2 anymore. It was working fine the other day. I tried signing out and back in with no luck.