I have a code base and some methods are never used.
Does javac
remove the unused methods from the class file?
Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.
Javac. In Java, source code is first compiled to the bytecode by the javac compiler. Then, a Java Virtual Machine (JVM) interprets and executes bytecode. So, javac is an excellent example of a compiler that belongs to an interpreter system.
Technically, javac is the program that translates Java code into bytecode (. class file) - an intermediate format which is understandable by the Java Virtual Machine (JVM). And java is the program that starts the JVM, which in turn, loads the . class file, verifies the bytecode and executes it.
The javac compiler source code is available in the OpenJDK repositories, at http://git.openjdk.java.net/. The mainline sources are in http://git.openjdk.java.net/jdk.
Q: I want to know if I have a code base and some methods are never used. Does javac remove the unused methods from the class file?
A: No. What goes into the class, stays in the class file.
... however ...
The JVM loads only what's needed into memory. RAM isn't "wasted" on unused classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With