Vinod Venkatasubramanian

Greenhorn
+ Follow
since Oct 19, 2003
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 Vinod Venkatasubramanian

If efficieny is not an issue, you could try using ArrayList to dynamically grow the array.
Basically, traverse the input array and for every element you want inserted into the destination array, use ArrayList.add.
18 years ago
Hi Ann,
Am slightly confused on what actually you want to do.
(1) How are the messages avbl on the queue ? As strings or as characters ?
(2) How do you want to format the message exactly ? Do you want to a read a string off the queue and the delimit it in a particular fashion ?
If you want to retrieve string messages off the queue and then format them, the first step would be to separate the reading of queue and formatting -> this makes it much simpler to code.
If you can give some details, I will see if I can be of any help.
18 years ago
If in case you have already defined main(), then consider adding current directory (".") to the classpath. For eg: your classpath will look like,
CLASSPATH=.;C;\jdk.......
If you send out the code you wrote it will help.
[ October 22, 2003: Message edited by: Vinod Venkatasubramanian ]
18 years ago
Use java.io.FileOutputStream.
It has a constructor with the signature
FileOutputStream(File file, boolean append) !
guess you can do the rest.
18 years ago
The book on Design Patterns by the Gang of 4 discusses this pattern.
One nice real-world example in Windows is the "Run" dialog box (Start->Run)... how many ever times you click on 'Run', the same dialog box is returned, ie, the handle to the same window.
18 years ago
Apart from the book, it might be worthwhile to look at some articles at javaworld.com

Originally posted by Vidya Sethuraman:
Thanks..I understood why its print 10 and 0 but i still didnt get how 20 i printed.
Also, Can you tell me some gud mock tests that i should try.


Am not sure about mock tests... but about the 20 -
We have to understand that there are two v's - The object 'v' in 'another' is a totally different 'v' from the one in amethod. See the commented code segment below - i have renamed the 'v' in another to v2 for clarity:
public void amethod() {
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
// now v has i=20 in it
System.out.print( v.i );
}//End of amethod
public void another(ValHold v2, int i){
i=0;
// v2 is passed the reference of v - so it points to v
// the v of amethod gets modified to 20 (thats why the o/p is 20)
v2.i = 20;

// new object called vh
ValHold vh = new ValHold();

// v2 now points to vh, not to v of amethod
v2 = vh;

// v2.i means vh.i so o/p is 10
System.out.print(v2.i);
// i is the argument i which is 0
System.out.print(i);
}//End of another
First of all let me say that this was very interesting.. for a moment I was confused...
But the answer is 10020 bcoz the 'v' within 'another' method is different from the 'v' in 'amethod'.
Replace the 'v' in 'another' method with 'v2' or something and step through the statements, it will be clear.
Its great to see how our eyes and brain play tricks - we see both v's and assume they are the same !!
[ October 21, 2003: Message edited by: Vinod Venkatasubramanian ]
The way floats are stored internally (in the form of exponents) gives it a larger range and hence makes it safe to cast a long to a float.
Long to int of course might lead to possible loss of info.
Here's what the Java Language Specification says about the for loop:
"
The for statement executes some initialization code, then executes an Expression, a Statement, and some update code repeatedly until the value of the Expression is false.
ForStatement:
for ( ForInit ; Expression ; ForUpdate )
Statement
ForStatementNoShortIf:
for ( ForInitopt ; Expressionopt ; ForUpdateopt )
StatementNoShortIf
ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression
The Expression must have type boolean, or a compile-time error occurs.
"
So the only real constraint is that the "Expression" part must return a boolean while the "ForInit" and "ForUpdate" can be valid Java statement(s) separated by commas... IN fact even the following works though you would not want to use it :-)
for (; ;) {
System.out.println("Never ending....");
}
[ October 20, 2003: Message edited by: Vinod Venkatasubramanian ]
Thanks everyone for pitching in !!!
Wayne, what you said seems to make sense... I was suspecting something similar (as in my second post) but could not put it in proper words.
I went throught the JLS and now its much clearer...
Coming from a C++ background (where both scenarios would work), guess I was expecting something else.
If you wonder WHY they made the specification like this, it might have to do with the fact that in Java, objects are not DESTROYED once they are out-of-scope.. they are only garbage collected. Whereas in C++, the 's' in the inner scope is destroyed once it has no meaning (ie, once that scope is exited)
Thanks again ! Appreciate your contributions a lot.
18 years ago
Iam not sure. As far as the compiler is concerned, there are only 2 scopes - the outer and inner one - I dont think there is a line-by-line parse which makes one scenario work and not the other.
A similar piece on C++ would work fine, wherever we put the definition in the outer scope. But in C++ you also have the scope resoultion operator (: to decide which one to refer to... not so in Java.
Putting what you said in other words - in the 2nd scenario, when the 's' is redefined in the inner scope, the one in the outer scope is still "in-scope". But this is not the case in the 1st scenario - by the time we reach the 's' in the outer scope, the one in the inner scope is already "out-of-scope". This seems to make sense...
Lets see if someone has any other view on it.
Thanks anyway !
[ October 19, 2003: Message edited by: Vinod Venkatasubramanian ]
18 years ago
I am curious as to why one of the following works while the other does not:
The following compiles fine:

Note that 's' and 'x' have be redefined in the outer scope.
The following throws a compile-time error ("s is already defined in main(java.lang.String[])"):

Can anyone explain why ?
[ edited to add and preserve formatting using the [code] and [/code] UBB tags -ds ]
[ October 20, 2003: Message edited by: Dirk Schreckmann ]
18 years ago