Default initialisation of instance vars...

* This program currently prints "s before Super() finished is Hello"
* followed by "s after Super() finished is Hello"
* If the declaration 'String s' is changed to 'String s = null'
* the program prints "s after Super() finished is null"
* I know this is the wrong way to do things, but my question is
* Why isn't the initialisation of instance var s set to null even if
* I don't explicitly say 'String s = null' i.e. what happened to the
* default initialisation to null??
* I believe this is a potentially disastrous situation for our app
* which uses this type of initialisation extensively, however am
* having trouble convincing the designer of this.
class Super {
     public Super() {
          init();
     protected void init() {
class Sub extends Super {
     String s;
     public Sub() {
          super();
          System.out.println("s after Super() finished is " + s);
     protected void init() {
          s = "Hello!";
          System.out.println("s before Super() finished is " + s);
public class Test1 {
     public static void main(String[] args) {
          new Sub();

My suggestion to your designer:
An init() method shared between constructors (within a class) is great and centralised, but declare it final. If you can't declare it final, then declare it private, which statically links the method call so the base class will always call its own init method, never its sub-classes'.
Allowing a base class constructor to access a method in a subclass is potentially catastrophic!
The following demonstrates the initialisation order for classes...class Base {
    static {
        System.out.println("Base static initialization");
    private int base = init();
    public Base() {
        System.out.println("Base constructor");
    private int init() {
        System.out.println("Base initialization");
        return 1;
class Sub extends Base {
    static {
        System.out.println("Sub static initialization");
    private int sub = init();
    public Sub() {
        System.out.println("Sub constructor");
    private int init() {
        System.out.println("Sub initialization");
        return 2;
public class Test {
    public static void main(String[] args) {
        new Sub();
$ java Test
Base static initialization
Sub static initialization
Base initialization
Base constructor
Sub initialization
Sub constructorThe primary use for a constructor (IMHO) is to create an instance of a class that satisfies the class invariants. The logic within the constructor should then, in particular, ensure those invariants before exiting. If a constructor calls (directly or indirectly) an overridable method that is required to ensure the base class invariants, and the overriding method does not call make a call to the overriden method, then the base class invariants no longer hold.
Further, in the case of an init() method that all classes will call on construction, and in sub classes the first line will always call the super-class implementation (Thus preventing the above situation), in subclasses this init method will be called more than once - by each constructor in the chain - which may lower performance, or even break class invariants once again.
Finally, it's just too uncertain exactly what order your initialisation is going to complete in... except that at some point, you will have access to uninitialised members of your subclass.
This topic is one of those covered in Joshua Bloch's Effective Java, stating that a constructor should simply never call an overridable method. Go final, or go private.
If the designer doesn't listen, tell him (her?) s/he'll have to debug any initialisation timing problems that crop up, because no sane programmer will take that job :-)
-Troy

Similar Messages

  • Data modeler cannot connect to non-default sql server instance

    I've just started using DM, it installed and loaded fine, I got the jdbc drivers v2.0 from MS so that I can reverse engineer a couple of SQL-Server 2005 DB's.
    All worked just fine until I tried to connect to a machine with a named-sql-server instance.
    Normal way of doing this for sql-server is to add instance name to end of hostname in the hostname field, like this: "server10\inst01"
    but this gives me a cannot-connect-to-server10 error.
    I copied database over to a different server that has just a default sql-server instance and it worked fine. (both sql-server2005 and 2000!)
    I also tried the older 1.2 jdbc driver from MS against the sql-server 2005 named instance, no luck!
    I tried putting the instance name in front of the port number, that didn't work either.
    Am I just doing something wrong? or does DM need a special way of specifying the instance name on the sql-server host?

    Hello,
    you don't need instance name in order to connect. It's only host and port - probably named instance is not listening on default port. It'll be unfortunate if dynamic port assignment is used - but probably that won't be the case.
    I hope someone can tell you the port number.
    Philip

  • Automatic Global Activity: Obtain instance vars from "BusinessProcess"

    Hi,
    I need obtain instance vars from BusinessProcess, but i can't find the method for this operation.
    Can some one give me answers about this problem?
    Thank you...

    You have to use the PAPI api inside the designer.
    You have to do something like this:
    Instance myInstance = BusinessProcess.getInstance(Strign instanceId)
    Object instanceVarValue = myInstance.getVar("myInstanceVarName");
    Hope this helps.
    -Pal

  • SQL Server 2012 - 3 SQL clustered instances - one default/ two named instances - how assign/should assign static ports for named instances

    We have two physical servers hosting 3 SQL 2012 clustered instances, one default instance and two named instances.
    The default instance is using port 1433 and the two named instances are using dynamic port assignment.
    There is discussion about assigning static port numbers to the two named clustered SQL instances.
    What is considered best-practice?  For clustered named instances to have dynamic or static ports?
    Are there any pitfalls to assigning a static port to a named instance that is a cluster?
    Any help is greatly appreciated

    Hi RobinMCBC,
    In SQL server the default instance has a listener which listens on the fixed port which is TCP port 1433. And for the named instance the port on which the SQL server listens is random and is dynamically selected when the named instance of the SQL server
    starts.
    For Standalone instance of the SQL server we can change the dynamic port of the named instance to the static port by using SQL server configuration manager as other post, however, in case of the cluster, when we change the port no. of the named instance
    to the static port using the method described above, the port no. again changes back to the dynamic port after you restart the services. I recommend you changing the Dynamic port of the SQL Server to static port 
    on all the nodes , disabling and enabling the checkpointing to the quorum.
    For more information, you can review the following article about how to change the dynamic port of the SQL Server named instance to an static port in a SQL Server 2005 cluster.
    http://blogs.msdn.com/b/sqlserverfaq/archive/2008/06/02/how-to-change-the-dynamic-port-of-the-sql-server-named-instance-to-an-static-port-in-a-sql-server-2005-cluster.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • InfoView - Default view latest instance possible?

    Hi,
    I have an issue with InfoView, and the opening/viewing of Desktop Intelligence reports.
    The report I am talking about is scheduled on a daily basis (each night) so users don't have to refresh it every time they open it.
    To view it via InfoView, they have 2 options:
    a) The most usual and logical is to press the main hyperlink, the one which shows the name of the report. This is always showing you the report with the data from when you did a last refresh of it (report is set to not refresh data on open). Seemingly totally ignoring the scheduled instances!
    b) Users can also open via 'View Latest Instance'. This shows the last result(instance) of the last successful schedule of the report.
    This is confusing, since I would of course like the users to view the latest version(instance or whatever) of the report in both scenarios a and b.
    Is it possible to make the main hyperlink with the name of the report point to the latest instance of the report also?? Or am I wanting too much here???
    Thanks for any help!
    Frode

    Hi Frode,
    Yes you can... In the CMC, goto to BusinessObjects Enterprise Applications --> InfoView and the Object Listing property set (1) View the Object or (2) View the latest successful instance of the object.
    This is a global setting and affects all users so changing this setting here will make it the default setting for all users. No individual setting is available for a user.
    Regards
    Jacques

  • After change port for TCPIP PORT for default SQL Server instance (MSSQLSERVER), sql service and sql agent service did not started again

    Hi 
    -when i install default instance MSSQLSERVER i added a domain account as a service account,
    - when i change port for TCPIP PORT , and after sql service and sql agent service did not started again.
    it thrown error 
    The SQL Server (MSSQLSERVER) service failed to start due to the following error: 
    The service did not start due to a logon failure.
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Service Control Manager" Guid="{555908d1-a6d7-4695-8e1e-26931d2012f4}" EventSourceName="Service Control Manager" />
        <EventID Qualifiers="49152">7000</EventID>
        <Version>0</Version>
        <Level>2</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
    but when i add domain\sqservice account in administrators group these services started,
    1) here  why this change behavior  happened
    2i changed the port 1500
    adil

    HI
    the sql instance service is running with domain/sqlservice account , 
    - i stopped the sql service service
    - when i start it not started again and i found below error message
    Domain and account: MOJPORTAL\spsqlservice
    This service account does not have the required user right "Log on as a service."
    User Action
    Assign "Log on as a service" to the service account on this computer. You can use Local Security Settings (Secpol.msc) to do this.
     If this computer is a node in a cluster, check that this user right is assigned to the Cluster service account on all nodes in the cluster.
    If you have already assigned this user right to the service account, and the user right appears to be removed, 
    check with your domain administrator to find out if a Group Policy object associated with this node might be removing the right.
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Service Control Manager" Guid="{555908d1-a6d7-4695-8e1e-26931d2012f4}" EventSourceName="Service Control Manager" />
        <EventID Qualifiers="49152">7041</EventID>
        <Version>0</Version>
        <Level>2</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x8080000000000000</Keywords>
        <TimeCreated SystemTime="2015-04-24T17:12:58.326973300Z" />
        <EventRecordID>2177</EventRecordID>
        <Correlation />
        <Execution ProcessID="520" ThreadID="4044" />
        <Channel>System</Channel>
        <Computer>PORTALSQL1.mojportal.com</Computer>
        <Security />
      </System>
      <EventData>
        <Data Name="param1">MSSQL$xSQL</Data>
        <Data Name="param2">xxxL\spsqlservice</Data>
      </EventData>
    </Event>
    adil

  • Default initialisation of member variables and local variables

    I don't understand why member variables are initialized with default values by Java.
    Objects are initialized with "null" and primitives with "0", except boolean, which is initialized with "false".
    If these variables are used locally they are not initialized. The compiler requires them to be initialized by the programer, for example "String s = null".
    Why? What is the use of that difference?
    And why are arrays always initialized with default values, no matter if they are member variables or local variables? For example String[] s = new String[10]; s[0] to s[9] are initialized with "null", no matter if "s" is a local or member variable.
    Can someone please explain that strange difference, why it is used? To me it has no sense.

    Most of the time I have to initialize a local variable
    with "String s = null" in order to use it because
    otherwise the compile would complain. This is a cheap
    little trick, but I think everyone uses it.
    I wouldn't agree with "most of the time". The only cases where it is almost necessary to do that is when the variable should be initialized in a loop or a try-catch statement, and that doesn't happen too often.
    If local variables were initiliazed automatically without a warning it would be a Bad Thing: the compiler could tell when there is a possibility that a variable hasn't been assigned to and prevent manymanymany NullPointerExceptions on run time.
    And you didn't answer me why this principle is not
    used with arrays if it is so useful as you think.
    Possibly it is much more difficult to analyse the situation in the case of arrays; what if values are assigned to the elements in an order that depends on run time properties such as values returned from a random number generator.
    The more special rules one has to remember, the more
    likely one makes errors.I agree, but what is the rule to remember in this case?

  • What range TCP/IP Port should be give to default or named instance of sql server for security purpose to sql server ?

    Hi
    i am following technet article for Configure SQL Server security for SharePoint 2013 environments
    https://technet.microsoft.com/en-us/library/ff607733?f=255&MSPPError=-2147217396
    i want to change default TCPIP port from 1433 to which ports to change is securable for sql server
    i mean in what range 
    for example can i change to 1500 or 2000 or 1450 etc .
    if i assign like these portnos it will not affect to other ports in windows server 2012?
    adil

    I agree with Erland. (Always a good idea.) Changing the port doesn't help much to prevent attacks. If you decide to do that see Configure a Server to Listen on a Specific TCP Port (SQL Server Configuration Manager)
    http://msdn.microsoft.com/library/ms177440.aspx. Note
    "When selecting a port number, consult
    http://www.iana.org/assignments/port-numbers for a list of port numbers that are assigned to specific applications."
    It's important that you pick a number that isn't used by some other application. 
    Rick Byham, Microsoft, SQL Server Books Online, Implies no warranty

  • SQL Server 2012 Reporting Server Default USER group instance missing

    Hi
    We have installed SQL Server Reporting Services 2012 on Windows 2012 Server and we can’t see any SSRS default group on windows server group list say something like (SQLServerReportServerUser$TestServer$MSRS11_50.MSSQLSERVER)
    created as part of the installation
    we are migrating SQL Server 2008 R2 to SQL Server 2012, we were able to see default group for Reporting Server has been created in the earlier versions like SQLServerReportServerUser$TestServer$MSRS10_50.MSSQLSERVER
    Can you please assist whether we are missing anything in the SQL Server 2012 installation, this needs to be fixed as part of Report server user authentication 
    Thanks,
    Harish 

    Hello,
    You can use roles:
    http://msdn.microsoft.com/en-us/library/ms156406.aspx
    http://msdn.microsoft.com/en-us/library/ms159820(v=sql.110).aspx
    http://msdn.microsoft.com/en-us/library/ms156014.aspx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Purpose of default OC4J instance name (home)

    Hi
    During installation Oracle Application Server 10g Release 3, I've set another name than default OC4J instance (home), e.g. AS_Inst. When I've started server, I have two OC4J instances: default (home), and instance name, which I set during installation (AS_Inst). I'd like to ask, why there are two instances and what is purpose of default OC4J instance (home)?
    Thanks awfully for help.
    Regards

    That's default OC4J instance used for administration purposes... for example you want to deploy some application using Application Server Control, default home is required.
    HTH,
    Raj Mareddi
    http://www.freeoraclehelp.com

  • Repeatable row disabled by default. Need to enable all rows based on value in XML.

    I have a repeatable row in a table that is defaulted to read only.   If a certain value doesn't exist in the XML (populated != x), I want to make add / remove buttons visible and and make the text fields in the row and all subsequent instances Open.
    when populated !=x:
    This is the code:
    if (xfa.host.name != "XFAPresentationAgent" && this.resolveNode("populated").rawValue != "x") {
      oTargetField = this.resolveNode("#subform[2].tbl_people.person.name");
          oTargetField.access = "open";
      oTargetField = this.resolveNode("#subform[2].tbl_people.person.relationship");
          oTargetField.access = "open";
      oTargetField = this.resolveNode("#subform[2].tbl_people.person.age");
          oTargetField.access = "open";
    When I use this, it only enables the first row and none of the subsequent rows/instances.  
    Any assistance would be greatly appreciated!
    -Jeff

    Hi DCS_JeffW,
    I guess, you need to follow these steps:
    1) You need to find the number of repeating rows first. Assuming that "people.person" is the repeating instance:
                    var countOfPPInstances = xfa.resolveNode("....people.person").instanceManager.count;
    2) Modify your code as follws:
                    if (xfa.host.name != "XFAPresentationAgent" && this.resolveNode("populated").rawValue != "x")
                                    for(var i=0;i<countOfPPInstances;i++)
                                     xfa.resolveNode(“..people.person[“+i+”].name").access=”open”;
                                                      xfa.resolveNode(“..people.person[“+i+”].relationship").access=”open”;     
                                                      xfa.resolveNode(“..people.person[“+i+”].age").access=”open”;
    Let me know if this works. Alternatively, you can mail me your form @ [email protected]

  • Anyone have experience reusing "cell renderers" among multiple instances...

    I've implemented a 'light' cell renderer that sets all its attributes during the fetch to
    getCellRendererComponent()
    [in other words, all of the cell renderer instance vars are set during this call, wiping out the last objects settings]
    In the hopes of saving memory, I wanted to create one cell renderer instance and share it among 100's of the same type of object. Realizing that all paints should perform on the single threaded GUI-EVENT-THREAD, this operation should be safe.
    Anyone try this before?? Is it possible to reuse a single renderer instance among multiple Swing components? I look at the way Swing generates the default renderers if you don't specify one and it always returns a new instance ( the == is false ), yet each instance returned looks almost identical and contains references to the same objects with the same memory addresses.

    I'm pretty much sure that sharing one instance is the default behavior. Check out installDefault() of class javax.swing.plaf.basic.BasicListUI. Here, all JList instances are initialized with a single ListCellRenderer instance.
    Here's an example:public static void main(String[] arguments) {
            JFrame f = new JFrame();
            Vector v = new Vector();
            for (int i = 0; i < 10; i++)
                v.add(new Integer(i));
            JList l = new JList(v);
            l.setCellRenderer(new DefaultListCellRenderer() {
                private int val;
                public Component getListCellRendererComponent(
                    JList list,
                    Object value,
                    int index,
                    boolean isSelected,
                    boolean cellHasFocus) {
                    if (isSelected) {
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                    } else {
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                    setEnabled(list.isEnabled());
                    setBorder(
                        (cellHasFocus)
                            ? UIManager.getBorder("List.focusCellHighlightBorder")
                            : noFocusBorder);
                    val = ((Integer) value).intValue();
                    setPreferredSize(new Dimension(val * 12, 12));
                    return this;
                protected void paintComponent(Graphics g) {
                    g.setColor(getBackground());
                    g.fillRect(0, 0, getWidth(), getHeight());
                    g.setColor(getForeground());
                    for (int i = 0; i < val; i++)
                        g.fillOval(i * 12, 1, 10, 10);
            f.getContentPane().add(new JScrollPane(l));
            f.pack();
            f.show();
        }Hope that helps,
    bye

  • Not able to ssh from one EC2 instance to another

    I was trying to work with Oracle AMIs on Amazon cloud (EC2 instances).
    1) Created 2 EC2 instances of an Oracle database AMI ( based on Oracle Enterprise Linux (OEL) 5)
    2) I have opened ports in my security group associated with these EC2 instances.
    i) TCP 22 (SSH) - 0.0.0.0/0 ( Everybody)
    ii) ICMP ALL - 10.0.0.0/8 ( To enable ping functionality)
    So i am able to ping successfully from one EC2 to another with the public DNS, but ssh hangs
    a) Login to EC2 instance #1 from my desktop - SUCCESS
    b) ssh public_ip_of_instance_2 22  (HANGS).....
    c) Login to EC2 instance #2 from my desktop - SUCCESS
    d) ssh public_ip_of_instance_1 22 (HANGS).....
    Any ideas ? I worked with a default UBUNTU ec2 instance in amazon (public AMIs) and i did not face any problem doing an ssh from one EC2 to another.
    Is there something inside OEL (Oracle Enterprise Linux) that locks down ssh on port 22 from one instance to another ?
    Any ideas ?

    Hi All,
    I could solve it myself. Thanks for the time.
    The problem was I tried to navigate directly from the component ''BT125H_TASK' to the component 'CRMCMP_CMG', as I could not find any parent for BT125H_TASK earlier.
    Now I could find its parent component which is 'BT110M_ACT'.
    The outbound plug created in the task component has to be added to the component usage of 'BT110M_ACT' and the delegation should be done. The other things are the same. It works fine.
    Regards
    Vidhya

  • Is it possible to have 2 instances with the same name but different edition in the same server?

    Hi everybody!
    I have in a little trouble ....
    *** Scenario.
    Oracle Enterprise Edition 11gr2 over Oracle Solaris 11
    3 instances: PROD, QA, DEV
    1 ASM instance
    Listener ports: 1520, 1530 & 1540
               Those are production system
    *** The problem:
    Customer can't pay Oracle EE, they want to change to Oracle Std One
    Limitations:
    I cant have a similar system to test.
    *** My idea:
    Install Oracle Std One, in the same path:
    /u01/app/oracle/product/11.2.0/db          <-- EE
    /u01/app/oracle/product/11.2.0/db_one   <-- Std Ed One
    ASM:
    /u01/app/11.2.0/grid          <-- EE                    +ASM
    /u01/app/11.2.0/grid_one   <-- Std Ed One        +ASM1
    Create databases:
    Asign similar disks to +ASM1
    Create DGs on +ASM1
    Create databases: PROD, QA, DEV for Std Ed one
    - is it posible that they have same instance name?
    - if not, i suppose create as: PROD1, QA1, DEV1
    Configure Listener port : 1521, 1531 & 1541
    Migration technique:
    Create Tablespaces, schemas
    Lock users in EE
    down listener: 1520, 1530 & 1540
    Import data of final users in a window maintanance
    configure and up listener: 1521, 1531 & 1541
    Customer should test access and apps in new
    Please tell me if my Idea is reallistic, all comments are going to be very apreciated.

    sol.beach
    I suppose end customer use a port per database in order to separate in a logical way the access to the databases,
    i mean PROD, QA & DEV has the same users.
    Hemant K Chitale
    1. I've seen physical servers with 3 ASM instances: +ASM1, +ASM2, +ASM3
       on Solaris & Oracle 10g, I suppose is posible on 11g
    2. The sever has occupied 2  sockets (2 physical CPU), so I can use Oracle Standard Ed One.
    JohnWatson2
    Thanks for your comments.
    WadhahDaouehi
    1. - You cannot run two ASM instance simultaneously on one Server, but you can run many Oracle database simultaneously
          on the same server which they use the ASM as storage type.
      As a mentioned to  Hemant K Chitale, I've seen a system with several instances running
      About
         "you can run many Oracle database simultaneously on the same server which they use the ASM as storage type."
      I'm not sure if i can use the same ASM which is part of a current Enterprise Ed over the new installation with Oracle Std Ed One.
    2. - Why you want the same instance name?
    If it is about the service name, which has by default the same instance name, just you can create a different instance name
    and create the service name with the name that you wish.
    SQL> alter system set service_names='instance_name';
    Is a similar name, not the same
    PROD, QA & DEV
    PROD1, QA1 & DEV1
    I consider add "1" at the end to refer "Oracle Standar Ed One"
    But I agree with you, i can customize throught service_name.
    Regards,
    Abraham Mtz.

  • How do you change the default filename?

    I am using Photoshop 7.0.  I downloaded a Photoshop template which has buttons with text labels.  When I Save for Web, it names the output files by the name of the text on the buttons.  I don't want it to do this but rather the default way; for instance, my file is named primary.psd and I want the separate files to be named primary_01.jpg, primary_02.jpg, etc.  Where can I change this because I changed the text on the buttons but it has kept the original names.
    Also, is there a way to change the default location from "images" to something else?
    Thank you in advance.

    Take a look at this page from Version Tracker (I typed in "Safari search" and there seems to be a range of possibilities.)
    http://www.versiontracker.com/php/search.php?mode=basic&action=search&str=safari +search&plt%5B%5D=macosx&x=0&y=0

Maybe you are looking for

  • Lion Server File Sharing Crashes

    We have a brand new Mac Pro (12 core with 64GB of RAM) running OS X Lion Server in a corporate environment. The server is running only file sharing and software update servers, and we have around 40 users who need to be connected over AFP at all time

  • How do I put a photo slideshow on my Phone ?

    I have checked the manual, sought help and I still have a problem    I can get photos to sync back on my phone from my computer but I have a problem getting a slideshow to sync.    I thought it might be the format but my slideshow program has a tab f

  • HT201210 iOS 7 upgrade "Software Update Unavailable"

    I'm trying to upgrade my iPhone 5 to iOS 7 and am getting the following messege "Software Update Unavailable: Sofwate Update is not available at this time.  Try again later." How do I correct this? Thanks

  • Register AcroPDF.dll Windows XP

    How can I Register AcroPDF.dll of version 9.1.0.163 in Windows XP in 32 bit version,so that i can use as PDF viewer control in VS2005. Note from host: Please to do not duplicate your question in the subject line. The subject line is a brief sysnopsis

  • Unable to open app store

    Iam unable to open the app store..Please help me..