Constructor calls in BlazeDS?

I have a Java POJO that accesses a database. It establishes a connection to the database in the constructor, the uses that connection in each call to query the database.
However, the query time is VERY slow, PAINFULLY slow. I suspect that the constructor is being called each time the query method is called.
I am new to BlazeDS, so i am curious about a few things:
1- is the constructor called each time i make a call to the remote object?
2-is it possible to instantiate the object and keep it in memory so i can make references to the instantiated object instead?
3-Would this be facilitated using EJB or Spring Framework? I am looking into these, but don't know enough yet to make the call myself.
ANY information you can provide is GREATLY appreciated....

sorry, i REALLY need this answered, if possible, so i'm going to BUMP it just this once!

Similar Messages

  • Multiple times constructors calling in Myfaces

    Hi
    i m fasing multiple times constructor calling for myfaces programs
    i have created a small web appl. with one text box and one submit button, to test this behaviour.
    i have used this sample to
    get web page
    enter some text value
    submit the page
    and atlast page get returned to me
    i don't understand the multiple times consturctor calling and exact sequence of Getter/Setter calling?
    Following are details -
    faces-config.xml
    <managed-bean>
    <managed-bean-name>fileUploadBean</managed-bean-name>
    <managed-bean-class>com.dbschenker.dts.model.backingbean.FileUpload</managed-bean-class>
    <manged-bean-scope>request</manged-bean-scope>
    </managed-bean>
    jsp file
    <h:inputText id="txtSample" value="#{fileUploadBean.txtName}"/>
    <h:commandButton action="#{fileUploadBean.uploadFile}"
    image="../../images/upload_0.png"
    onmouseover="this.src='../../images/upload_0.png'"
    onmouseout="this.src='../../images/upload_1.png'"
    onclick="return true;"/>
    Backing bean
    public class FileUpload {
    private String txtName;
    public void setTxtName(String txtName) {
    System.out.println("Calling Setter... ");
    this.txtName= txtName;
    public String getTxtName() {
    System.out.println("Calling Getter... ");
    return txtName==null?"":this.txtName;
    public FileUpload() {
    System.out.println("Calling Constructor... ");
    public String uploadFile() {
    System.out.println("Upload Form Submitted... ");
    return "";
    Output to Console
    Calling Constructor...
    Calling Getter...
    Calling Constructor...
    Calling Constructor...
    Calling Getter...
    Calling Constructor...
    Calling Setter...
    Calling Constructor...
    Upload Form Submitted...
    Calling Constructor...
    Calling Getter...

    Hi
    that blog was really good and in depth...
    but i have one real time problem with multiple time constructor calling
    if you replace text box with file upload tag in my earlier sample program and then following is out put ...
    Calling Constructor...
    getUploadedFile()...
    Calling Constructor...
    getUploadedFile()...
    Calling Constructor...
    setUploadedFile()...
    Uploaded File Name - D:\AsnUploadTemplate02.XLS
    Calling Constructor... ------------------(.1
    Upload Form Submitted...
    java.lang.NullPointerException
         at com.dbschenker.dts.model.backingbean.FileUpload.uploadFile(FileUpload.java:40)
    ----------- trailing exception stack trace...
    Calling Constructor...
    getUploadedFile()...
    form this output u can find that my UploadedFile backing bean object gets null just before form submit method...
    whereas its has been properly instantiated in setter method,
    if constructor (1 wasn't call then object (uploadedFile) can be found in method (FileUpload.uploadFile)
    i have also tried to make scope of backing bean Session , but constructor, getter & setter calling sequence doesn't different even after.
    i have also considered both of your blog as ---
    http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html
    http://balusc.blogspot.com/2008/02/uploading-files-with-jsf.html
    but my problem stands as it is
    kindly help

  • Oracle Object Type Constructor Called Multiple Times

    I have an object type with a custom constructor. In SQL, when I reference the attributes the constructor is called multiple times in Oracle 11.2.0.4.
    Why is the constructor called multiple times?
    How do I stop it?
    My current work around is to reference the attributes and use the /*+ materialize */ hint.
    Problem Setup
        create or replace type Foo as object
          Bar1 NUMBER,
          Bar2 NUMBER,
          Bar3 NUMBER,
          CONSTRUCTOR FUNCTION Foo(p_Bar1 NUMBER, p_Bar2 NUMBER, p_Bar3 NUMBER)
            RETURN SELF AS RESULT
            DETERMINISTIC
        create or replace type body Foo is
          -- Member procedures and functions
          CONSTRUCTOR FUNCTION Foo(p_Bar1 NUMBER, p_Bar2 NUMBER, p_Bar3 NUMBER)
            RETURN SELF AS RESULT
            DETERMINISTIC
          AS
          BEGIN
            SELF.Bar1 := p_Bar1;
            SELF.Bar2 := p_Bar2;
            SELF.Bar3 := p_Bar3;
            dbms_output.put_line('Foo Constructor Called');
            RETURN;
          END;
        end;
    Problem
        -- Constructor is called 6 times!
        -- Once for each column and once for each predicate in the where clause.
        SELECT x.f.bar1 AS bar1, x.f.bar2 AS bar2, x.f.bar3 AS bar3, f
        FROM (
          SELECT foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3) f
          FROM dual d
        ) x
        WHERE x.f.bar1 = x.f.bar1 AND x.f.bar2 = x.f.bar2
    Output
    Foo Constructor Called
    Foo Constructor Called
    Foo Constructor Called
    Foo Constructor Called
    Foo Constructor Called
    Foo Constructor Called
    Workaround
        -- Work Around
        -- Constructor is called 3 times
        -- Once for each column in the inline view.
        -- Note, I removed column f (the object type) because it's not compatible with the materialize hint.
        WITH y AS (
          SELECT /*+ materialize */ x.f.bar1 AS bar1, x.f.bar2 AS bar2, x.f.bar3 AS bar3
          FROM (
            SELECT foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3) f
            FROM dual d
          ) x
        SELECT y.bar1, y.bar2, y.bar3
        FROM y
        WHERE y.bar1 = y.bar1 AND y.bar2 = y.bar2

    Another work-around is described in this thread... Accessing fields of a custom object type... which makes use of a collection type combined with the TABLE operator, like so...
    create or replace type FooTable as table of Foo;
    SELECT x.bar1 AS bar1, x.bar2 AS bar2, x.bar3 AS bar3, value(x) f
        FROM table(FooTable(
          foo(p_Bar1 => 1, p_Bar2 => 2, p_Bar3 => 3)
        )) x
        WHERE x.bar1 = x.bar1 AND x.bar2 = x.bar2
    BAR1 BAR2 BAR2 F
    1    2    3    (1, 2, 3)
    Foo Constructor Called
    Hope that helps...
    Gerard

  • Constructor calls in initialization lists

    Hello!
    I've encountered a difference in behavior between Solaris Studio 12 update 1 (CC: Sun C++ 5.10) and g++ that has me baffled.
    This is seen when a class's constructor features an initialization list before the start of its body. It seems that when I use a constructor call to initialize a member variable in the list, Solaris Studio calls that constructor once for the temporary object that is between parentheses and a second time to initialize my class's member variable with a copy constructor using the former temporary object. g++ by contrast calls that constructor only once.
    Here's a testcase that should hopefully clarify my point. The initialization list is in class Foo's constructor:
    File: "foo.h"
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    class Bar {
         size_t length;
    public:
         Bar(){
              std::cout << "Bar no args constructor. This: " << this << std::endl;
         Bar(size_t length){
              std::cout << "Bar length constructor. This: " << this << std::endl;
         Bar( const Bar& ) {
              std::cout << "Bar copy constructor. This: " << this << std::endl;
         virtual ~Bar(){
              std::cout << "Bar destructor. This:" << this << "\n";
    class Foo {
    private:
         int alpha;
         Bar bravo;
    public:
         Foo(int length);
    };File: "foo.cpp"
    #include "foo.h"
    Foo::Foo(int len): bravo(Bar(len)) {
         alpha=len;
    }File: "testcase.cpp"
    #include "foo.h"
    #include <unistd.h>
    int main( int argc, char** argv) {
         Foo testcase(4);
         usleep(2000000);
         std::cout << "Program end of life" << std::endl;
         return EXIT_SUCCESS;
    }When I compile these files with Solaris Studio...
    $ CC -library=Crun,Cstd  -o ./foo.o -c ./foo.cpp ; CC -library=Crun,Cstd -o ./sol_studio_testcase ./testcase.cpp ./foo.o...the testcase program produces this output:
    $ ./sol_studio_testcase
    Bar length constructor. This: 8047744
    Bar copy constructor. This: 804777c
    Bar destructor. This:8047744
    Program end of life
    Bar destructor. This:804777cBy contrast, when I use g++...
    g++ -o ./gfoo.o -c ./foo.cpp; g++ -o ./gplusplus_testcase ./testcase.cpp ./gfoo.o...the output shows only one call to a contructor for class Bar:
    Bar length constructor. This: 0x8047784
    Program end of life
    Bar destructor. This:0x8047784I'm working on a fairly large g++ codebase that makes heavy use of initialization lists throughout and relies on g++'s behavior in this regard (there's some vital memory management baked in the constructors and destructors).
    So would anyone here know if/how I could induce Solaris Studio's CC to behave like g++ in this case?
    Best regards,
    - Matt Boyer

    In the initialization
    Foo::Foo(int len): bravo(Bar(len)) { ... } the program semantics call for creating an anonymous temp object of type Bar that is used to initialize the bravo member of Foo, and later destroyed.
    The C++ standard allows, but does not require, an implementation to eliminate the temp object in some circumstances. The Sun/Oracle C++ compiler does not currently have this optimization.
    But there is no reason in this case to write bravo(Bar(len))+, because bravo is already of type Bar. If you write the simpler code bravo(len)+, no temp object is implied or created by the compiler.

  • Constructor Calls...

    I have read that the default constructor calls itself in each and every case. And it calls its super class constructor. Is it true?
    1- What are the cases in which default constructor is not needed?
    2- Is it Object's class default constructor that finally initializes instance variables or something else?

    not exactly.
    this is what happens:
    1. if there is an explicit call to another constructor with this(..) execute it.
    else if there is an explicite call to super(...) call the constructor of the super class
    else if we are not of type Object call super().
    2. init instance variables with explicitly given default values
    3. execute code in constructor.

  • Dynamic constructor call with arguments

    hey all i am quite new to this dynamic creation stuff
    basically i have an array of class literals i.e One.class Two.class Three.class
    etc
    i then loop through this array using the isInstance() method to find the objects correct type
    when i find this type i want to then create an object of this type with arguments passed to the constructor
    i know there is a way to create the object using a defualt non arg constructor call using newInstance()...
    so to repeat is there a way to dynamically create an object while passing arguments to the constructor?
    thanx rob

    Call getContstructor() on the class passing it an array of argument types. Then call newInstance() on the Constructor object that gets returned passing it an array of the arguments.

  • Parent constructor calls abstract method

    Hi everybody!
    I'm wondering if there is something wrong with java or if the idea is just too ill?
    Anyway, I think it would be great if this hierachy would work...
    Two classes A and B.
    Class A defines an astract method.
    In A's constructor this abstract method is called.
    Class B extends A and provides an implementation for the abstract method in A.
    Class B also defines a member variable that is set in B's implementation of the abstract method.
    In class' B constructor the parent constructor A() is called.
    example:
    public abstract class A {
      public A() {
        createComponents();
      public abstract void createComponents();
    public class B extends A {
      private String string = null;
      public B() {
        super();
        System.out.println("B::B() " + string);
      public void createComponents() {
        System.out.println("B::createComponents() begin");
        string = new String("test");
        System.out.println("B::createComponents() " + string);
      public void describe() {
        System.out.println("B::describe() " + string);
      public static void main(String[] args) {
        B b = new B();
        b.describe();
    }running the code above produces the following output:
    B::createComponents() begin
    B::createComponents() test
    B::B() null
    B::describe() null
    why is the string member variable null in B's constructor??
    thanks in advance
    Peter Bachl
    Polytechnic University of Upper Austria, Hagenberg
    [email protected]

    The answer is that the call of the super-constructor
    is allways done before the initialization
    of the member variable. That's all and that's the
    normal behavior.
    order :
    - initialization of static variables
    - call to the super-constructor
    - initialization of the instance variables
    - execution of the constructor
    Since this is the advanced forum it is relevant to point out that that is not exactly true.
    There is a step in java that 'initializes' member variables before any constructors are called, super or other wise.
    From the JLS 12.5...
    Otherwise, all the instance variables in the new object, including those declared in superclasses, are initialized to their default values (4.5.5)
    Using the following code as an example
      class MyClass
         int i1;
         int i2 = 1;
    .When creating an instance of the above there will be three 'initializations'
    // Part of object creation...
    i1 = 0; // The default value
    i2 = 0; // The default value
    // Part of construction...after super ctors called.
    i2 = 1; // The variable initializer (see step 4 of JLS 12.5)
    Unfortunately the descriptions are rather similar and so confusion can result as to when the assignment actually occurs.

  • JLabel constructor call problem

    Hello,
    I've problem with calling JLabel's constructor with passing String value to constructor.
    jobject jobjLabel;
    jclass JLabelClass;
    jmethodID mid;
    JLabelClass = (*env)->FindClass(env,"javax/swing/JLabel");
      if(JLabelClass == NULL) {
         printf("Can't find class JLabel\n");
         goto destroy;
      mid = (*env)->GetMethodID(env,JLabelClass,"<init>","(Ljava/lang/String;)V");
      jobjLabel = (*env)->NewObject(env,JLabelClass,mid,"Hello World");At line:
    jobjLabel = (*env)->NewObject(env,JLabelClass,mid,"Hello World");Main Thread exits with error code 1. I am sure that this line is true but I didn't find problem.
    Are there any methods to find errors before program exit?

    Probably I've found. I must pass constructor value as String object. Am I wrong?
    But Are there any methods to find our errors before program exit?
    Thanks in Advance

  • [OO Concept] Make a parent class perform code after constructor calls?

    Hello,
    I want to do something like this:
    class Parent {
       Parent(){
          // do some parent stuff
       private void postConstruction(){
          // parent and all subclasses have completed construction, now do some post-construction code
          // analyze some of the child construction stuff
    class Child extends Parent{
         Child(){
           // do some child stuff
         public static void main(String[] args){
              Child child = new Child();
    }I assume I am having this problem because of bad OO design. What would be the problem way to design this so that the parent can check the values of its members after all of its subclasses have been constructed?
    Thanks..

    You can certainly call the postConstruction() method from your Parent constructor. But then (as you can see) it will be called before anything in your Child constructor. Bad design? Yes, bad design of the Java language in my opinion. It should have allowed the user to control the order of initialization more. But it doesn't. So you can't do that. Which basically means you can't use the constructor to construct your objects. You'll have to call some other method where you aren't required to call super.postConstruction() at the beginning.

  • Remote Call to Blazeds and displaying the result set in grid

    Hi,
    I want to call a remote method using Flex application from Blazeds and display the values in DataGrid. Can anyone help in this ?
    -- I am using AMFChannel
    -- The method to be called is PolicyApnVO.getPoliciesApn()
    -- Please advice any correction if required
    Here is the mxml code :
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    creationComplete="initApp()" viewSourceURL="srcview/index.html">
        <!--
        Simple client to demonstrate runtime configuration of destinations.
        The "runtime-employee" destination is configured in
        EmployeeRuntimeRemotingDestination.java.
        -->
        <mx:Script>
            <![CDATA[
                import mx.messaging.ChannelSet;
                import mx.messaging.channels.AMFChannel;
                import mx.rpc.remoting.mxml.RemoteObject;
                [Bindable]
                public var srv:RemoteObject;
                public function initApp():void
                    var channel:AMFChannel = new AMFChannel("my-amf", "http://192.168.102.208:8400/policyAnalytics/messagebroker/amf");
                    var channelSet:ChannelSet = new ChannelSet();
                    channelSet.addChannel(channel);
                    srv = new RemoteObject();
                    srv.destination="runtime-policy";   
                    srv.channelSet = channelSet;
                    srv.PolicyApnVO.getPoliciesApn();
            ]]>
        </mx:Script>
        <mx:Panel title="Policy Details" width="100%" height="100%">
            <mx:DataGrid width="100%" height="100%" dataProvider="{srv.PolicyApnVO.getPoliciesApn.lastResult.data.result}"
                         showDataTips="true">
                <mx:columns>
                    <mx:DataGridColumn headerText="APN Id" dataField="apnId"/>
                    <mx:DataGridColumn headerText="APN Name" dataField="apnName"/>
                    <mx:DataGridColumn headerText="Policy ID" dataField="policyId"/>
                    <mx:DataGridColumn headerText="Policy Name" dataField="policyName"/>
                </mx:columns>
            </mx:DataGrid>
        </mx:Panel>
    </mx:Application>

    There may be other ways to do this but here's what I would do:
    1) add a results method to the remote object:
    src.result="onResult(event.result)";
    2) add the callback method: private function onResult(event : * = null)
    :void{
                                                         if(event is
    ArrayCollection)
                                                                myData =
    ArrayCollection(event);
    3) add the variable: private var myData:ArrayCollection;
    4) make the dataProvider for the grid use the my data :
    dataProvider=""
    You can probably avoid all this by adjusting your dataProvider. I am just
    not sure what it would be without experimenting. But definitely not what
    you have. Maybe just {svc.result}.

  • Constructor calling problem

    I was trying to do a this() constructor using such code in Ball class extending another class:
         abstract protected Color getNeutralColor();
         Ball(Color color) {
              super(color);
         Ball() {
              this(getNeutralColor());
         }And I got this compile-error:
    temp.java:20: cannot reference this before supertype constructor has been called
                    this(getNeutralColor());I thought that it is possible to jump to another this() constructor before calling super() in any one of them. Do I have to unbind those two and write separate code for each of them?

    I've put such code into Ball.java and still get the same compile-error:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public abstract class Ball extends RoundButton {
         protected Color color;
         abstract protected Color getNeutralColor();
         Ball(Color color) {
              super(color);
              this.color = color;
         Ball() {
              this(getNeutralColor());
    class CodeBall extends Ball {
         protected Color getNeutralColor() {
              return Color.white;
    }

  • Superclass Constructor calling overridable validation method

    I have the following class:
    public class SuperClass
       private int x;
       public SuperClass(int x)
          setX(x);
       protected void validateX(int x)
          if(x < 0)
             throw new IllegalArgumentException("x < 0");
       public int getX()
          return x;
       public void setX(int x)
          validateX(x);
          this.x = x;
    }My question is: How can I avoid calling setX(int) in the constructor besides simply dupicating validateX(int) in the constructor if I want to subclass SuperClass? [I read in a recent Java Fundamentals newsletter that calling overridable methods in superclass constructors is a bad idea int that it tends to destabilize the whole class hierarchy.  I don't want to make validateX(int) and setX(int) final.]

    Never call overrideable methods from constructors. No exceptions.
    You can use a factory method to validate your object after its created if you must.
    public class SuperClass
       private int x;
       public SuperClass()
       static SuperClass createSuperClass(int x){
             SuperClass sc = new SuperClass();
             sc.setX(x);
             return sc;
       protected void validateX(int x)
          if(x < 0)
             throw new IllegalArgumentException("x < 0");
       public int getX()
          return x;
       public void setX(int x)
          validateX(x);
          this.x = x;
    }Or you can use template method
    public class SuperClass
    private int x;
    public SuperClass(int x)
    setXImpl(x);
    final protected void validateX(int x)
    if(x < 0)
    throw new IllegalArgumentException("x < 0");
    public int getX()
    return x;
    final void setXImpl(int x){
    validateX(x);
    this.x = x;
    public void setX(int x)
    setXImpl(x);
    In general I don't like to call any overrideable methods from within my class. I try not to be anal about it though. My personal choice would be to duplicate the set method in the constructor. You should be constructing the object not using it. access instance variables not methods.

  • Problem in RPC call (flex,blazeds,spring,H2,tomcat,eclipse)

    Hi, I've problem displaying value from backend onto the flex UI. I'm using Flex,BlazeDS, Spring, H2 in my applicaiton (testdrive app).  
    I've basically added another flex project to the testdrive app i downloaded. everything is working fine except the intended rpc invoke. 
    pls find the code snippets for the related change below :  
    1. FlexHelloWorld.mxml 
    private function resultHandler(event:ResultEvent):void 
    //used for debugging - shows details about result 
    //returned by the Java class method 
    Alert.show("success... in flex"); 
    Alert.show( ObjectUtil.toString(event.result) ); 
    <mx:RemoteObject id="ro" destination="helloServiceDestination" result="resultHandler(event)" fault="faultHandler(event)"/> 
    <mx:Panel x="25" y="10" width="653" height="407" layout="vertical" title="Test Flex 3 Using Java" borderColor="#008040" fontFamily="Arial" fontWeight="bold" fontSize="13"> 
    <mx:Text text="Click The Button To Test Getting Data Into Flex From A Java Class" fontWeight="bold" width="250"/> 
      <mx:Button label="Get Hello World Mesg From Java!" click="ro.getHelloWorld()"/> 
    </mx:Panel> 
    2. remoting-config.xml in flex 
    <destination id="helloServiceDestination" channels="my-amf"> 
         <properties> 
             <source>org.springframework.flex.samples.example.HelloWorld</source> 
         </properties> 
      </destination> 
    3. flex-servlet.xml in spring 
    <flex:remoting-destination ref="helloServiceDestination" /> 
    4. app-config.xml in spring 
    <bean id="helloServiceDestination" class="org.springframework.flex.samples.example.HelloWorld">   
      </bean> 
    5. HelloWorld.java 
    package org.springframework.flex.samples.example; 
      * TODO Document HelloWorld 
      * <p /> 
      * @author Vinod.Jayakumar 
    public class HelloWorld { 
    public String getHelloWorld(){ 
         return "HelloFromJava"; 
    expected result : http://localhost:1977/testdrive/FlexHelloWorld.html on click of button in the screen a alert message "HelloFromJava" should be shown but i get the following error message :  
    (mx.rpc::Fault)#0 
       content = (null) 
       errorID = 0 
       faultCode = "InvokeFailed" 
       faultDetail = "Couldn't establish a connection to 'helloServiceDestination'" 
       faultString = "[MessagingError message='Destination 'helloServiceDestination' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" 
       message = "faultCode:InvokeFailed faultString:'[MessagingError message='Destination 'helloServiceDestination' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']' faultDetail:'Couldn't establish a connection to 'helloServiceDestination''" 
       name = "Error" 
       rootCause = (null) 
    Request you all to provide your valuable inputs. I know there's really something silly which has gone wrong

    Hi jvk180:
    Firstly, you should either need to define the destination in remoting-config.xml or in app-context.xml, but and in both places.
    Secondly, the error indicates that it is missing the channel information.
    Option 1:
    Assuming your bean "helloServiceDestination" uses other Spring beans, then:
    1. The right place to declare the destinations is in app-context.xml.
    2. In that case, you need to also define the channels that the destination will be exposed over. See documentation for how to do that.
    3. In your remote object declaration, you need to pass the channel set that gets used as well.
    <mx:ChannelSet id="cs">
       <mx:AMFChannel url="http://<yourServerName>:<yourServerPort>:/<yourContextRoot>/messagebroker/amf"/>
    </mx:ChannelSet>
    <mx:RemoteObject id="ro" destination="helloServiceDestination" channelset="{cs}" result="resultHandler(event)" fault="faultHandler(event)"/>
    Option 2:
    If you declare your destination, in remoting-config.xml, then you need to compile your swf with services-config.xml. Refer to documentation for how to do that.
    Hope that helps.
    Rohit

  • The constructor should be called just for the first object only.

    hello everybody!
    Please check out this code:
    class father
         father()
    class son1 extends father
         son1()
    class son2 extends father
         son2()
    public check
        public static void main( String args[] )
         son1 object1=new son1();
         son2 object2=new son2();
    In both the case for
    son1 object1=new son1();*
    son2 object2=new son2();*
    the constructor of the father class is invoked, i.e,
    father()
    +{+
    +}+
    What I want is the father constructor should be invoked only once i.e, when the first object(object1) is created and when the second object(object2) is created the father constructor should not be invoked. Is that possible in java, if yes, how?. Where should I make the changes in the given code?
    Please advice,
    Thank you.

    No, not the way you have designed it.
    What you have is
    Son1 IS A Father
    Son2 IS A Father
    Are you sure that is what you want, while the Sons will most likely end up as Fathers, as you only want the Father constructor called once it sounds like you want a
    Son1 HAS A Father.
    To do this you need to user composite relation.
    I.e.
    class Father {
       Father() {
           System.out.println( "Daddy!" );
    class Son {
      private final Father myFather;
       Father( Father myFather ) {
           this.myFather = myFather;
           System.out.println( "Son" );
    public static void main( String[] args ) {
        Father baba = new Father();
        Son jerry = new Son( baba );
        Son fred = new Son( baba );
    }

  • Inherit / extend class calls constructor...

    Hi,
    Class A extends class B like so:
    public class A extends B{}
    Why is class B's constructor called? I thought when A extends
    B, A gets all of B's methods and variables, great; but I don't need
    the constructor called because class B has already been created. I
    just want class A to inherit all of B's methods and variables. Can
    a class have two constructors, so when I extend class B an empty
    constructor is called but when I instantiate it the constructor
    with code is called?
    I feel like I’m missing something here.
    Thanks,
    4dplane

    Yep you are missing something. :)
    The constructor is just that -- it builds each instance of
    the class, puts it together if you will. Without a call to the
    superclass's constructor you won't get all its properties, methods,
    etc.
    You'll notice that the B constructor is even call first. That
    is to make sure that everything is ready and accessable to A
    It sounds like whatever you are trying to do isn't really a
    good candidate for extension.. Fill us in a bit more and perhaps we
    can come up with some ideas..

Maybe you are looking for

  • Process Chains (Urgent)

    Hi, Can any one pls tell me how to create process chains,as i am new to process chains. Pls give me the steps how to design the process chains. Thanks in Advance.

  • Color -  highlight words

    I'm using the highlight words column attribute for a report with a search parameter. I was wondering if there is a way to change the color of the text that is highlighted. Thanks in advance, Sam

  • Airport Express and 2wire gateway

    I have a 2wire 2700HG-D gateway and bought an Airport Express today to stream music to my stereo. When connecting the Airport Express in Client mode, I lose the ability to access the internet from my MacBook. I've followed the steps here: http://disc

  • Itunes freezes after playing 10+ songs

    Anyone else have this happen? I click around listening to samples, then after about 10 itunes will not play another. I can get it to work again by closing itunes and closing the process itunes.exe. Thanks.

  • How many licenses are required to be bought?

    Hello.. We are a section of ten in our organization with 1000+ manpower. To make a lot of work lighter, we have decided to go for Acrobat Pro. Is it possible to get license for all ten of us? And if yes, how much would it cost?