• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package file and class

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one java file there can be only one public class....we name the java file same as of the java class....now in one file how many packages can be there?
in one package how many public classes can be there?whats the main difference between package and file?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by swapnil paranjape:
...now in one file how many packages can be there?
in one package how many public classes can be there?whats the main difference between package and file?


In java "package" is a way of organizing java classes in order to identify each class uniquely. Having said that you can surely think that a "package" is an hierarchy of folders.
A java file named HelloWorld.java sitting in ...com/idreamz/research folder
should have the package declaration as . And the next thing is to compile and run.

For your questions, you can have only one package declaration. Now if you understand package you can have N (many) classes. Now it should be clear to understand the difference between "package" from a "class".

cheers,
Swapan
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Swapnil,


....now in one file how many packages can be there ?



Packages are nothing more than the way we organize files into different directories according to their functionality, usability as well as category they should belong to.

<b>PACKAGES DO NOT REPRESENT ANY SORT OF SOURCE CODE ORGANIZATION.</b>

There can be only a single package declaration in one java source file. This package can successively have more subpackages.

...in one package how many public classes can be there?



There can be any number of public classes in a package. But ur source file can contain only one public class definition. Import statements help us use the classes defined in that particular package.

...whats the main difference between package and file ?

A package is a way to organize ur source files and classes and interfaces. A file is the place where ur source code is implemented.

Hope this clears ur doubts !!

Cheers !!
 
swapnil paranjape
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you sherry and swapan..that was of great help...
reply
    Bookmark Topic Watch Topic
  • New Topic