Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should two java files that differ only in comments produce different class files?

I have a file called One.java that has only one commented line. I compiled it to produce the class file One.class and Renamed it as old.class. Then, I opened One.java, introduced five more commented lines and compiled it again to produce One.class. Both the class files had the same size, but when I ran diff on them like: diff One.class old.class I got the output:

Binary files One.class and old.class differ

This is my One.java file:

// One.java
class One
{
    public static void main(String [] args)
    {
        System.out.println("Hello Java world");
    }
}

and this is my revised One.java (with additional lines of comment):

// One.java
// One.java
// One.java
// One.java
// One.java
// One.java
class One
{
    public static void main(String [] args)
    {
        System.out.println("Hello Java world");
    }
}

I am using Java SE 10 on an iMac running High Sierra.

like image 812
Seshadri R Avatar asked Dec 31 '25 13:12

Seshadri R


1 Answers

Debugging symbols; basically the code includes line numbers and other metadata for debugging. You can examine it yourself with javap -v One.class and javap -v old.class

like image 78
Elliott Frisch Avatar answered Jan 03 '26 01:01

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!