Search for 'foo' in all the java files under 'dir1', 'dir2' and 'dir3' directory tree and print only the names of the matched files
find dir1 dir2 dir3 -type f -name "*.java" -exec grep -il 'foo' {} \;