• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

package

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we create user define package. in this package we define several classes
my question is which name we should save the program
 
Marshal
Posts: 80983
530
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You save the classes in files with their names. You can save them in a .src (for source) folder, or (probably better) in folders matching the package hierarchy. The Java Tutorials might help you.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sunil Sunny wrote: Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.


Are you talking about single file? Ideal practice is - create a different file for each class. That way, it becomes easy to maintain the application.
 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sunil Sunny wrote: Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.


If you are having muliple classes in single file you are not required to must have a public class. All classes can have default access modifier.
 
Campbell Ritchie
Marshal
Posts: 80983
530
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sunil Sunny wrote: . . . If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . . . .

Not quite accurate; the other two people posting have given the correct answers.
 
This tiny ad will self destruct in five seconds.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic