Search code examples
javajakarta-eecall-by-value

References of objects in Java EE. Difference for remote and local interfaces?


As far as I know, Java is only call-by-reference. If an entity has to go through a remote interface, can it still have a reference? Now the entity is basically in another container, how can it still have the reference of the object? In other words: Is it possible that entites that 'go through' remote interfaces are not just references, but a copy of the object (call-by-value)?

Sorry if that is a silly idea, but the whole call-by-reference (or pass by refrence?) concept is confusing me in Java EE.

EDIT: In other words: Are objects from session beans ALWAYS passed as a reference?


Solution

  • Java is always a call-by-value. Here is the example which will make things clear:

    class Operation{  
    int data=50;  
    
    void change(int data){  
      data=data+100;//changes will be in the local variable only  
    }  
    
    public static void main(String args[]){  
      Operation op=new Operation();  
      System.out.println("before change "+op.data);  
      op.change(500);  
      System.out.println("after change "+op.data);   
    

    }
    }

    Output:before change 50
           after change 50