• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about fundamentals  RSS feed

 
John Godfrey
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been messing around with Java to create an application to compare MD5 checksums. It reads in each checksum/file name line by line as a String object, and compares the two relevant lines using the compareTo() method of the String class.

The logic I'm using uses a Boolean called sumsMatch, which I initialise as true, and set to false if the program encounters any checksums that aren't identical.

My question is this: is this bad practice? I'm thinking that it could lead to false positives, although I haven't come across any in my testing.

Would it be better to initialise sumsMatch as false instead, and make the rest of the program more complicated?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to calculate the AND over a number of boolean values - true if all values are true, and false if at least one value is false. By definition, the AND over no values at all is true, since true AND x is x for all boolean values. That should be your initial value.

For an OR it's vice versa - false if all values are false, and true if at least one value is true. The OR over no values at all is false, since false OR x is x for all boolean values.
 
John Godfrey
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!