This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!

Manish Nijhawan

Greenhorn
+ Follow
since Apr 04, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Manish Nijhawan

Hi Pardeep,
As you have explained that at the commented line since all the objects have the references so they are not eligible for the GC. But since that line is the last line of the method , so after that line all the references to all the objects will vanish , so all the Live objects should be eligible for GC.

Please explain me this as i am very much confused about GC.
Hi,

int [] a1;
the above statement means that a1 is of type int[].

int[] a1 , a2;
The above statement means that a1 and a2 both are of type int[].

so int[] becomes the type and a1 and a2 becomes variables.

if we write int[] a1[];
this means a1 is an array of type int[](which itself is an array) therefore a1 is of type int[][] i.e. a 2-d array.

but if we write int[] a1 , []a2;
here a1 is the name of the variable but []a2 cannot be resolved as the compiler expects a variable name and [] are not allowed in the name of the variable.
Hi,

If the Left Hand Side of the assignment operator is byte , char or short and the right hand side of the assignment operator can be resolved at compile time itself then the implicit narrowing conversion is applied by the compiler.
consider the following examples

byte b;
int ten = 10;
final int TEN = 10;
b = 10; // No compliation error as 10 is a constant and can be resolved at compile time

b = TEN; // No Compilation error as TEN is a final variable and can be resolved at complie time

b = ten; // Compilation error as ten is a variable which cannot be resolved at compliettime. ten can have any value which might not fit into byte.

b = 10 + TEN ; // No compilation error as 10 and TEN both can be resolved at compiletime.
i am sorry for the mistake the example which i have given should be
Consider this
String s1 = new String("Hello");
String s2 = new String("Hello");
String s3 = s2;

then s1 == s2 returns false ( s1 and s2 refer different String onject )
s1 = s3 returns false
s2 = s3 returns true as both of them points to the same string object (s2 and s3 are aliases )
when we write the following statement where A and B are not of primitive data types
A == B

then if A and B points to the same object then it will return true else it will return false. i.e. == operator does not comapre the values of the objects rather they check the reference values of A and B. if A and B are alias of each other only then == operator will return true.

Consider this
String s1 = new String("Hello");
String s2 = new String("Hello");
String s3 = s1;

then s1 == s2 returns false ( s1 and s2 refer different String onject )
s1 = s3 returns false
s2 = s3 returns true as both of them points to the same string object (s2 and s3 are aliases )
in case of i = i++;

i = ( return i and increment the value of i by 1)

initially i is 0 , the value to be returned is determined to be 0. then the value of i is incremented by 1 so i become 1 now the return happens which return the value 0.

the return happens after the value of i is incremented.

the defination of i++ is :- the current value of i is to be taken for evaluating the expression and after using its current value increment it by 1

the value of i is incremented before the returns happens

consider the following example
int i = 0 , j ;
j = i++ + i++;
the answer will be j = 1 and i = 2 and not j = 0 , this is because after using the value of i , it is incremented immediately so that the new value can be used in the next increment. after the whole expression is evaluated and the increment being done , then the value of the expression is returned to the left hand side variable.

I hope that i have made myself clear.
Hi Amitkumar,

when u write i = i++; what is happening is as follow

i = i++;
i = (return i and the value if i will be incremented to 1 )
since the value returned is 0 thus 0 is assigned to i again. ( The incremented value of i is overwritten with the new value (0) )

but in case of j = i++;
j = (return i and the value of i is incremented to 1 )
the value of j will be that of i before increment i.e. 0 and the value of i will increment to 1 ( In this case the value of i is not overwritten but assigned to j)

I hope u got it.
Thanks a lot vidya. I have understood the concept.

Its that the return statement in the try block will be evaluated but before returning the value it will execute the finally block and inside the finally block when it encounters the return statement it will return that value.
It means that if there is a return statement in the try block as well as in the finally block then the try block return statement will not get executed.

am i correct ??

But if it is so then why the o/p of following comes out to be 11 instead of 10 ??



public class F {
public int testMethod()
{
int i = 10;
try
{
return ++i;
}
finally
{
return i;
}
}
public static void main(String[] args) {
System.out.println(new F().testMethod()); }
}
Can any one tell me that when is the finally block exceuted ??
Also what will be the o/p of the following code.

public int testMethod()
{
try
{
....
....
return 10;
}
catch(Exception ex)
{
....
....
}
finally
{
return 20;
}
}

will the value returned by this method is 10 or 20 ???