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

Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
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 byte code different for both programs?
Namely the difference in the classes is that an end-of-transmission (^D) character is replaced with a end-of-text character (^C)
java compilation bytecode java-10
add a comment |Â
up vote
7
down vote
favorite
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 byte code different for both programs?
Namely the difference in the classes is that an end-of-transmission (^D) character is replaced with a end-of-text character (^C)
java compilation bytecode java-10
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
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 byte code different for both programs?
Namely the difference in the classes is that an end-of-transmission (^D) character is replaced with a end-of-text character (^C)
java compilation bytecode java-10
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 byte code different for both programs?
Namely the difference in the classes is that an end-of-transmission (^D) character is replaced with a end-of-text character (^C)
java compilation bytecode java-10
java compilation bytecode java-10
asked 2 hours ago
KNejad
11319
11319
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
Basically, line numbers are kept for debugging, so if you change your source code the way you did, your method starts at a different line and the compiled class reflects the difference.
add a comment |Â
up vote
1
down vote
You can see the change by using javap -v which will output verbose information. Like other already mentioned the difference will be in line numbers (LineNumberTable section):
$ javap -v HelloWorld.class > with-line.txt
$ javap -v HelloWorld.class > no-line.txt
$ diff with-line.txt no-line.txt
3c3
< MD5 checksum 435dbce605c21f84dda48de1a76e961f
---
> MD5 checksum 058baea07fb787bdd81c3fb3f9c586bc
51c51
< line 4: 0
---
> line 3: 0
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
Basically, line numbers are kept for debugging, so if you change your source code the way you did, your method starts at a different line and the compiled class reflects the difference.
add a comment |Â
up vote
8
down vote
accepted
Basically, line numbers are kept for debugging, so if you change your source code the way you did, your method starts at a different line and the compiled class reflects the difference.
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
Basically, line numbers are kept for debugging, so if you change your source code the way you did, your method starts at a different line and the compiled class reflects the difference.
Basically, line numbers are kept for debugging, so if you change your source code the way you did, your method starts at a different line and the compiled class reflects the difference.
answered 1 hour ago
Federico klez Culloca
13.7k113973
13.7k113973
add a comment |Â
add a comment |Â
up vote
1
down vote
You can see the change by using javap -v which will output verbose information. Like other already mentioned the difference will be in line numbers (LineNumberTable section):
$ javap -v HelloWorld.class > with-line.txt
$ javap -v HelloWorld.class > no-line.txt
$ diff with-line.txt no-line.txt
3c3
< MD5 checksum 435dbce605c21f84dda48de1a76e961f
---
> MD5 checksum 058baea07fb787bdd81c3fb3f9c586bc
51c51
< line 4: 0
---
> line 3: 0
add a comment |Â
up vote
1
down vote
You can see the change by using javap -v which will output verbose information. Like other already mentioned the difference will be in line numbers (LineNumberTable section):
$ javap -v HelloWorld.class > with-line.txt
$ javap -v HelloWorld.class > no-line.txt
$ diff with-line.txt no-line.txt
3c3
< MD5 checksum 435dbce605c21f84dda48de1a76e961f
---
> MD5 checksum 058baea07fb787bdd81c3fb3f9c586bc
51c51
< line 4: 0
---
> line 3: 0
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can see the change by using javap -v which will output verbose information. Like other already mentioned the difference will be in line numbers (LineNumberTable section):
$ javap -v HelloWorld.class > with-line.txt
$ javap -v HelloWorld.class > no-line.txt
$ diff with-line.txt no-line.txt
3c3
< MD5 checksum 435dbce605c21f84dda48de1a76e961f
---
> MD5 checksum 058baea07fb787bdd81c3fb3f9c586bc
51c51
< line 4: 0
---
> line 3: 0
You can see the change by using javap -v which will output verbose information. Like other already mentioned the difference will be in line numbers (LineNumberTable section):
$ javap -v HelloWorld.class > with-line.txt
$ javap -v HelloWorld.class > no-line.txt
$ diff with-line.txt no-line.txt
3c3
< MD5 checksum 435dbce605c21f84dda48de1a76e961f
---
> MD5 checksum 058baea07fb787bdd81c3fb3f9c586bc
51c51
< line 4: 0
---
> line 3: 0
answered 1 hour ago
Karol Dowbecki
9,76442541
9,76442541
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52625161%2fwhy-does-a-java-class-compile-differently-with-a-blank-line%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
