Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAditya Puri
1,080 PointsWhy did we have a new class file?
When we ran the program, why did a new class file(Treet.class) got created?
1 Answer
Harry James
14,780 PointsHey Aditya,
This happens when we use the javac command, when the compiler does the work for us :)
This converts the code we have written into a smaller file, that is more efficient to be run on devices.
Hope it helps and if you have any more questions, give me a shout :)
Aditya Puri
1,080 PointsAditya Puri
1,080 Pointshow can we use that smaller file?
Harry James
14,780 PointsHarry James
14,780 PointsHey Aditya,
We can't actually use this ourselves, as to us it isn't a readable format. Java knows how to read it for us though, so we'd just call it with
java Treet
.Note that this would actually throw an error as we're trying to run a class without a main() method. However, it's the same thing we're doing when we call
java Example
, we're telling Java to run the Example.class file rather than the Example.java file.So, to summarize:
javac
command to compile our human-readable code into a smaller, more efficient file, the .class file. This code is readable to the computer, not us, and provides binary instructions for how to operate.java
command to run the code that is readable to the computer - the .class files.Hopefully this explains things but if you're not quite there, let me know :)
Aditya Puri
1,080 PointsAditya Puri
1,080 PointsSo we can delete that file? Is it just a binary form of the file that had been runned? If we run our program multiple times then wouldn't a lot of these files clutter in our folders and make everything look messy?
Harry James
14,780 PointsHarry James
14,780 PointsHey again Aditya,
The file will overwrite itself whenever you run
javac
again, preventing the clutter you're on about :)Also just to clarify, it's not a binary file of a program that has been run, it's a binary file of a program that has been compiled. Even if you were to just use the command
javac
withoutjava
(Compiling, not running), these files would still be created.Aditya Puri
1,080 PointsAditya Puri
1,080 Pointsso if we delete them and then compile again, then they would be recreated? And if we compile again without deleting then the existing one would be rewritten?
Harry James
14,780 PointsHarry James
14,780 PointsYep! You got it :)
Aditya Puri
1,080 PointsAditya Puri
1,080 Pointsk thanks!