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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.)

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post by OCAJO1 »

By the way, what would be a technical (and/or business) reason to have an unnamed package?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Unamed package makes it easy to write small test programs. I havent come across any business reason for it.
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests