質問

I recently accidentally submitted my .class file instead of the .java file for an assignment.

After feedback from the grader, I submitted my .java file. Everything worked out fine from there, the grader trusted that it was an honest mistake.

However, is there a simple way for the grader to check to see if the two files really match up?

So far, I've only thought of two solutions:

  1. Compile the .java, and see if the .class outputted is identical/very similar. This is probably very compiler dependant. If the compilers were the same, are there other variables that would make the .class different?

  2. Decompile the .class file, and do a character comparison. This seems like a lot more work, and probably match the .java file even less than solution 1.

Is there a reliable way to check this?

役に立ちましたか?

解決

If you compile with the exact same compiler in the exact same enviornment, it is highly likely that you will get identical class files.

However, if there are variations in compiler or platform, you should look at this discussion.

Outside of that, you will probably have to evaluate it functionally. That is, write a test class that exercises all desired behaviors of each class and check whether they all return identical results.

他のヒント

I did a very simple test and it worked for me..

I compiled a simple java program and created its .class file Then I just change one letter inside System.out.println and again crated a .class file

Then used diff command in linux and it tells me that two binary files are different

So I think instead of decompiling the .class file and then checking both .java files you can directly check for two .class files

At least it worked for me.

Hope this helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top