Pintu Ranjan Sai
CoreJava
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

Sir, What is the difference between pass by value and pass by reference. can u give an example?

View Answers

August 10, 2011 at 4:35 PM


Pass by value calls a function or returns a value based on the number or "value".While Pass by reference calls a function and passes a pointer to a memory location that contains the value.

Pass By Value: It refers to pass the variables or a constant that holds the primitive data type to a method.

Example:

public class PassByValue{
public static void display(int a){
a=5;
System.out.println(a);
}
public static void main(String[]args){
int i=20;
System.out.println(i);
display(i);

}
}

Pass By Reference: It refers to pass an object variable to a method.

Example:

public class PassByRefernce{
public static void display(StringBuffer sb){
sb=sb.insert(8,"to");
System.out.println(sb);
}
public static void main(String[]args){
StringBuffer sb1=new StringBuffer("Welcome RoseIndia");
System.out.println(sb1);
display(sb1);
}
}









Related Pages:
CoreJava Project
CoreJava Project  Hi Sir, I need a simple project(using core Java, Swings, JDBC) on core Java... If you have please send to my account
corejava - Java Beginners
corejava pass by value semantics  Example of pass by value semantics in Core Java.  Hi friend,Java passes parameters to methods using pass by value semantics. That is, a copy of the value of each of the specified
JList
JList  pls tell me about the concept the JList in corejava? and tell me a suitable example
core java - Java Beginners
core java  how to create a login page using only corejava(not servlets,jsp,hibernate,springs,structs)and that created loginpage contains database(ms-access) the database contains data what ever u r enter and automatically date
Java Locale
/corejava/javatext/parseAndFormatDateUsingLocale.html Thanks
Eclipse - IDE Questions
Eclipse  Hi To All.. I am new to ECLIPSE IDE. Please suggest me any book which can give me complete idea of setting environment and development with basic to advance development of java like(corejava,servlet,jsp,struts,ejb
What is Locale - Java Beginners
://www.roseindia.net/tutorial/java/corejava/javatext
HOW TO BECOME A GOOD PROGRAMMER
HOW TO BECOME A GOOD PROGRAMMER  I want to know how to become good programmer   Hi Friend, Please go through the following link: CoreJava Tutorials Here you will get lot of examples with illustration where you can
autentication & authorisation - JSP-Servlet
/interviewquestions/corejava/null-marker-interfaces-in-java.shtml Thanks
how to count words in string using java
how to count words in string using java  how to count words in string using corejava   Hi Friend, Try the following code: import java.util.*; class CountWords{ public static void main(String[] args
Inter Thread Communication
://www.devmanuals.com/tutorials/java/corejava/InterthreadCommunication.html
Factorial Program in Java
"); } } } Output C:\Documents and Settings\bharat\Desktop\bipul\CoreJava\Swing Example...\bipul\CoreJava\Swing Example\Factorial> java Factorial1 enter
using oops concepts - Development process
total source code in corejava using oops concepts.  Hi
Interthread Communication in Java
. This tells the Consumer that it should now remove it. package corejava
help me in these - Java Interview Questions
use the corejava.*  Hi Friend, 1) import java.util.*; public class
Mutliple files upload
; if (skilltype == "Java") { list = new Array("CoreJava","J2EE","J2SE..."); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
; if (skilltype == "Java") { list = new Array("CoreJava","J2EE","J2SE..."); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
; if (skilltype == "Java") { list = new Array("CoreJava","J2EE","J2SE..."); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
; if (skilltype == "Java") { list = new Array("CoreJava","J2EE","J2SE..."); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
== "Java") { list = new Array("CoreJava","J2EE","J2SE..."); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.