Jdev11 complains about public instance variables, but not Jdev10

Hi all, if I fire up Jdeveloper10 I can declare a public instance variable. (OK, stylistically maybe not a good thing, but nothing in the java 'rules' that says I shouldn't be able to do this.) However in Jdeveloper11 it complains, it underlines it in red and grumbles "should not have greater than protected access."
Anyone know where to turn off this compiler hint?
thanks.
public class Thing() {
public String bob; // complains in jdev11, ok in jdev10.

Hi Kevin, thanks for the tip. It's taken me years just to remember where to turn on the line numbers in 'preferences' , so I would never have found that one about the instance variable checks ! Frank, thanks for the update, I agree it's useful as a stylistic hint, but I think that the Jdev floating code assist, rather than just hinting "declare this field protected" (as this will obviously fix it) would be more user-friendly if it also said "or disable under preferences - code assists." But Jdev11 is growing on me, tons of cool stuff :-)
thanks all.

Similar Messages

  • Public instance variable vs. accessor method

    I know some OOP purists believe all instance variables should be private, and if there's a need to view or set the value of these instance variable, public accessor methods need to be created. Data encapsulation is the driving force behind this belief.
    But in Java, it's easy enough to declare an instance variable public thus eliminating the need to write accessor method. What's the rational behind this feature? Is it merely to save developer some time from typing in the accessor methods? Does this reason justify the use of public members?

    I know some OOP purists believe all instance variables
    should be private, ALL? No way!
    and if there's a need to view or
    set the value of these instance variable, public
    accessor methods need to be created. There has to be a reason for any :- public int getMyInt(){ ...
    and in many cases protected or default package is more appropriate
    Data
    encapsulation is the driving force behind this belief.
    Correct , also avoiding multiple instances of member states - very often its a control issue too
    But in Java, it's easy enough to declare an instance
    variable public Yes and its also easy enough to write shittie code too ...
    if an instance variable is public there should be a clear comment explaining why the field has to be public
    thus eliminating the need to write
    accessor method. There's nothing wrong with accessors and mutators - the java language is full if them
    What's the rational behind this
    feature? As you stated encapsulation
    Is it merely to save developer some time
    from typing in the accessor methods? This is a lame reason
    Does this reason
    justify the use of public members?and attract unwanted side effects?
    I also don't like to see (or to write) a huge long list of getters and setters at the bottom of any class file and find it quite ugly - You should use them when you need to, not as a matter of routine.
    Accessor - mutator is a design issue for private instance variables that you wish to keep hidden. Your suggestion to make them all public is also a design issue and if I was to see a long list of public variables at the beginning of a class (unexplained with javadoc comments) I would be very puzzled indeed.
    Eclipse will automate the generation of accessors and mutators for you and also has a refactoring tool too - both are extremely useful

  • Question about final instance variables

    Hi, I recently have come across a situation that I realized I did not understand and I could not find the answer after a bit of googling and searching the forum so I thought I would quickly pose the question to the crowd. Basically I want to know if declaring a final instance variable and assigning it to an existing Object will make an immutable copy of that Object. For example:
    Dimension myDims;
    public void someMethod()
    myDims = new Dimension(320, 240);
    doSomething();
    public void doSomething()
    final myFinalDims = myDims;
    This is not real code (obviously) and I made it quickly just to get my point across. Basically my question is if I create an Anonymous Inner class within the doSomething() method that accesses the myFinalDims variable, will the inner class actually access the myDims variable (which could have its value changed before the inner class accesses the variable) or will it be accessing a copy of the myDims Object that will have the same value as when the final variable was declared and instantiated?

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

  • About "method", "instance variable" and "constructor"

    Does a method need to be initialise?? if yes, how to write the code?
    for example,is it:
    public String mymethod( String args[]); ?
    public double mymethod2 (); ?
    what is the meaning of "instance variable" and "constructor"?
    Please help.....THANKS!

    Previously posted to this OP:
    Read the Java Tutorial: Learning the Java Language.
    http://java.sun.com/docs/books/tutorial/java/index.html
    � {�                                                                                                                                                                                                                                                                                                   

  • Should i initialize the instance variables or not?

    hi guys ,i am trying to learn java therefore if i miss something sorry.
    for example i have like this a class
    is it good thing to always initialize those variables or initialize like in this exam and initialize with constructor too ?
    public class SomeClass
         private double principal=1.0;
         private double rate=0.1;
         private int    years=1;
         private int    times=1;
         public static void main(String[] args)
    }

    878144 wrote:
    i guess i explicitly initialize them or i dont however java does it for me even i dont explicitly say int variable=0; however java will do it i guess also it doesnt make sense to me i do or compiler does.No idea what you're saying here. Try writing proper sentences with proper capitalization, grammar, spelling, and punctuation.
    why some people say yes some of them say no.if u dont do it then java does it also same thing.Reason to do it: Makes it clear what you want the initial value to be, and that you didn't forget to initialize it.
    Reasons not to do it: Redundant and cluttersome. Also, can lead to unexpected behavior in some cases involving subclasses.
    Ultimately, the decision is more about personal preference than anything.

  • Retrieve environment variables (but not classpath or other java ones..)

    Hi,
    Does somebody know another way than System.getPropriety() to retrieve a environment (system) variable? I have a variable so-called CSServer designing a path, and I do not succeed to retrieve it from a Java program.
    Any ideas?
    Thanks
    Richie

    I once implemented it by creating a process that executedecho %<yourVar>%and reading the output, but I'm not very proud of it.
    For other options, search the forums.
    Kind regards,
      Levi

  • Siteminder authentication on j2ee Dialog Instances only but not on C.I

    I am doing an Siteminder external authentication implementation on SAP
    Enterprise Portal 6.40 SP16.I have a configuration that want somehow to
    validate.
    The issue is that the J2EE Dialog Instances should be protected by SM
    Agent (they are the load-balanced nodes with the Apache web agent) but
    the Central Instance (which will run on a separate node) protected just
    with the default basic authentication supported by SAP and not with the
    SM Agent. The idea is to be able to access the CI without going through
    the Front Web Instances for troubleshooting purposes.
    Can we support them on this & in what form of configuration?
    I appreciate your comments on this.
    Thanks
    Tagore

    ok I will try to add BasicPasswordLoginModule and check it out .after that as you said when I access url http://server:50000/irj -> it should directly go to portal  with default authentication (not siteminder).
    I'm still wondering without customizing authscheme.xml how the siteminder is doing authentication  as per your scenario explained in ur previous mail.
    we have customized the in httpd.conf file in   apache server like  below..
    <VirtualHost server:80>
        ServerName xxxxxx
    Alias /siteminderagent/pwcgi/ /usr/netegrity/webagent/pw/
        <Directory /usr/netegrity/webagent/pw/>
            Options Indexes MultiViews ExecCGI
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    xxxxxx
    xxxxx
         ProxyPass       /irj/  http://server:50000/irj/
         ProxyPassReverse /irj/ http://server:50000/irj/
    </VirtualHost>
    APACHE deafult port 80 will listen ur portal url access http://server/irj -> pass this resource request to webagent and  check if or not resource proteced in siteminder policy server and does authentication .Once its autheticatated sitmeinder provide  user id  in the form header to j2ee.
    if you try to  access  the  portal by giving following url http://server:50000/irj will not work .
    could you tell me the 
    Note: in our scenario whe have installed both webserver (IBM HTTP APACHE 6.X)and web agent & ERP AGENT & PORTAL SERVER  installed on same box.
    Can you send me  doc how you custmozed ur webserver for proxy & reverse proxy  to my e-mail id :[email protected]
    anyhow may I know your e-mail id ?
    Thanks
    Tagore

  • HT3529 My imessages say delivered about 15 messages up but not sending my message.

    it doesn't say anything else like not delivered and i can contact other contacts. i have contacted them before but it isn't sending and i'm not sure if i am or am not recieving.
    Please help

    basically, is it delivered or not my message as it is playing up!

  • HT4528 i5 is complaining about two genuine Lightning cords not being compatible with device, that previously were just fine. Did an update received muck this up??

    I've had my i5 for over a year now. I received a lightning cord with the phone and bought a second (for backup) and now both are telling me there are compatiblity issues. My iHome, which I usually use to charge my phone at night (via it's lightning docking station) is doing the same. It would seem an update brought this on. I could reset my phone, but I don't want to lose/re-set up everything. I can't be the only one

    it may be an update that became corrupt during installation
    hundreds of millions of users world wide do not have this issue
    Reset ( no data lost ) and then if required restore with backup and finally as new to see if that fixes it

  • HT5312 Okay, this explains about the rescue email, but not about resetting your security questions? Help please?

    I have a bad memory and I can't remember the answers to my security questions, so I need to reset them, although I have no clue how to do that....

    Click here and request assistance.
    (75393)

  • When can I make instance variables public?

    I noticed that some of the in-built Java classes have public instance variables, for example in Rectangle the variables x, y, width and height are all directly accessible from outside. When is it okay to make public instance variables? Is it when they are primitive types? I thought maybe it is when they are final variables - but that can't be the case because you can directly modify the Rectangle's public instance variables.
    I've always used getter and setter methods in my objects because I was told "making instance variables public is bad". But obviously this isn't necessarily the case (unless the guys at Java are bad programmers). I think directly accessing the instance variables makes for much neater and more readable code. Is there any convention or best-practise guidelines on when I can or can not make them public?
    P.S. I also just "don't get" why you can't make them public if you're just going to provide a getter and setter method anyway... what's the difference? I suppose the theory is that the setter method should do some checking to make sure the input is valid. But what if the setter method just accepts -anything- of the appropriate type (accepts any Rectangle, for example)? What's the use of hiding the instance variables?
    teach me.
    Thanks. ;-)

    For the most part, it is true that making instance member variables other than private is not a good idea. This concept, known in OO circles as "information hiding", typically allows the greatest flexibility in internal implementation of a class, since you can change the internal structure of the class without affecting the clients that use the class.
    Let me add that Sun's programmers are a team, and teams have members of differing capabilities.
    It is also true that there may be cases where exposing instance variables is unlikely to cause problems. Simple classes, or very stable classes that will not change are some examples, but not all.
    Following a guideline blindly is not a good idea either. You need to evaluate each instance in which you decide you might want to deviate from "good programming practices". Still, best practices are best practices for a reason. It is best to understand them, and then decide if you can violate them.
    For my own part, I don't think it is "neater" to expose such variables, and I have personally had to deal with situations where a change in a class's internal structure was extremely painful because the original developer chose to make all his instance variables public.
    {?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Inheritance - instance variable initialization

    Hi all.
    I have a question regarding inherited instance variables.
    class Animal {
       int weight;
       int age = 10;
    class Dog extends Animal {
       String name;
    class Test {
       public static void main(String[] args) {
          new Dog();
    }This is just an arbitrary code example.
    When new Dog() is invoked, I understand that it's instance variable "name" is give the default
    type value of null before Dog's default constructor's call to super() is invoked.But Im a little perplexed about
    Animals instance variables. I assume that like Dog, Animals instance variables are given their default type values
    of 0 & 0 respectively, before Animals invocation of super(); What im unclear about is that at the point that weight and age are given their default type values, are Dog's inherited weight and age variables set to 0 aswell at that exact moment? Or are Dog's inherited weight and age variables only assigned their values after Animals constructor fully completes because initialization values are only assigned to a classes instance variables after it's call to super().
    Many thanks & best regards.

    Boeing-737 wrote:
    calvino_ind wrote:
    Boeing-737 wrote:
    newark wrote:
    why not throw in some print statements and find out?Super() or this() have to be the very first statement in a constructor..
    Also you cannot access any instance variables until after super or this.
    :-S
    Kind regardsbut if you add the "print" statement in animal constructor, you can easily see what happened to the attributes of Dog ; that s the trick to print "before" super()You can never add a print before super(). It's a rule of thumb, super() and this() must always be the first statements
    in a constructor, whether added implicitly by the compiler or not. In this case there are 2 default constructors (inserted by the compiler), each with a super() invocation. Even if i added them myself and tried to print before super(), the compiler would complain.
    Thanks for the help & regards.you didn't understand what i meant ; take a look at that:
    class Animal {
       int weight;
       int age = 10;
       public Animal() {
           Dog thisAsADog = (Dog) this;
          System.out.println(thisAsADog.name);
          System.out.println(thisAsADog.x);
    class Dog extends Animal {
       String name;
       int x = 10;
    public class Test {
       public static void main(String[] args) {
          new Dog();
    }this way you will know what really does happen

  • Inheritance & instance variables

    Okay, this just went against everything I thought I knew about inheritance and Java...
    So I wrote something like the code below, and when I declared
    ClassB cb = new ClassB();
    cb.variable2 was set to "". I traced it line-by-line in JBuilder's debugger, and I watched it set it to "bar" with my very own eyes, and then the tracer went to the "String variable2 = "";" line AFTER it ran the constructor. Is that supposed to happen?
    class ClassA{
         String variable1 = "";
         ClassA()
             parse();
         protected void parse()
              variable1 = "foo";
    class ClassB extends ClassA
        String variable2 = "";
        ClassB()
            super();
        protected void parse()
            super.parse();
            variable2 = "bar";

    And also: for those of you who said "never use an
    overridable method in the constructor," does this mean
    that every time you create a subclass, you must write
    a constructor that initializes all of the instance
    variables? Not exactly sure what you mean by "initializes all of the instance variables." You certainly don't need to explicitly initialize each of your object's fields in the constructor; in some cases, you won't know their values at that time.
    Doesn't this cause you to have to change all the subclasses
    individual subclasses if you ever needed to remove or change
    a superclass' instance variable (for example)?No, and this comes back to my point that a class is only responsible for the fields that it declares. If you don't try to change your superclass' fields directly, then you're not dependent on how it's implemented. Instead, you should call the appropriate superclass constructor. For example:
    public class XXX
        protected Map     _data;
        public XXX()
            _data = new HashMap();
        public XXX( Map data )
            _data = data;
    }Let's say that you now want to create class YYY, which extends XXX but uses a TreeMap instead of a HashMap. You could simply access "_data" directly; after all, it's "protected" and not "private". However, this introduces a dependency: class XXX now cannot change field "_data" without breaking class YYY. Instead, you should call the second constructor, which initializes the field from passed data:
        public YYY()
            super(new TreeMap());
        //...There are still ways that this example could break ... for example, the implementor of XXX could decide that the second constructor should copy the passed Map. There are ways to avoid this, but we won't go into those here :-)

  • JDEVELOPER 10G, ADF BC: Passivate static instance variables in AM?

    I understand the need to passivate/activate instance variables but what about static instance variables within an application module?
    Thanks,
    Wes

    Static variables - being class variables and not instance variables - persist without a need for passivation. Is there a particular reason or scenario why to use static variables? You have to consider that since all AM instances will share it, changing it in one AM instance - i.e. one user session - will affect all other AM instances - i.e. all other user sessions! You also have to consider the implications of multithreading when attempting to modify the static variable.

  • Renaming instance variable VS use of "this."

    Open Topic:
    Do you prefer this code?
    private var _myVar:int;
    public function myClassConstructor(value:int) {
         _myVar = value;
    or this code? (JAVA style)
    private var myVar:int;
    public function myClassConstructor(myVar:int) {
         this.myVar = myVar;
    Discuss the pros and cons, especially if performance is involved.
    You have 10 minutes... I will be collecting the papers

    Bertrand G. wrote:
    So no one is concerned about any performance issues using 'this'... I have seen somewhere that using 'this' in C++ is not as efficient as renaming the variable, because it makes an object instantiation or something like that.
    Most people will go for clarity of purpose in the code in preference to performance, simply because performance is not a critical factor for MOST purposes.
    I personally prefer using this for the setters and getters, this way I can have the same variable name for both the method parameters and the class variable.
    Just my 2 cents...
    I think the usual practice for getters and setters is to have a private variable for the instance variable and to name it with an underscore prefix to indicate that the variable is private. In that way references to the private variable are distinct to the variable name used in the setter and getter. In any event, in my setter I invariably name the parameter with the new value "newValue" or "newWhatever", some people just use "pWhatever" to indicate that variables have been passed as parameters, so the use of "this" is not required.
    I don't see the use of "this" as particularly relevant to performance, or getters and setters, and I would recommend naming private variables with an underscore prefix to indicate the use of a private instance variable, though not everyone follows this convention and may use other conventions, or indeed no convention at all.
    Paul

Maybe you are looking for