- D option

Requirement of -d option

  • It's not advisable to keep both .class files and .java files inside the same folder.
  • Because instead of deleting .class file ,if u delete any .java file we will lose the original code.
  • Creating .java file will take more time compared to creating .class file.In order to overcome this drawback it's better to separate .class files from .java files

How to Redirect .class files to user specified location:

  • By default,compiler will create .class files under current directory i.e. where java files are available
  • If we want to create user specified location (or) different location we should use the -d option for the javac command.
-d option with javac command

-d option with javac command example

If we compile java files by using -d as shown in the above. .class files will be created under classes folder Instead of creating under current directory (i.e. src). Here we can specify destination path in two ways

  • Absolute path: it specifies the path from starting to ending.
  • Real path: it specifies the path from present location to destination location.

Note1 :
  • From cmd prompt if we want to go one step up we need give ../ .

We can see the example below screen shot.
-d option with Absolute path and Relative path

Folder Structure of .class files creation:
Structure of .class file creation

Note2 :
  • .. --- means one step up or previous directory.
  • . ---- means current directory

How to compile more then one java file at a time.
  • If we want to compile all java files at a time then we should give *.java rather than the one specific file name unlike HelloWorld.java
  • By using *.java we can able to compile all java files with in only one folder.

Folder Structure with more than one file

Compile Command more than one java