First of all, make sure you're using regular ascii quotes like
' (ascii codes
0x27, respectively) in shell scripts, because the example in your post contains non-standard quote characters. If you look closely, they look a bit different. Most probably this is a copy-paste error from a rich text document format like Word, OOWriter, or even a browser window.
Since you're on a Mac, you most probably have the BSD implementation of
sed, in which case you have to write the command this way:
find . -name "*.java" -exec sed -i '' s/foo/bar/g \;
In the BSD implementation of
-i flag needs an argument: the extension of a backup file. For example with
-i .bak the command would backup
file1.txt.bak first before performing the replacement in the original file. Using an empty argument
'' means to not use a backup file, which seems to be what you want.
The same thing in the GNU implementation would be:
find . -name "*.java" -exec sed -i s/foo/bar/g \;
Thank you @bahamat and @Mikel for improving my answer with your comments.