aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes public, protected, package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "public, protected, package" Watch "public, protected, package" New topic
Author

public, protected, package

Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
I was wondering what to keep access levels of classes and methods? For example in my fbn.client package, do I need to make the FBNClient class package level or public? I was leaning toward the latter as then it cannot be accessed outside its package. Also server classes like IMPL's etc, do they need to be public? You see I am too used to using public all the time that i hate to think of package but that is the right way to go.


Never be satisfied with anything less than the best and you will surely pass the test...
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
Also whats the point in having public methods, if the class itself is given package access?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I think that is a good question. I made sure that all my instance variable were private, and if I needed any of them that I would include a public method that would return the value.
As far as making the methods public, I think that package is good, but what if you want to extend some other new application and use the classes there. Or actually thinking about it my DataAccessFacade was part of my db package and not my client package, even though the client used it to pass calls to the data class. So if they were package then the client could never call them.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
So do you think its a good thing to make classes package?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Nah, I like either public or private. I always think making something package visible only is limiting where the objects can be used.
Mark
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
All I want is to win the Lotto. Is that asking too much?
Of course not. Mark what a cool signature! I have not seen such a cool one, but seen a lot as follows.
XXXXXXXXXXXXXXX(My Good Name) THEN
SUN Certified Programmer For The Java 2 Platform
SUN Certified Web Component Developer For The Java 2 Platform
SUN Certified DeveloperFor The Java 2 Platform
SUN Certified Architect For The Java 2 Platform
BLAH,BLAH,BLAH,


A long tail after their name then their posting. I could not say anything even though I did not like it. Everybody knows certified people or who want to certify roam around JavaRanch. I know, they are certified and they have full right to express it as RESUME all the time. I am mouthy, it is really bad.
But I liked yours. GOOD LUCK! It was being unnoticed here. Just I wanted to draw the attention. I am sorry being off the track during public and private parade.
-Bal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public, protected, package