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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite
1












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)










share|improve this question

























    up vote
    7
    down vote

    favorite
    1












    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)










    share|improve this question























      up vote
      7
      down vote

      favorite
      1









      up vote
      7
      down vote

      favorite
      1






      1





      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)










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      KNejad

      11319




      11319






















          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.






          share|improve this answer



























            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





            share|improve this answer




















              Your Answer





              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              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.






              share|improve this answer
























                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.






                share|improve this answer






















                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  Federico klez Culloca

                  13.7k113973




                  13.7k113973






















                      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





                      share|improve this answer
























                        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





                        share|improve this answer






















                          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





                          share|improve this answer












                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 1 hour ago









                          Karol Dowbecki

                          9,76442541




                          9,76442541



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              White Anglo-Saxon Protestant

                              BuddyTV

                              Conflict (narrative)