About 11,900,000 results
Open links in new tab
  1. How to use references in Java? - Stack Overflow

    Jan 17, 2011 · Java Objects are always accessed by a reference. Like the primitive types this reference is passed by value (e.g. copied). Since everything a programmer can access in java is passed by copying it (references, primitives) and there is no way to create a reference to a primitive type, any modification to a method parameter (references, primitives ...

  2. java - What are classes, references, and objects? - Stack Overflow

    Feb 10, 2012 · In Java, you can not access objects directly, you can only use references. Java does not copy or assign objects to each other. But you can copy and assign references to variables so they refer to the same object. Java methods are always pass-by-value, but the value could be an object's reference. So, if I have:

  3. What exactly is a reference in Java? - Stack Overflow

    Sep 4, 2015 · Java references are stongly typed: you can't "reinterpret" what lies on the other end of a reference unless you reinterpret it as a type that that object actually is. Also a short note about the word "reference": C++ has references that act quite differently from both pointers in C and references in Java (but I don't know enough about C++ to ...

  4. Is Java "pass-by-reference" or "pass-by-value"? - Stack Overflow

    Sep 3, 2008 · The Java Spec says that everything in Java is pass-by-value. There is no such thing as "pass-by-reference" in Java. The key to understanding this is that something like. Dog myDog; is not a Dog; it's actually a pointer to a Dog. The use of the term "reference" in Java is very misleading and is what causes most of the confusion here.

  5. java - Creating References to Objects - Stack Overflow

    Feb 19, 2013 · In Java, the new keyword returns a reference to a newly-constructed object. Therefore, in. String s = new String("foo"); the value of variable s is a reference to a String object. And then, if you were to do something like. String t = s; then you've set t to the same value as s, which is to say, it's now a reference to the same object.

  6. java - What's the difference between primitive and reference types ...

    It storing an address of the object it refers to. Reference or non-primitive data types have all the same size. and reference types can be used to call methods to perform certain operations. when declaring the reference type need to allocate memory. In Java, we used new keyword to allocate memory, or alternatively, call a factory method. Example:

  7. java - What is Object Reference Variable? - Stack Overflow

    Nov 25, 2015 · What is Object Reference variable in java? Simply, it is a variable whose type is an object type; i.e. some type that is either java.lang.Object or a subtype of java.lang.Object. Does the reference variable hold the memory address of the object? Probably yes, but possibly no. It depends on how the JVM represents object references.

  8. What is the meaning of "this" in Java? - Stack Overflow

    Dec 13, 2020 · this is a keyword in Java. Which can be used inside method or constructor of class. It(this) works as a reference to a current object whose method or constructor is being invoked. this keyword can be used to refer any member of current object from within an instance method or a constructor. Check the examples in the link for a clear understanding

  9. How to do "call by reference" in Java? - Stack Overflow

    Jul 18, 2021 · From Java The Complete Reference by Herbert Shildt 9th edition: "When you pass an object to a method, the situation changes dramatically, because objects are passed by what is effectively call-by-reference.

  10. Can I pass parameters by reference in Java? - Stack Overflow

    Jul 1, 2009 · Java is confusing because everything is passed by value. However for a parameter of reference type (i.e. not a parameter of primitive type) it is the reference itself which is passed by value, hence it appears to be pass-by-reference (and people often claim that it is). This is not the case, as shown by the following:

Refresh