Why does a Java class compile differently with a blank line?

I have the following Java class

public class HelloWorld {
  public static void main(String []args) {
  }
}

When I compile this file and run a sha256 on the resulting class file I get

9c8d09e27ea78319ddb85fcf4f8085aa7762b0ab36dc5ba5fd000dccb63960ff  HelloWorld.class

Next I modified the class and added a blank line like this:

public class HelloWorld {

  public static void main(String []args) {
  }
}

Again I ran a sha256 on the output expecting to get the same result but instead I got

11f7ad3ad03eb9e0bb7bfa3b97bbe0f17d31194d8d92cc683cfbd7852e2d189f  HelloWorld.class

I have read on this TutorialsPoint article that:

A line containing only white space, possibly with a comment, is known as a blank line, and Java totally ignores it.

So my question is, since Java ignores blank lines why is the compiled bytecode different for both programs?

Namely the difference in that in HelloWorld.class a 0x03 byte is replaced by a 0x04 byte.

4 Answers
4

Leave a Comment