• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Sybex 815 Chapter 1 practice question 15

 
Greenhorn
Posts: 1
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, I have a little confusion with question 15 (page 33) and its answer (page 493) of the Java 11 OCP study guide (815).
The question asks what is the output of a chunk of code when run as "java Duck Duck Goose". I understand the answer quoted in the book (none of the above), as well as the reasoning (code is missing the static keyword on the main method). However I feel there may be an additional issue at play here: the command being used to run the code.
The java command is being used though the file is specified without the .java extension. I guess my question is this: are we to assume that where "java" is used that the code has already been compiled into bytecode using javac? Or is this a typo within the book and the command should instead be "java Duck.java Duck Goose"?


Another question while I'm at it. On page 10 the main method's parameter, a String array, is described. I'm curious as to why the example using varargs has a trailing semicolon? Out of curiosity I tried adding the semicolon but as I suspected the compilation failed.

Cheers
 
Saloon Keeper
Posts: 1328
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Brad!

The authors come on here periodically, but some of us are here more often, and as for myself in particular, I am also preparing for taking the 819, so...

I had never noticed the extra ;'s on the two examples of page 10, I agree that they don't belong inside the (    ) for a parameter list!

The ability to "run from source" at all, without a separate compile step, is rather new.
From what I can tell you would only expect to see one or two questions on that, and it should be clear that is what they are talking about.

Almost all the "code sample" questions imply that the source is saved in an appropriately named file and compiled, there are some exceptions where they are trying to see if you know that you can only declare one top-level public class interface or enum per java source, if you know that there can be 0 or 1 package statement per source file, and if present it must be the first non-blank, non-comment line, etc.

Cheers!
 
author & internet detective
Posts: 40747
827
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

Brad Phillips wrote:The java command is being used though the file is specified without the .java extension. I guess my question is this: are we to assume that where "java" is used that the code has already been compiled into bytecode using javac? Or is this a typo within the book and the command should instead be "java Duck.java Duck Goose"?


It's not a typo. It is context dependent. In this case, we are assuming the code has been compiled already. However, as you noted java Duck.java would also be correct because that would assume the code hadn't been compiled.

Note that javac/java are not on the 819 exam. We cover them because you need to know how to run code in order to have any chance of practice and passing the exam . Also, there are a few topics in chapter 1 that were on the 815 but removed on the 819.


Brad Phillips wrote:Another question while I'm at it. On page 10 the main method's parameter, a String array, is described. I'm curious as to why the example using varargs has a trailing semicolon? Out of curiosity I tried adding the semicolon but as I suspected the compilation failed.


I went semicolon hunting and that one was clever enough to escape. (Seriously, it's a typo. Adding to the errata now)

Welcome to CodeRanch!
 
Jesse Silverman
Saloon Keeper
Posts: 1328
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait up, Jeanne!

Note that javac/java are not on the 819 exam. We cover them because you need to know how to run code in order to have any chance of practice and passing the exam . Also, there are a few topics in chapter 1 that were on the 815 but removed on the 819.



I thought we said that non-modular javac and java were removed from the exam, i. e.:

javac --module-path mods/ -d myModuleBase myModuleBase/module-info.java myModuleBase/my/package/*.java

java --module-path mods/ --module myModule/my.package.EntryClass
type kinda stuff still is in scope for the exam?

I agree we definitely need to know it either way, but did you over-speak in the quote above?  Or did I read that wrongly?



 
Jesse Silverman
Saloon Keeper
Posts: 1328
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I missed Jeanne for now, but found this quote on the 819 Oracle page she linked to:

Deploy and execute modular applications, including automatic modules


reply
    Bookmark Topic Watch Topic
  • New Topic