USE OF –d OPTION

According to industry convention you can’t put both .class file and .java file inside a single folder.
So you have to make two separate folders for two separate files.
Let us take a example, we will put the .class files in class folder and .java files in src folder.
-d option is helped us to ”specify where to place generated .class file”.
For the above class let us make two folders one is “class” to store .class files and another one is “src” to store .java files.
You can make use of –d option.
For that you have to create a .java file inside the src folder & you have to compile it through javac command.
Let’s see how to run it through command prompt: 
By the above command you can compile store and run a program through cmd.
The “javac –d ../class Bbs.java” give the path to class folder where you are going to store the class file.
For running another program no need to open another command prompt, you have to just go one step back to src folder by using “cd ../src”.
You will run this program through the cmd as bellow, now you will get how to run the program through –d option. -d option2 
Like above commands we can compile store and run any java program from anywhere.
 

1

2

3

4

5

6

7

8

package pack;

class IntAdd

{

    public static void  main(String[]args)

    {

        System.out.println(10+20);<br>

    }

}

O/P:

-d option

1

2

3

4

5

6

7

8

9

10

11

12

13

     

class Hello

{

  public  static void main(String[] args)

    {

        System.out.println("Hello  World!");

        System.out.println("Hello  World!");

        System.out.println("Hello  World!");

        System.out.println(10+20);

        System.out.println(20.29);

        System.out.println("i");

    }

}

O/P:

-d option

1

2

3

4

5

6

7

8

9

     

class PrintI

    {

        public  static void main(String[] args) {

          int  i;

          i=20;

          System.out.println(i);

        }

    }

O/P:

-d option2

1

2

3

4

5

6

7

8

9

10

11

         

class Initialize

    {

        public  static void main(String[] args)

            {

                int  i;

                int  j;

                j=i;

                System.out.println(j);

            }

    }

O/P:

-d option2