A colleague of mine would like to compare 25+ different Java implementations of the same homework. Is it OK (ethically/legally in the US) to share my students' class homework solutions with him for his research purposes?
You need to run this by your Institutional Review Board (IRB), as you would any time you use data from human subjects for research.
From what you describe, it has a good chance of qualifying for an IRB exemption under one of these categories (if identifying information is removed before giving the data to the researcher):
but even then, the IRB needs to be the one to make that determination.
Franck doesn't say where he is. What ff524 says is true in the US. Any research with human subjects must be approved by an appropriate review process beforehand.
One horror story (allegedly true) goes like this. A graduate student in music history spent her summer touring through Appalachia, convincing people to let her record them singing traditional songs. But that research had to be thrown out, because of the advance approval process she hadn't known was required.