Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Modifiers, do I realy need them

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple question :
Are the access modifiers (aka scopes) something what you need to know to "program" in java or is enough to know only some API (e.g that the String class has a split method).

I know the answer, but I need to know some other people meaning.
How about you guys ? feel free to add all your comments (related with the topics) to this post.

Regards,
M
 
Campbell Ritchie
Sheriff
Pie
Posts: 49751
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you do. But don't confuse access modifiers with scopes, which are something completely different.

You want to hide the fields of your classes, usually by giving them private access and you usually want to make the methods widely available by giving the public access.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are traffic lights something I need to know to "drive"? Is it enough too know what a few of the signs mean?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12183
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Are traffic lights something I need to know to "drive"? Is it enough too know what a few of the signs mean?

that would depend on where you are driving. if you're only on country roads that don't HAVE stoplights, then no, you don't.

The same would go for java (IMHO). if you are just going to do simple stuff, then no, you don't need access modifiers. if you are going to do anything even REMOTELY beyond a basic program, then yes.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49751
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're only on country roads without stoplights, you still have to know about traffic lights (at least in Britain) because you will have to take a driving test which is mainly town traffic.

Or you can drive without a licence, without a test on the car, without tax and insurance. etc.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:

The same would go for java (IMHO). if you are just going to do simple stuff, then no, you don't need access modifiers. if you are going to do anything even REMOTELY beyond a basic program, then yes.


If you are saying that access modifiers are necessary to write complex programs, Smalltalk programmers will disagree. In Smalltalk all methods are automatically public, and all fields private. And Smalltalk is known to be quite appropriate for complex programs.

I'd still say that to be taken seriously as a Java programmer, you will need to at least understand how they work.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people,

First I'll like to thanks for your interest.
I anticipate this answers and I agree with everything.
I come on this (strange) questions after some endless discussions with some of the "visual" developers, this people are used to use smart IDES where everything is pink, or at least it looks like. This is a classical case where a tool changes quick from a bless in to curse and this without the victim can check something.
Even if you try use the theory like argument they have the "look it works" argument.
What arguments can I bring in this kind of dispute ?
What you guys think about ?


Regards,
M
[ April 24, 2008: Message edited by: Mihai Radulescu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic