How do you pass objects in Java? By reference? If so, give an example. Also, how do you display them in a JSP?
Printable View
How do you pass objects in Java? By reference? If so, give an example. Also, how do you display them in a JSP?
Tricky question. Everything in Java is passed by value. Objects are actually never passed, only references to objects. This makes it sound like objects are passed by reference but they are NOT.
Code wise, objects are passed like any other variable.
As far as JSP pages go, that's a pretty broad question. The most basic way is something like this:Code:Person guy = new Person();
Person girl = new Person();
guy.shakeHands(girl);
public class Person(){
public void shakeHands(Person shakee){
}
}
I know this works for return types of Strings and ints. It might work for others but I'm not 100% sure.Code:<%= object.toString(); %>