Wednesday, October 8, 2025
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
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11875 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS