aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IS this question good? why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IS this question good? why" Watch "IS this question good? why" New topic
Author

IS this question good? why

huanyu zhao
Greenhorn

Joined: Feb 22, 2001
Posts: 29
what is the value of j at line 17?
[ June 26, 2002: Message edited by: huanyu zhao ]

[img]http://www.flyheart.com/bbs/attach/2002/11/07/59790-signature-embed.jpg[/img]
Chung Huang
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
Originally posted by huanyu zhao:


Correct me if I am wrong, wouldn't this thing produce a compiler error at the line that says

since i>10 gives me boolean value which & don't take? Or is it a runtime error since express are evaluated during runtime...either way I thought & is a bitwise operator that only take integer, while boolean is never evaluated as integers.


Let us be showered in the light of confusion!
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]
Chung Huang
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
Never mind, forgot about that short-circut nature
wouldn't j be 2? the call send over 2, and the line says j += k where j is 0 and k is the value send over which is 2.
[ June 26, 2002: Message edited by: Chung Huang ]
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
& can take both boolean and integral operands.
&& can be applied to boolean expressions only.
Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
To geetha
I thought the & operand is not short cutted!
only && is short-cutted. I thought the second operand always gets evaluated even if the first operand evaluates to false. but if you use && then if the result can be determined, then the second operand doesn't get evluated?
correct me please.


Amir
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
To Amir,
Yes, && is short-circuited and not &.
Both operands r evaluated in case of &.
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
good question huanyu, just one detail:

we always have to be aware of these little errors.
Francisco


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
huanyu zhao
Greenhorn

Joined: Feb 22, 2001
Posts: 29
Originally posted by geetha nagarajan:
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]

oh good! thank you!
Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
The code in your very first post does not the main() properly defined is that a typo???
Coz if it is not the prograom will fail to run right??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IS this question good? why