Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command line invocation

 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given two files:

a=b.java
c_d.class

Are in the current directory, which command-line invocation(s) could complete without error? (Choose all that apply.)

1.

java -Da=b c_d
2.

java -D a=b c_d
3.

javac -Da=b c_d
4.

javac -D a=b c_d


question is from K&B.

i think the answer should be 2. but its 1. why?

a=b is the name of a java file its not name-value pair for a property.
 
Nasser Fayeghi Fard
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha Daga wrote:
Given two files:

a=b.java
c_d.class

Are in the current directory, which command-line invocation(s) could complete without error? (Choose all that apply.)

1.

java -Da=b c_d
2.

java -D a=b c_d
3.

javac -Da=b c_d
4.

javac -D a=b c_d


question is from K&B.

i think the answer should be 2. but its 1. why?

a=b is the name of a java file its not name-value pair for a property.


Dear Neha,
Note that there must NOT be any space between -D switch and parameter name
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats what I want to know if a=b is a java file, then how java -Da=b c_d is setting a property ?
 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha if you observe all otions carefully you will find that option 1 is correct one,

As you know javac is used for compiling .java files, and
java is used for running .class files.


Now for each option explanation is as follows

1. 1st option is used for running c_d.class file
and we are setting a=b system property.

2. For 2nd option there shouldn't be any space between D and a=b

3 and 4. We can't use javac to compile class files, we use javac to compile .java files

Hopes this will help you in understanding this
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, now I get it.

thanks Rohan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic