Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does javac removes methods that are not referenced in the code?

Tags:

java

javac

I have a code base and some methods are never used. Does javac remove the unused methods from the class file?

like image 694
CommonMan Avatar asked Mar 07 '12 22:03

CommonMan


People also ask

What does javac command do?

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.

How does javac compiler work?

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.

What is the difference between Java and javac?

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.

Where is javac source code?

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.


1 Answers

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.

like image 69
paulsm4 Avatar answered Oct 07 '22 00:10

paulsm4