File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes = Operator 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 "= Operator" Watch "= Operator" New topic
Author

= Operator

Thillakan Saba
Ranch Hand

Joined: May 15, 2007
Posts: 53
Can you please any one explain following code segment ?



SCBCD, SCJP & MCP
HowToAskQuestions
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

there are two copies of the same code......

well the if(flag = true) has a gotcha....there is = and not ==. So it is an assignment not comparison. This will make the condition true.

flag = false;
if(flag = true)//it will result in flag becoming true and condition becoming true too..


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Thillakan Saba
Ranch Hand

Joined: May 15, 2007
Posts: 53
Oopps!! Thanks,
boolean values can be used with in if block with = operator.
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
in java = is different of the == in the exam there are serveral questions so.


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Originally posted by Sabanayakam Thillakan:
Oopps!! Thanks,
boolean values can be used with in if block with = operator.


This is a similar problem as = with ints in C and C++.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: = Operator