[Request] Java Access Controls

Post all your tuts or request for tuts here.
Post Reply
User avatar
Zak Zillion
Posts: 112
Joined: Thu Apr 07, 2011 12:55 am

[Request] Java Access Controls

Post by Zak Zillion »

I would really appreciate it if someone could please go into detail about Java Access Controls. I know what they are but I am having trouble putting my mind around the different uses of each.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein

Old Project(s):
The Dark Flame
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [Request] Java Access Controls

Post by Jackolantern »

What do you mean "access controls"? You mean visibility modifiers (private, public, protected, etc.)?
The indelible lord of tl;dr
User avatar
Zak Zillion
Posts: 112
Joined: Thu Apr 07, 2011 12:55 am

Re: [Request] Java Access Controls

Post by Zak Zillion »

yup! sorry about that, in the book i'm reading it has them listed as access controls.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein

Old Project(s):
The Dark Flame
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [Request] Java Access Controls

Post by Jackolantern »

Ahh, ok! The .NET in me made my ears perk-up when I heard "controls" lol.

Anyway, here is a concise, small tutorial on the Oracle site that explains and compares each modifier. Beyond that, I suggest to just make some little experiment classes, and try some things out. See what can access what variables. Don't forget to make subclasses as well, as that is a quite a large dimension to how access modifiers work!
The indelible lord of tl;dr
User avatar
Zak Zillion
Posts: 112
Joined: Thu Apr 07, 2011 12:55 am

Re: [Request] Java Access Controls

Post by Zak Zillion »

Thanks Jack! :D I've been having trouble understanding why it would be a bad thing to make most classes public/protected and at the bottom of that page it clearly stated that it could effect other parts of code which now that I think about it it makes sense! :P But I think your right, I'm just going to make a bunch of little test projects to mess with different types of controls.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein

Old Project(s):
The Dark Flame
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [Request] Java Access Controls

Post by Jackolantern »

You pretty much hit the nail on the head. One of the reasons why object-oriented programming was created and became so popular is that it is well-suited to making large, complex applications. I am not sure if you have experienced this yet, but once a coding project gets to a certain point, you can no longer remember the structure of every code statement anymore. And inevitably, you are going to have to go back and change code you wrote before. But if you can't remember off the top of your head how your entire application is structured, you are going to start breaking things when you try to change your code, because your code is unnecessarily "coupled" within itself. That means that every object is digging through every other object excessively in ways that it should not. You begin to lose control over what your code is doing and what it is accessing, because every object interaction was created in the fastest, easiest way. Access control makes you think about the "interface" that your classes expose to the code outside of itself (not interface programming constructs, but interface as in the public and/or protected methods and fields in a class that allow other classes, "clients", to alter it in a controlled way).

And of course access control can be somewhat of a security measure to prevent broken code from screwing with things it shouldn't, and can limit dangerous bugs. This is especially important for things like banking applications, where all fund transferal methods need to be hidden behind a tightly controlled interface to prevent bugs in the system from causing massive damage to the company.
The indelible lord of tl;dr
User avatar
Zak Zillion
Posts: 112
Joined: Thu Apr 07, 2011 12:55 am

Re: [Request] Java Access Controls

Post by Zak Zillion »

:D I love how when people on this site explain stuff it makes a whole lot more sense then any tutorial I can find. Thanks again jack
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein

Old Project(s):
The Dark Flame
Post Reply

Return to “Tutorials”