In this article, Let’s learn How to Set Destination of the Class File in Java. Before that, let’s understand what is a class file. When we compile a java file, we get a class file. A Java class file is a file containing Java byte-code and having ” .class” extension that can be executed by JVM.
The java file is compiled using javac command as shown below.
javac filename.java
In general, when a java file is compiled the generated ” .class” file will also be saved in the same folder. In order to set the destination of .class file we use -d option while compiling the ” .java” file, as shown below:
javac filename.java -d "path to store the .class file"
Example:
Source : Gfg.java file in "/home/mayur/" directory Destination :"/home/mayur/folder" directory Command : javac Gfg.java -d "/home/mayur/folder"
Implementation:
Java
// How to Set Destination of the Class File in Java? public class demo { public static void main() { System.out.println( ".class file will be saved in destinated folder" ); } } |
Folder Before program execution:
During Execution:
After Execution: