Difference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bagmita
    New Member
    • Jan 2007
    • 8

    #1

    Difference

    What is the difference between object and object reference?And what do the the following two statements signify?
    Statement1::

    String s="Bagmita";

    Statement2::

    String s=new String("Bagmita ");
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bagmita
    What is the difference between object and object reference?And what do the the following two statements signify?
    Statement1::

    String s="Bagmita";

    Statement2::

    String s=new String("Bagmita ");
    The difference between these two statements can be infered from this thread.
    In the first statement s holds a string literal value. s refers to literal "Bagmita".

    In the second statement, s holds a reference to an object that has just been created in memory.

    String s1="Bagmita";
    String s2=new String("Bagmita ");

    s1 == s2 compares the memory addresses (object references) and so returns false. But s1.equals(s2) compares what these 2 are refering to (references) and so returns true.

    Comment

    • bagmita
      New Member
      • Jan 2007
      • 8

      #3
      Originally posted by r035198x
      The difference between these two statements can be infered from this thread.
      In the first statement s holds a string literal value. s refers to literal "Bagmita".

      In the second statement, s holds a reference to an object that has just been created in memory.

      String s1="Bagmita";
      String s2=new String("Bagmita ");

      s1 == s2 compares the memory addresses (object references) and so returns false. But s1.equals(s2) compares what these 2 are refering to (references) and so returns true.
      thank you.i am preparing for java certification,c an you please suggest me certain good websites for mock tests?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bagmita
        thank you.i am preparing for java certification,c an you please suggest me certain good websites for mock tests?
        I suggest you try mock tests after you've had a thorough revision of the main concepts of Java. The Java classes on this site specify some of the things you'll need to know to pass that test. When are you planning on taking the test?

        Comment

        • bagmita
          New Member
          • Jan 2007
          • 8

          #5
          I am going to take the test by the end of this month..I have tried out many mock tests from various sites but my score is not so satisfactory especially in collections and garbage collection ..also threads

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by bagmita
            I am going to take the test by the end of this month..I have tried out many mock tests from various sites but my score is not so satisfactory especially in collections and garbage collection ..also threads
            Feel free to post any questions you are not comfortable with including your suggested solutions.

            Comment

            • bagmita
              New Member
              • Jan 2007
              • 8

              #7
              int[][] makeArray( int size)
              { int[][] triArray = new int[size] [];
              int val=1;
              for( int i = 0; i < triArray.length ; i++ )
              { triArray[i] = new int[i+1];
              for( int j=0; j < triArray[i].length; j++ )
              { triArray[i][j] = val++;
              }
              }
              return triArray;
              }

              Can you please explain the flow transfer of this program and what its output will be?

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by bagmita
                int[][] makeArray( int size)
                { int[][] triArray = new int[size] [];
                int val=1;
                for( int i = 0; i < triArray.length ; i++ )
                { triArray[i] = new int[i+1];
                for( int j=0; j < triArray[i].length; j++ )
                { triArray[i][j] = val++;
                }
                }
                return triArray;
                }

                Can you please explain the flow transfer of this program and what its output will be?
                Like I said post your suggested solution first.

                Comment

                Working...