r/javahelp • • Aug 14 '22

Basic Java questions thread

Hello, I'm coming from C++ and having to learn some Java pretty quickly. I have some questions, and wanted to post in a single thread, so that I'm not flooding /r/javahelp.

I'll post my questions in the comments. Anyone else is free to answer or ask qs of their own. Thank you.

20 Upvotes

33 comments sorted by

View all comments

1

u/rootseat Aug 14 '22

Is the following true or false?

Java packages are imported. When a source file contains the line import foo.bar.baz, we are asking the compiler to find all the files that contain the line package foo.bar.baz.

So when I have the following in file.java:

package a.b.c

import x.y.z

class Yay {}

Then my intent would be that Yay depends on x.y.z, and also that a.b.c is required by some other class elsewhere.

1

u/[deleted] Aug 15 '22

"a.b.c is required by some other class"

Not necessarily, no. Other classes may import your Yay class and for this they would need to import "a.b.c", yes.