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

187 views Asked by At

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?

2

There are 2 answers

1
Nakul91 On BEST ANSWER

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               
0
user2381681 On

It is the copy of the entity object not the reference, I mean that's why serialization of entity objects is very important here, serialization helps in getting the copy the entity object when it transfers through the remote interface not the reference, because this reference would have no value in another container..