• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Sybex 829 - Review Questions Chapter12]

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
regarding question #3 (Chapter 12 p.713), the related explanation states:
"Option D would be correct if the rest of the command were correct."
Option D is: -m and -p
But, to run a program the command shouldn't be the opposite: -p and -m (making option F the right one)?

Thanks in advance.
 
Marshal
Posts: 79231
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know, but please tell us who don't have the book/site the full text of the questions.
 
Federica Sacca'
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
here attached the screenshot of the question, related answer's options and the review answer.

Thanks.

BR.
test_modules_question_3.png
[Thumbnail for test_modules_question_3.png]
 
Bartender
Posts: 3908
43
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[UPD] the command below is wrong, see update and explanation next posting

Hi Federica, this command would be correct:


java -m zoo.animal.talks/zoo.animal.talks.Peacocks -p modules


where

zoo.animal.talks.Peacocks -- a runnable class' fully qualified class name
zoo.animal.talks -- module name

Syntax:

 -p <module path>
 --module-path <module path>...
                 A ; separated list of directories, each directory
                 is a directory of modules.




      java [options] -m <module>[/<mainclass>] [args...]
      java [options] --module <module>[/<mainclass>] [args...]
          (to execute the main class in a module)



 
Federica Sacca'
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mikalai,
thanks for your reply!

So, if I understand correctly, the following command should be the same but in reverse order (it's a run command module example in the book - s.attachment):

java -p mods -m zoo.visitor/zoo.visitor.Tourist




run_command.jpg
[Thumbnail for run_command.jpg]
 
Mikalai Zaikin
Bartender
Posts: 3908
43
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Federica,

Sorry, my first posting was wrong and you're right.

The -m option must go in the very end, because after the runnable class will go arguments which will be passed into the static main(String[] args)  method, so option -p (module path) may not go after the -m (module), in that case it will be ignored by Java Module System, and passed as array of strings in the main method

This must be the correct command:

java -p modules -m zoo.animal.talks/zoo.animal.talks.Peacocks
 
Mikalai Zaikin
Bartender
Posts: 3908
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what is the book on the photos, but seems the explanation is not fully accurate. Besides wrong class name syntax, the order of options is invalid (and it's very important IMHO).
 
Federica Sacca'
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mikalai,
thanks again for your feedback.

All the photos in this thread are taken from the book "OCP Study Guide exam 1Z0-829. (This book is very helpful for me   )

 
author & internet detective
Posts: 41871
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mikalai Zaikin wrote:The -m option must go in the very end, because after the runnable class will go arguments which will be passed into the static main(String[] args)  method, so option -p (module path) may not go after the -m (module), in that case it will be ignored by Java Module System, and passed as array of strings in the main method

This must be the correct command:

java -p modules -m zoo.animal.talks/zoo.animal.talks.Peacocks


I didn't know this. Mikalai is correct. I ran it and the behavior matches his statement.



Added to the errata, my notes and my brain
 
Jeanne Boyarsky
author & internet detective
Posts: 41871
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was also wrong in our Java 11 books so added to that errata as well
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic