What is the function of "-d ." command?

Thread Solved

Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

What is the function of "-d ." command?

 
0
  #1
Jul 4th, 2009
The program is given at the bottom
To compile java programs in the command prompt I use the following command:
C:\jtemp\MyPack>javac AccountBalance.java -d .

Only then are the classes compiled and I am able to run the main() function. When I execute the above command a folder "MyPack" is created inside the pre-existing MyPack folder. It contains the 2 classes specified in the program.

Then to execute the compiled program I use the following command:
C:\jtemp\MyPack>java MyPack.AccountBalance

No doubt the program succeeds and prints the expected lines.

Now that's fair enough. The reason I am writing this thread is that I am unable to understand the true significance of the "-d ." command. If I try to compile the classes without it, firstly no folder is created inside the pre-existing folder "MyPack" and secondly the following commands yield a "NoClassDefFoundError". Please note that the classes are still compiled and appear just besides the .java file in the window. It is just that they do not execute successfully this time.

C:\jtemp\MyPack>java MyPack.AccountBalance
C:\jtemp\MyPack>java AccountBalance

I know it has got something to do with the "Classpath" variable but even after reading about it, it's still Greek and Latin to me.

Please help. The Program is stored at the address "C:\jtemp\MyPack>" on my hard-disk, has the name "AccountBalance.java" and is as follows:
  1. package MyPack;
  2.  
  3. /**
  4.  *
  5.  * @author Shashank Sawant
  6.  */
  7. class Balance {
  8. String name;
  9. double bal;
  10.  
  11. Balance(String n, double b){
  12. name = n;
  13. bal = b;
  14. }
  15. void show(){
  16. if(bal<0)
  17. System.out.print("->");
  18. System.out.println(name + ":$" + bal);
  19. }
  20. }
  21.  
  22. class AccountBalance {
  23. public static void main (String args[]){
  24. Balance current[]=new Balance[3];
  25.  
  26. current[0]=new Balance("K. J. Fielding",123.23);
  27. current[1]=new Balance("Will Tell",157.02);
  28. current[2]=new Balance("Tom Jackson",-12.23);
  29.  
  30. for(int i=0;i<3;i++)
  31. current[i].show();
  32. }
  33. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,600
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: What is the function of "-d ." command?

 
0
  #2
Jul 5th, 2009
If your program file has package statement then all these classes defined inside the file must be stored into package name folder.

Example in above post:

  1. >javac AccountBalance.java -d .
statement creates a folder MyPack in current directory (. with command line) and both Balance.class and AccountBalance.class files are placed into MyPack folder.

Run - JVM launch AccountBalance class from file system folder MyPack.

  1. >java MyPack.AccountBalance

If you want to store compiled classes in another folder other that current directory.
  1. >javac AccountBalance.java -d c:\test
Last edited by adatapost; Jul 5th, 2009 at 1:59 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Re: What is the function of "-d ." command?

 
0
  #3
Jul 5th, 2009
Originally Posted by adatapost View Post
If your program file has package statement then all these classes defined inside the file must be stored into package name folder.

Example in above post:

  1. >javac AccountBalance.java -d .
statement creates a folder MyPack in current directory (. with command line) and both Balance.class and AccountBalance.class files are placed into MyPack folder.

Run - JVM launch AccountBalance class from file system folder MyPack.

  1. >java MyPack.AccountBalance

If you want to store compiled classes in another folder other that current directory.
  1. >java AccountBalance.java -d c:\test
Thanks for the reply. I am assuming that the last sentence in your post should have "javac" instead of "java". Please correct me if I am wrong.

I did that. Actually to be exact I did the following thing:
c:\jtemp\mypack>javac AccountBalance.java -d c:\jtemp\adat

As expected a folder "MyPack" was created inside the "adat folder.
For confirmation this is the address of the folder I am talking about:
c:\jtemp\adat\mypack>
Also, as per expectations, it has the 2 class files.

Now this is where my usual problem begins. The problem I can't get around no matter what I try; the problem who's answer is what I am seeking on the internet.

How should I execute these class files? Every attempt I make yields the result "NoClassDefFoundError".

Please help. These are the ways I have attempted to execute the classes:
1. c:\jtemp\adat\mypack>java MyPack.AccountBalance
2. c:\jtemp\adat\mypack>java .AccountBalance
3. c:\jtemp\adat>java MyPack.AccountBalance
4. c:\jtemp\adat>java AccountBalance

All result in the same error. It is not the compilation, or the place where the class files get stored is the issue. The issue is how do I run the class files? I know only one way - and I must thank you (adatapost) for that respite - but that method is too restricted. This only method is what I have given in my first post. But when I change the location where the classes are finally compiled, I can't run them.

Please help!

Regards,

-sgsawant
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,600
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: What is the function of "-d ." command?

 
0
  #4
Jul 5th, 2009
Thanks,

I have correct that.

See,
  1. c:\xyz>javac AccountBalanace.java -d c:\pqr
.class files are copied at MyPack under c:\pqr folder.

Use -classpath or -cp swith with java launcher
  1. c:\xyz>java -cp c:\pqr MyPack.AccountBalance

or
  1. c:\pqr>java MyPack.AccountBalance
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 24
Reputation: ThinkFree is an unknown quantity at this point 
Solved Threads: 3
ThinkFree ThinkFree is offline Offline
Newbie Poster

Re: What is the function of "-d ." command?

 
0
  #5
Jul 6th, 2009
c:\jtemp\adat>java MyPack.AccountBalance
should work. It works for me.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 16
Reputation: sincerelibran is an unknown quantity at this point 
Solved Threads: 9
sincerelibran sincerelibran is offline Offline
Newbie Poster

Re: What is the function of "-d ." command?

 
-1
  #6
Jul 7th, 2009
Originally Posted by sgsawant View Post
The program is given at the bottom
To compile java programs in the command prompt I use the following command:
C:\jtemp\MyPack>javac AccountBalance.java -d .

Only then are the classes compiled and I am able to run the main() function. When I execute the above command a folder "MyPack" is created inside the pre-existing MyPack folder. It contains the 2 classes specified in the program.

Then to execute the compiled program I use the following command:
C:\jtemp\MyPack>java MyPack.AccountBalance

No doubt the program succeeds and prints the expected lines.

Now that's fair enough. The reason I am writing this thread is that I am unable to understand the true significance of the "-d ." command. If I try to compile the classes without it, firstly no folder is created inside the pre-existing folder "MyPack" and secondly the following commands yield a "NoClassDefFoundError". Please note that the classes are still compiled and appear just besides the .java file in the window. It is just that they do not execute successfully this time.

C:\jtemp\MyPack>java MyPack.AccountBalance
C:\jtemp\MyPack>java AccountBalance

I know it has got something to do with the "Classpath" variable but even after reading about it, it's still Greek and Latin to me.

Please help. The Program is stored at the address "C:\jtemp\MyPack>" on my hard-disk, has the name "AccountBalance.java" and is as follows:
  1. package MyPack;
  2.  
  3. /**
  4.  *
  5.  * @author Shashank Sawant
  6.  */
  7. class Balance {
  8. String name;
  9. double bal;
  10.  
  11. Balance(String n, double b){
  12. name = n;
  13. bal = b;
  14. }
  15. void show(){
  16. if(bal<0)
  17. System.out.print("->");
  18. System.out.println(name + ":$" + bal);
  19. }
  20. }
  21.  
  22. class AccountBalance {
  23. public static void main (String args[]){
  24. Balance current[]=new Balance[3];
  25.  
  26. current[0]=new Balance("K. J. Fielding",123.23);
  27. current[1]=new Balance("Will Tell",157.02);
  28. current[2]=new Balance("Tom Jackson",-12.23);
  29.  
  30. for(int i=0;i<3;i++)
  31. current[i].show();
  32. }
  33. }
Dear Friend,

-d stands for deprecated. That means, some of the functions/features which were used in the earlier versions of java and not included in the newer versions. You might be using some of those functionalities or features. That's why you're getting such an error. So when you compile you've to use -d. The syntax actually is javac -d Sample.java
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,600
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: What is the function of "-d ." command?

 
0
  #7
Jul 7th, 2009
sincerelibran,
-d for dead
-d for drop
-d for duplicate
Do not write anything.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 9
Reputation: sgsawant is an unknown quantity at this point 
Solved Threads: 0
sgsawant's Avatar
sgsawant sgsawant is offline Offline
Newbie Poster

Re: What is the function of "-d ." command?

 
0
  #8
Jul 7th, 2009
Originally Posted by adatapost View Post
Thanks,

I have correct that.

See,
  1. c:\xyz>javac AccountBalanace.java -d c:\pqr
.class files are copied at MyPack under c:\pqr folder.

Use -classpath or -cp swith with java launcher
  1. c:\xyz>java -cp c:\pqr MyPack.AccountBalance

or
  1. c:\pqr>java MyPack.AccountBalance
Thanks a lot!

The instruction to change the classpath works and executes the program. Even though after entering the directory where MyPack folder (containing the classes) is stored, the command
C:\jtemp\adat>java MyPack.AccountBalance
doesn't work. (refer the attachment)

Nevertheless my problem has been solved. Perhaps the classpath variable is locked by default and explicit instruction is necessary on my machine (just a guess).

Thanks to everyone, esp. adatapost!

Regards,

-sgsawant
Attached Thumbnails
java_prob_daniweb.JPG  
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC