Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (3.4k points)

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.

1 Answer

0 votes
by (46k points)
Line numbers are stored for debugging, so if you modify your source code the way you did, your method starts at a distinct line and the compiled class reflects the variety.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...