Haibo Jia

Greenhorn
+ Follow
since Aug 22, 2007
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 Haibo Jia

Hi,

The answer K&R book provided also make me confused. I make following test code

All the right anwser he gives can't be compiled. Anyone can give an explanation? Thanks.
Hi Alexsandra,

The two replace methods will create two objects refered by 2 ref, so compansion of ref result in false. Thax.
Answer should be "Not Equal".

if("String".replace('g','G') == "String".replace('g','G'))



The code above compare two reference to the different String object. Pls remember String is immutable Class, So "String".replace('g','G') will result in creating reference to a new String object with value of "StringG". Two times excution will create two different reference, so the result of comparison is the false. Hope explanation makes sense.
Hi Ranchers,
From my understanding "Programmatically Thrown Exceptions" must be declared or catched, but why does the code as following can be compiled:

1. class B {
2. public static void main (String[] arg)
3. {
4. Integer i=Integer.valueOf("123");
5. }
6. }

In the class "Integer", the method "valueOf" is declared as ---
public static Integer valueOf(String s)throws NumberFormatException.

why, in the caller code, can it be complied without exception thrown or captured ? Thanks.