By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

Difference

P: 8
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");
Jan 10 '07 #1
Share this Question
Share on Google+
7 Replies


10K+
P: 13,264
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.
Jan 10 '07 #2

P: 8
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,can you please suggest me certain good websites for mock tests?
Jan 11 '07 #3

10K+
P: 13,264
thank you.i am preparing for java certification,can 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?
Jan 11 '07 #4

P: 8
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
Jan 11 '07 #5

10K+
P: 13,264
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.
Jan 11 '07 #6

P: 8
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?
Jan 11 '07 #7

10K+
P: 13,264
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.
Jan 11 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.