Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is a project and a package the same thing?  RSS feed

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the book im reading talks about classes in packages etc
is a package and a project the same thing
if i create a project called Cowboys ...is that a package?

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know this is the definition of a package:
Definition: A package is a grouping of related types providing access protection and name space management. Note that types refers to classes, interfaces, enumerations, and annotation types. Enumerations and annotation types are special kinds of classes and interfaces, respectively, so types are often referred to in this lesson simply as classes and interfaces.

but when does it become necessary to use one,or create one...
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is a package and a project the same thing

The term "project" has no meaning in the Java language. Some IDE's (such as Eclipse)  do use the term "project" to specify a particular style of grouping code, but there is no specific correlation with the concept of Java packages.
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes fred i did realise that...

so when i create a new project called Java in intelij etc...is that a package? ....or is a package something else?
could a package just be a group of reusable classes that perform a specific function?

thanks for answering fred
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the tutorial: http://docs.oracle.com/javase/tutorial/java/concepts/package.html
 
Liutauras Vilda
Marshal
Posts: 4647
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:...so when i create a new project called Java in intelij etc...is that a package? ....or is a package something else?

You might getting confused because of their look in your file system. Same as the project, package in your file system look exactly the same - as a "folder" basically.

When you create a project in your IDE environment, you get a folder with project's specific stuff inside. Could be "src" (for source files *.java) and "bin" (for compiled binary files *.class) folders as well with some other optional files.

When it comes down to packages, packages being specified within your source files (*.java) as a very first statement, before any import statements or class declaration. Those packages later in your file system look exactly like folders if that is easier to understand for you.
Packages are specifically treated and named like that, because they are directly related with Java language syntax, i.e.: package jon.ninpoja;    <-- that would look in your project folder "ProjectName\jon\ninpoja\DeclaredClassName.java"

So, in case you have your projects folder in your windows drive C:\ and all your IDE environment projects being created in for example C:\workspace\ AND you create a project "Java", all it would look in your file system as C:\workspace\Java\    <-- some project specific folders would be inside too, lets assume "src" and "bin".

Now if you'd create 1 source file (Java class) named "Test" with declared package name "jon", so all structure would look as C:\workspace\Java\src\jon\Test.java

After all, your confusion is understandable, I'd say don't worry too much about it for now and keep moving with the book, some time later it will start making sense. It isn't most important thing for now probably for you to concentrate on.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jon ninpoja wrote:if i create a project called Cowboys ...is that a package?

No, in a real Java project you often create multiple packages in one project. It is definitely not the case that one project always corresponds to one package, or the other way around.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!