Page 1 of 1

[HD Pg 41, Sec. 2.3.1 - important-points-about-the-unnamed-package]

Posted: Wed Dec 26, 2018 8:54 pm
by OCAJO1
//in Item.java

package com.amazon.sales.itemMaster;

public class Item {

public static void main(String[] args) {
}

}

Not sure if this is because of NetBeans file placement or what, but I created the above per page 41, and of course the compiler did not like the fact that package name did not match the file name! So what's the trick?

Re: [HD Pg 41, Sec. 2.3.1 - important-points-about-the-unnamed-package]

Posted: Wed Dec 26, 2018 9:53 pm
by admin
There is no rule that correlates the name of the package and the name of the file! The rule is about name of the class (that too, only if the class is public) and the name of the file.

Check out the last para on page 39 titled "Directory in which source files should reside". Netbeans enforces this convention but this is not mandatory. Another reason to avoid the IDEs while studying for the certification. You will waste time chasing ghosts like this.

(I have requested the author to make this point clear in the book.)

Re: [HD Pg 41, Sec. 2.3.1 - important-points-about-the-unnamed-package]

Posted: Thu Dec 27, 2018 1:38 pm
by OCAJO1
Having just read page 39 and the quiz on page 42, I kind of figured it was netbeans' deal. Thanks for confirming it.

Re: [HD Pg 41, Sec. 2.3.1 - important-points-about-the-unnamed-package]

Posted: Wed Jan 02, 2019 8:56 pm
by OCAJO1
By the way, what would be a technical (and/or business) reason to have an unnamed package?

Re: [HD Pg 41, Sec. 2.3.1 - important-points-about-the-unnamed-package]

Posted: Thu Jan 03, 2019 2:44 am
by admin
Unamed package makes it easy to write small test programs. I havent come across any business reason for it.
Paul.