Skip to content
Related Articles

Related Articles

How to Set Destination of the Class File in Java?
  • Last Updated : 08 Dec, 2020

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.


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 -d "path to store the .class file"


Source         : file in "/home/mayur/" directory
Destination     :"/home/mayur/folder" directory
Command        : javac -d "/home/mayur/folder"



// How to Set Destination of the Class File in Java?
public class demo {
    public static void main()
            ".class file will be saved in destinated folder");

Folder Before program execution:

During Execution:

After Execution:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :