Dharmesh Gangani

Ranch Hand
+ Follow
since Feb 20, 2004
Merit badge: grant badges
For More
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 Dharmesh Gangani

I am very much confused about the Parsers. Which parsing method (DOM or SAX) is best suited and recommended..

Please help..
Thanks Warren,

I got the difference.

Thanks again.
I m not exactly aware about C & C++.
Hi,

The key here is to understand how the post-increment operator works as well as the order in which expressions are evaluated.

The post-increment operator works in this way -
1. return the current value of i (= 0)
2. increment the current value and store it in variable i. (i = 1)

Now, the value returned by the post-increment operation (i.e. 0) is assigned to the LHS variable i, overwriting the previously written value 1.

Thus, i = i++; leaves i = 0;

Hope, this has cleared ur doubt.
Consider the following lines of code -



This program compiles and runs properly.

Now, consider another version of getNumber() method -


The code now gives a compilation error.

I read the following lines about Assignment conversions -
You can automatically assign a value to a variable, even if that assignment would require a narrowing conversion, as long as the value is known at compile time (a literal value, or a final variable) and that value "fits" into the target type.

In this case, i have declared a final int variable and still it is giving a compile-time error in the second version of getNumber().
Can anyone explain this..
This code will throw one more compilation error for the line

System.out.println(i);


This is because, this print statement is after a while(true) loop and this loop does not break (since break statement is not reachable by the compiler).
<quote>
class Level1Exception extends Exception{}

class Level2Exception extends Level1Exception{}

class Level3Exception extends Level2Exception{}

class Purple
{
public static void main(String args[])
{
int a, b, c, d, f, g, x;
a = b = c = d = f = g = 0;
x = 1;
try
{
throw new Level1Exception();
try
{
switch (x)
{
case 1:
throw new Level1Exception();
case 2:
throw new Level2Exception();
case 3:
throw new Level3Exception();
}
a++;
}
catch (Level2Exception e)
{
b++;
}
finally
{
c++;
}
}
catch (Level1Exception e)
{
d++;
}
catch (Exception e)
{
f++;
}
finally
{
g++;
}
System.out.print(a + "," + b + "," + c + "," + d + "," + f + "," + g);
}
}
</quote>


Hi Nikhil,
The problem is in the first line of the first try block "throw new Level1Exception();"

After You throw an exception in a code, the statements after the throws stmt will become unreachable by the compiler and hence, it fill flag an compile-time error.

-Dharmesh G.
Hi All,

I did this samll exercise. I had written a small code in java to put messages in the queue. The code had a loop which would insert messages repeatedly onto the queue. I found that some messages were properly put on the queue but, it gave a SocketException afterwards and no further messages were put onto the queue.

So, i want to know, is there some MAX limit for the queue which allows only a fixed maximum number of messages to be put on the queue? OR is it a MAX Size limitation for the messages that can be put on the queue?

Please help.

Thanks,
Dharmesh
17 years ago

The '+=' operator creates a new String object where the .concat(String) and .toUpperCase() methods do not.



The '+=' operator and the '.concat()' works the same way. A new string is created as a result of both the operations. For this example, In case of s+="here", a new string is created after combining the 2 strings s & "here" and then this string is assigned to s.

For s.concat(s1), a new string is created after combining the contents of the 2 strings s & s1 but since it is not addigned to any object, this new string is lost.

If the statement had been s = s.concat(s1); then string s would hold contents of the new string created as a result of the .concat()

Hope this clarifies things.
Hi,

I agree with Lyn Yang. The answer could very well be 10 as " " is present in the System.out.println() statement. This string will be created in the heap as there is no such string in the heap at that point.

How come the device instance variable got initiated in the superclass?



This is because the device instance variable in the superclass in declared static.

- Dharmesh G.
//line2
Object o = s2;

The line means Object o will point to the same reference to which s2 is pointing. So (s2 == o) will return since both the objects are pointing to the same reference.
Hi,

I am also preparing for SCJP 1.4.

Priya, can u tell me which is the K&B book. I mean the complete name & Author(s).

Thanks,
- Dharmesh
I am still not able to understand it completely. can anyone explain that in a little more detail ?

Thanks in advance.
- Dharmesh