Java Java Data Structures Efficiency! Design the UI

Derek Derek
Derek Derek
8,744 Points

importing packages


I'm not sure about the relationship between the directories/folders in which the .java files are saved and the package commands on each of the files.

For instance,

for and, it is "package com.teamtreehouse.model;" and these are stored in com/teamtreehouse/model.

for it imports both of the files in com/teamtreehouse.model "import com.teamtreehouse.model.Song;" "import com.tremtreehouse.model.SongBook;"

for which is saved in com/teamtreehouse, it is "package com.teamtreehouse;"

My questions are

  1. why do the files have to be saved in different directories and how do we determine which one has to go where
  2. how does the location in which they are saved change the import package lines?

Thank you!

Jasper Peijer
Jasper Peijer
18,537 Points
  1. Files are saved in different locations for accesibility. For example: If you want some certain classes have accessibility to an method in another class and some not, You give the method protected instead of public or private. This means it is only accessible from the same package.
  2. The import package line is basically what you wanna import and in which package is it located. So if you are in a class in the package com.teamtreehouse.model and you wanna import for example the class Apple from the package com.teamtreehouse (NOT in com.teamtreehouse.model). Then you wanna use this:

import com.teamtreehouse.Apple;