Anshul Manisha

Ranch Hand
+ Follow
since Apr 17, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Anshul Manisha

For your first question the else corresponds to the second if statement. Since first condition is not met(closed is supplied in place of open) hence no if loop is entered.
For your second question
Here is the sequence
i = 1
enter do loop
i = 2
execute while(b=!b)
no b=!b will result in true because b is false hence !b is true
enter do loop again
i = 3
execute while(b=!b)
this time b=!b results in false hence no more execution of do...while take place.
[This message has been edited by Anshul Manisha (edited July 24, 2001).]
Hi,
Only the class members can be used without initialization. Here your variable tmp is initialized before it is used in the println statement(inside the if...else block) comment out the else block and compiler will complain.
Any variable defined within the scope of method has to be initialized before it is used.
regards

Originally posted by Bhaskar Selvaraju:
In java String is treatd as an object and not as a primitive data type. Only primitve data types need to be initialized before they can be used inside a method. Hope it is clear to you.
Bhaskar


Hi
check this out Collections chapter from Core Java 2
as I understand, if you create a string with new then a new instance is entered in the string pool even if that literal exists earlier.
Jane
I have a query here.
when we say
String st = new String("hello")
aren't we creating two objects ? One String object on the heap and an instance of literal in String pool?
Thanks much
Hi,
This is because the println method in Printstream is overloaded to accept char[] as argument. So when you call
System.out.println(c)
toString() method of object is not invoked to provide you with hashcode value. println is not overloaded for int[] hence you get hashcode. In
System.out.println("char is " + c)
toString method of Object is called and you get the hashcode value
What is your point Lashkar???

Originally posted by Detlev Beutner:
A1.
That is somehow logical, because the "real" abs-value would be 2147483648, but Integer.MIN_VALUE is 2147483647 (think about zero!).


Hi Integer.MIN_VALUE is -2147483648 Integer.MAX_VALUE is 2147483647. Now I don't know why this is so but maybe it is because if you convert 2147483648 to binary you get
1000 0000 0000 0000 0000 0000 0000 0000
which in signed form is equal to -2147483648
Now folks I don't claim it to be the right answer it is just a speculation, so don't hold me to it
Here is description of trim() method for String class in Java API


If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.


Hence trim is doing nothing but returning reference to current String object. In replace() since two new String objects are created they are not equal.
Java ternary operator(conditional operator) has higher precedence than assignment operator so x?1:2 is evaluated first and then the value is assigned to a

you'll get:
sb1 ---> "hello there" <--- s1 = s2<br /> sb2 ---> "hello"
[/B]
</BLOCKQUOTE>

Java passes by reference so while calling method bufTest references of sb1 and sb2 are passed. Now these references are immutable i.e. you cannot pass back a changed reference to the calling block. If you make any changes to reference inside your called method then the change is done in the copy local to called method. However you can modify the properties of the object referenced. So if you append to sb1(you are modifying the property) it will be reflected in the calling block(prints "hello there" second time) but if you change the reference then the calling block will retain reference to original object(sb2 prints "hello" in main)
Hope that this helps.

[This message has been edited by Anshul Manisha (edited July 15, 2001).]
Here is what Java API says about the replace method of String class


Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.

Here is what JLS has to say about it
Sect 14.3


A local class is a nested class (�8) that is not a member of any class and that has a name. All local classes are inner classes (�8.1.2). Every local class declaration statement is immediately contained by a block.
and
It is a compile-time error if a local class declaration contains any one of the following access modifiers: public, protected, private, or static.