Differnce between null string and an empty string??

what is the major difference between null string and an empty string??
I wrote the following simple program and I could see some different output.
Other than that, any other differences that we should pay attention to???
C:\>java TestCode
Hello
nullHello
public class TestCode
     public static void main(String[] s)
     {     String s1 = "";
          String s2 = null;
          System.out.println(s1 + "Hello");
          System.out.println(s2 + "Hello");
}

There's a big difference between the two. A null String isn't pointing to an object, but an empty String is. For example, this is perfectly fine:
public class TestCode
    public static void main(String[] args)
        String s = "";
        System.out.println(s.length());
} It prints out 0 for the length of the String, just as it should. But this code will give you a NullPointerException:
public class TestCode
    public static void main(String[] args)
        String s = null;
        System.out.println(s.length());
} Since s isn't pointing to anything, you can't call its methods.

Similar Messages

  • Difference  between null vector and empty Vector

    What is the diffrence between null vector and empty vector.

    null vector means the JVM doesn't allocate memory.It doesn't exist
    in memory. NO instance!
    empty vector means the JVM allocated memory.It exists in memory.
    it's a instance than is accessabel.But only have on elements.
    GL&HF.

  • Differnce between SAP-XI and SAP PI

    hi can any body tell me what is the differnce between SAP-XI and SAP-PI

    Hi vijay,
    u can get lot of information regarding PI and XI in sdn.There already exists a no. of thread.just search with keyword "XI 3.0 and PI 7.0" u can get a lot.
    XI 3.0
    1. J2Se adapter engine was replaced with J2EE Adapter Engine.
    2. BPM was available from XI 3.0
    3. Part of Netweaver 2004
    PI 7.0
    1XI renames as Process Integration
    2.. Part of Netweaver 2004s.
    3. Has all features of XI 3.0 and every SP of Pi 7.0 has a corresponding release for XI 3.0.
    4. Runs on WAS 7.0 and has same features as XI 3,0
    From functional point, there is no difference between XI3.0 and PI7.0. There are changes only wrt SP. For every SP release on PI7.0 a corresponding SP for XI3.0 is also released.
    A comparision of the service packs in 2004 and 2004s;
    in 2004 - in 2004s
    SP12 & < - SP04
    SP13 + 14 - SP05
    SP15 - SP06
    SP16 - SP07
    SP17 - SP08
    SP18 - SP09
    For release notes
    ref:http://help.sap.com/saphelp_nw04/helpdata/en/cf/9844428e9cbe30e10000000a155106/frameset.htm
    There is no f'nal difference between XI 3.0 and PI 7.0. In order to bring all netweaver releases on par with each other , SAP released / renamed XI as PI and it is a part of NW04s
    For every release of PI 7.0, there is a parallel Support Pack on XI.
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/706005a3-3bd6-2910-91ae-a2016239bdcf">SAP NetWeaver Process Integration 7.1 – Overview of New Capabilities</a>
    Also check these threads.
    Difference between NetWeaver 2004 and NetWeaver 7.0 or 7.1
    All the diff  between XI 3.0 and PI 7.0
    differences between xi 3.0 and pi 7.0
    Difference/ changes from XI 3.0 to PI 7.0
    regards
    Bill

  • Differnce between AT NEW AND ON CHANGE OF

    Hi,
    Differnce between AT NEW AND ON CHANGE OF
    Iam waiting foryour reply
    Thanks & Regards
    Raja Sekhar.T

    Hai Raja
    check the following Documents
    1. AT NEW f.
    2. AT END OF f.
    3. AT FIRST.
    4. AT LAST.
    5. AT fg.
    Effect
    In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.
    You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.
    The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .
    At the end of a control group ( AT END OF , AT LAST ), there are two types of control level information between AT and ENDAT :
    If the sort key of the extract dataset contains a non-numeric field h (particularly in the field group HEADER ), the field CNT(h) contains the number of control breaks in the (subordinate) control level h .
    For extracted number fields g (see also ABAP/4 number types ), the fields SUM(g) contain the relevant control totals.
    Notes
    The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur.
    The fields CNT(h) and SUM(g) are filled with the relevant values for a control level at the end of each control group ( AT END OF , AT LAST ), not at the beginning ( AT FIRST , AT NEW ).
    When calculating totals with SUM(g) , the system automatically chooses the maximum field sizes so that an overflow occurs only if the absolute value area limits are exceeded.
    You can also use special control break control structures with LOOP s on internal tables.
    Variant 1
    AT NEW f.
    Variant 2
    AT END OF f.
    Effect
    f is a field from the field group HEADER . The enclosed sequence of statements is executed if
    the field f occurs in the sort key of the extract dataset (and thus also in the field group HEADER ) and
    the field f or a superior sort criterion has a different value in the current LOOP line than in the prceding ( AT NEW ) or subsequent ( AT END OF ) record of the extract dataset.
    Example
    DATA: NAME(30),
          SALES TYPE I.
    FIELD-GROUPS: HEADER, INFOS.
    INSERT: NAME  INTO HEADER,
            SALES INTO INFOS.
    LOOP.
      AT NEW NAME.
        NEW-PAGE.
      ENDAT.
      AT END OF NAME.
        WRITE: / NAME, SUM(SALES).
      ENDAT.
    ENDLOOP.
    Notes
    If the extract dataset is not sorted before processing with LOOP , no control level structure is defined and the statements following AT NEW or AT END OF are not executed.
    Fields which stand at hex zero are ignored by the control break check with AT NEW or AT END OF . This corresponds to the behavior of the SORT statement, which always places unoccupied fields (i.e. fields which stand at hex zero) before all occupied fields when sorting extract datasets, regardless of whether the sort sequence is in ascending or descending order.
    Variant 3
    AT FIRST.
    Variant 4
    AT LAST.
    Effect
    Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST ) or on the last loop pass (with AT LAST ).
    Variant 5
    AT fg.
    Addition
    ... WITH fg1
    Effect
    This statement makes single record processing dependent on the type of extracted record.
    The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record).
    Addition
    ... WITH fg1
    Effect
    Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1 .
    Basic form
    ON CHANGE OF f.
    Addition
    ... OR f1
    Effect
    Executes the processing block enclosed by the " ON CHANGE OF f " and " ENDON " statements whenever the contents of the field f change (control break processing).
    Normally, you use the statement to manipulate database fields during GET events or SELECT / ENDSELECT processing.
    Note
    There are special control structures for processing control breaks in LOOP s on internal tables or extract datasets AT ).
    ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field can only be changed in the relevant ON CHANGE OF statement. It is not reset when the processing goes into loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value.
    Example
    TABLES T100.
    SELECT * FROM T100 WHERE SPRSL = SY-LANGU AND
                             MSGNR < '010'
                       ORDER BY PRIMARY KEY.
      ON CHANGE OF T100-ARBGB.
        ULINE.
        WRITE: / '**', T100-ARBGB, '**'.
      ENDON.
      WRITE: / T100-MSGNR, T100-TEXT.
    ENDSELECT.
    Displays all messages with their numbers in the logon language, provided the number is less than '010'.
    Each time the message class changes, it is output.
    Addition
    ... OR f1
    Effect
    Also executes the code whenever the contents of the field f1 changes.
    You can use this addition several times.
    Example
    Logical database F1S
    TABLES: SPFLI, SFLIGHT, SBOOK.
    GET SBOOK.
      ON CHANGE OF SPFLI-CARRID   OR
                   SPFLI-CONNID   OR
                   SFLIGHT-FLDATE.
        ULINE.
        WRITE: /5 SPFLI-CARRID, SPFLI-CONNID,
                5 SFLIGHT-FLDATE, SPFLI-FLTIME,
                5 SFLIGHT-SEATSMAX, SFLIGHT-SEATSOCC.
      ENDON.
      WRITE: / SBOOK-CUSTOMID.
    The code between ON CHANGE OF and ENDON is executed only if at least one of the fields SPFLI-CARRID , SPFLI-CONNID or SFLIGHT-FLDATE has changed, i.e. there is a different flight connection (which also has bookings).
    Notes
    Thanks & regards
    Sreenivasulu P

  • Differnce between business name and physical name

    What is the differnce between business name and physical name in OWB

    Hi Vibhuti,
    What I have noticed is that Physical name is THE important thing that is required while importing and synchronising. It has a length limitation of 30. The mappings appear with this name in the left panel in design center. The Business name is just for reference I believe.
    Cheers,
    Swagata

  • What is the differnce between Blue,Purple and Orange Audio Tracks. Can you convert either to Green Midi Track?

    What is the differnce between Blue,Purple and Orange Audio Tracks. Can you convert either to Green Midi Track?

    Are you asking about Garageband? Your signature also mentions Logic, but I have never worked with that.
    Concerning Garageband:
    Real Instrument regions from your recordings are purple.
    Real Instrument regions from Apple Loops are blue.
    Regions from imported audio files are orange.
    Software Instrument regions from recordings, loops, and imported MIDI files are green.
    So far as I know you can convert software instrument loops to real instrument loops, but not real instrument loops to software instrument loops.

  • Differnce between DB Backup and generate Script

    whats the differnce between DB Backup and generating Script of a database.
    Please mention the main diffrence as we know while genearating script we can select tables/procedures of our choice instead of having all while in backup it takes full tables and procedures.

    Hi Abhishek,
    In addition to others’ posts, we need to know that there are different types of
    backup in SQL Server, such as full backup, differential backup, log back up, file backup and so on.  It is recommended to back up database on a regular basis, as a well-planned backup
    and restore strategy helps protect databases against data loss caused by a variety of failures. You can make
    maintenance plans to back up database automatically.
    However, generating scripts is not a disaster recovery option. If you encounter some failures about database, you cannot get data back by generating scripts.
    Thanks,
    Lydia Zhang

  • Differnce between type f and type p?

    Hi All,
    What is the Differnce between type f and type p?
    Regard,
    Mike

    Hi Mike
    Differnce bw type F and type P:-
    Packed numbers - type P
    Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.
    You can use type P data for such values as distances, weights, amounts of money, and so on.
    Floating point numbers - type F
    The value range of type F numbers is 1x10*-307 to 1x10*308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data.
    You use type F fields when you need to cope with very large value ranges and rounding errors are not critical.
    Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.
    C ---> character
    D ---> date
    P ---> packed
    T ---> time
    X ---> hexadecimal
    I ---> integer.
    N ---> Muneric.
    Reward pts if help.
    Regards
    Deepanker

  • Whats the differnce between a7 chip and m7 chip

    iPhone 5s, whats the differnce between a7 chip and m7 chip?

    For more details on M7 you can read http://en.wikipedia.org/wiki/Apple_M7
    Allan

  • Day of year bug - format date/time string and scan from string?

    I've noticed that the day of year returned by "Format Date/Time String.vi" starts with a value of 1 for Jan-1 while "Scan from String.vi" wants a 0 index.  Is this a bug or feature?  
    (I'm using Labview 2010 Service Pack 1)

    I think the best idea is to use seconds since for your arithmetic, because it is going to be the most consistent and robust solution. Knowing that a day has 86400 seconds is all that is needed and you won't run in possible inconsistencies with date time implementations caused by our anything but logic calender. I would hazard that the functionality of converting a timestamp into year and day of year and back is impossible to make consistent without sacrificing other possibly conflicting transformation in the Timestamp into String and Timestamp from String manipulations.
    "Seconds since" being the actual base unit in all LabVIEW timestamps, it is best to do any arithmetic on it in this base unit.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Differnce between byte[] reading and int[] reading

    While reading information from file using fileInputStream ....
    Is there any differnce between byte[] reading and int[] reading ?

    Well, in as much as you can do the former and not the latter.
    FileInputStream just reads blocks of bytes. If you want to read more sophisticated element you need to wrap in in a DataInputStream or a Reader.

  • EJB QL 2.1 and oracle empty string values

    Hello,
    I�ve written a simple finder with ejb ql. One arg is a string which can be empty. My problem is, that oracle treats empty strings as null and so it seems to be impossible to write one general query for it:
    select object(a) from example a where a.test1 = ''
    returns nothingselect object(a) from example a where a.test1 is null
    the row where test1 is nullDoes anyone know a solutions for this issue? I think the ejb ql is not really portable in this way?
    Greetings,
    Thilko

    To me, it looks like any class that has a comparator should work:
    Sec 11.2.6.7 of the 2.1 draft has as syntax for BETWEEN:
    "arithmetic_expression [NOT] BETWEEN arithmetic-expression AND arithmetic-expression"
    Sec. 11.2.6.6 of the 2.1 draft says:
    "Arithmetic expressions can be used in comparison expressions. Arithmetic expressions are composed of other arithmetic expressions, arithmetic operations, path expressions that evaluate to numeric values,
    and numeric literals."
    However, since 2.1 is still in draft the "implementations" may or may not fully support it. You should mention what product you're using when you post here (e.g. RI, Weblogic, Websphere, etc.)

  • POSTING TO JSP FORMS GIVES NULL OBJECT RATHER THAN EMPTY STRING

    This post is for Dan Norris of DOE. He brought this up in a submitted tar, but it is addressed by the PDK community here.
    We arehaving problems using the standard HTTPServletRequest getParameter
    methodinside of the portal.
    The standard for this method is as follows:
    *If you usethis method to read from a text field without any text in it, you
    get an empty string. ( "" )
    *If you use it to read from a text field with text in it youwould get the
    corresponding text.
    *If you try to read from a field that doesn'texist then and only then would
    you get a Null object.
    On our portal server itis behaving differently inside of portlets.
    * If you use this method to readfrom a text field without any text in it, you
    get a Null Object
    * If you use itto read from a text field with text in it you would get the
    correspondingtext.
    * If you try to read from a field that doesn't exist you also would youget a
    Null object.
    Also, on the same server If you access a simple JSP directlywithout the it
    being a portlet, it behaves as defined by standard Javadocumentation.
    Test case:
    Create test.jsp with these contents:
    ========start test.jsp
    <%@pageimport = "oracle.portal.provider.v1.*,
    oracle.portal.provider.v1.http.*"%>
    Form to test submission of empty form field.<br>
    Text Field Value ="<%=request.getParameter("testField")%>"
    <form name="test" action="<%=
    HttpPortletRendererUtil.htmlFormActionLink(request,PortletRendererUtil.PAGE_LINK
    ) %>">
    <%=
    HttpPortletRendererUtil.htmlFormHiddenFields(request,PortletRendererUtil.PAGE_LI
    NK) %>
    <INPUT type="text" name="testField">
    <INPUT type="Submit"name="Submit">
    </form>
    ========end test.jsp
    =================startprovider.xml
    <provider class="oracle.portal.provider.v1.http.DefaultProvider"
    session="true">
    <portlet class="oracle.portal.provider.v1.http.DefaultPortlet" version="1" >
    <id>1</id>
    <name>TestPortlet</name>
    <title>Test</title>
    <description>Test</description>
    <timeout>100</timeout>
    <timeoutMsg>Test Portlet timed out.</timeoutMsg>
    <showEdit>false</showEdit>
    <showEditDefault>false</showEditDefault>
    <showPreview>false</showPreview>
    <showDetails>false</showDetails>
    <hasHelp>false</hasHelp>
    <hasAbout>false</hasAbout>
    <acceptContentTypes>
    <item>text/html</item>
    </acceptContentTypes>
    <portletRenderer class="oracle.portal.provider.v1.http.PageRenderer" >
    <appPath>/</appPath>
    <appRoot>/u01/app/oracle/product/ias1021/Apache/Apache/htdocs</appRoot>
    <renderContainer>false</renderContainer>
    <showPage>test.jsp</showPage>
    <pageParameterName>next_page</pageParameterName >
    </portletRenderer>
    </portlet>
    </provider>
    =================end provider.xml
    After you have theprovider added to the portal, login to the portal as
    portal30 and go toAdminister Tab->Display Portlet Repository and display the
    portlet.
    1.Enter "test" in the text field and submit.
    2. Returns Text Field Value ="test"
    3. Submit form leaving the text field empty.
    4. Returns Text FieldValue = "null"
    Submitting the form with the text field empty should returnvalue of "", and
    not "null".

    fyi in case anyone else ever wants to know:
    I found it... the details I was looking for were in the OC4J 9.0.2 Release Notes:
    Display of null values in JSP.
    In Oracle9iAS, a null value printed from a JSP page displays, by default, as
    the string "null." To display nothing instead, set the attribute jsp-print-null
    to false in the <web-app> element of
    global-web-app.xml or orion-web.xml.

  • Difference between str="Hai"; and str = new String("Hai");

    HI,
    String szFirst = "Hello World":
    String szSecond = new String("Hello World");What is the difference between the two types of string initialization?

    RajivGuna wrote:
    HI,
    String szFirst = "Hello World":
    String szSecond = new String("Hello World");What is the difference between the two types of string initialization?What do you think the difference is?

  • OSB to Object Types: difference between NULL value and not available

    Hello all,
    I have a question about Object Types. More specifically, how to differentiate between an empty value (null) and a string not available.
    This is my case:
    I have created an object type with three parameters.
    CREATE OR REPLACE TYPE OSB_EMP_OBJ_TYPE AS OBJECT
    (EMP_ID NUMBER
    ,DEPT_ID NUMBER
    ,ORDER_ID NUMBER
    ,CONSTRUCTOR FUNCTION OSB_EMP_OBJ_TYPE
    RETURN self as result
    /I would like to see what happens when I put an empty string into emp_id, NULL into DEPT_ID and nothing into ORDER_ID.
    To do so I have this test script:
    declare
      p_emp OSB_EMP_OBJ_TYPE := OSB_EMP_OBJ_TYPE();
    begin
      p_emp.EMP_ID := '';
      p_emp.DEPT_ID := null;
    --  p_emp.ORDER_ID := null;
      if p_emp.EMP_ID is null
      then
        dbms_output.put_line('Empty');
      end if;
      if p_emp.DEPT_ID is null
      then
        dbms_output.put_line('NULL');
      end if;
      if p_emp.ORDER_ID is null
      then
        dbms_output.put_line('Not available');
      end if;
    end;The result of this is:
    Empty
    NULL
    Not availableIt seems that Oracle treats all three situations alike. What I would like to achieve is a way to see that p_emp.ORDER_ID was not initialized.
    To elaborate a bit: in our production system this procedure would be called from OSB and the object type would by the input for that procedure. Our database version is 10.2.0.5.0.
    Our procedures look something like this:
    procedure p_procedure ( p_emp in osb_emp_obj_type )
    is
    begin
      do_something;
    end;Can anyone tell me if there is a way to achieve this, so I can see whether or not a value in the object type was filled?
    Thanks in advance!

    Darn...
    Eventually we want to use this for an update procedure. The client gets all current data from the database by calling a webservice that (using OSB) selects the data from our database. What we want to achieve is that the client can update that data, by returning only the changed fields to an update procedure.
    We then handle an empty tag to update the field to null, and we ignore missing tags.
    OSB itself can handle this, but PL/SQL can't.
    I'm now thinking of adding an indicator to each optional field (clear_field_yn). OSB can still check for empty tags or missing tags. When a tag is empty, it's corresponding indicator will be set to 'Y'. If the tag is missing, then it will be set to 'N'.
    Is that a solution to consider, or is there a much simpler approach possible?

Maybe you are looking for

  • Safari wont open it always crashes with error report

    Everytime i open safari i get this report and i dont know what to do ? Safari quit unexpecectadly while using the librooksbas.dylib plug in i dont know what this plug in is ? can you help as it wont open at all.

  • Ipod color will not show up as a ipod color

    I just upgraded from a 3g 15 to a 4g 60gb color. i can connect to OSX most of the time, and i can get my music on there (with out pics). problem is that my itunes on my powerbook does not show anything in the options about photos. i opened itunes in

  • Problem in alv fieldcat function

    data: begin of it_mara occurs 100,          matnr LIKE mara-matnr,          ernam LIKE mara-ernam,          ersda LIKE mara-ersda,          mtart LIKE mara-mtart,        end of it_mara. i am using the above mentioned int tab. the following function i

  • Smartform batch rpint with Front andf Back page ??

    Hi Experts, My scenario is that i have a program that prints a document within a loop, making use of FM 'SSF_FUNCTION_MODULE_NAME' to call a smartform that ive designed.  Once the name is returned i use FM 'gv_func_mod_name' and parameters:     contr

  • Reverse Telecine Question

    I'm testing "Cinema Tools Reverse Telecine" from the FCP Tools menu with NTSC DV media and related 35mm Telecine Logs (flxs). The resulting 24fps QTs show proper KeyCode info in overlays and original lab burn-ins but Video TC looses sync between over