Monday, February 9, 2026
HomeLanguagesJavaHow to Set Destination of the Class File in Java?

How to Set Destination of the Class File in Java?

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:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32493 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6866 POSTS0 COMMENTS
Nicole Veronica
11991 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12086 POSTS0 COMMENTS
Shaida Kate Naidoo
7001 POSTS0 COMMENTS
Ted Musemwa
7241 POSTS0 COMMENTS
Thapelo Manthata
6953 POSTS0 COMMENTS
Umr Jansen
6939 POSTS0 COMMENTS