---
title: "Discussion on \"Pass by Reference vs Pass by Value\" | Hashnode"
description: "Discussion on \"Pass by Reference vs Pass by Value\". Introduction\nHave you ever faced a situation where you compared two strings using the \"==\" operator in Java, but it returned false even though the strings were equal? This can be a frustrating experience for Java coders. I made this mistake myself wh..."
url: "https://hashnode.com/posts/pass-by-reference-vs-pass-by-value/64286bb1aa3a8326fa3ac0cd"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Pass by Reference vs Pass by Value](https://iamvbenz.hashnode.dev/pass-by-reference-vs-pass-by-value?utm_source=hashnode&utm_medium=feed)

Introduction Have you ever faced a situation where you compared two strings using the "==" operator in Java, but it returned false even though the strings were equal? This can be a frustrating experience for Java coders. I made this mistake myself wh...

Apr 1, 2023 · 4 min read · iamvbenz.hashnode.dev  
Updated Apr 9, 2023  
Read the article

-   [#wemakedevs](https://hashnode.com/tag/wemakedevs)
-   [#java](https://hashnode.com/tag/java)
-   [#hashnode](https://hashnode.com/tag/hashnode)
-   [#pass-by-refernce-pass-by-value-in-java](https://hashnode.com/tag/pass-by-refernce-pass-by-value-in-java)

## Written by

[Sham Vijay](https://hashnode.com/@iamvbenz)

@iamvbenz · Chennai,India

  
[View profile](https://hashnode.com/@iamvbenz)

I am B.tech Student who is passionate about science and tech Currently learning solving leetcode and learning web development

## Responses 2

Markdown supported · ⌘↵ to post

[Wellington Domiciano](https://hashnode.com/@wldomiciano)

[Apr 5, 2023](https://hashnode.com/posts/pass-by-reference-vs-pass-by-value/64286bb1aa3a8326fa3ac0cd/comment/642cc560480bd310626c0711)

Your example for Pass by Reference section is wrong because the second println will print 10, not 20.

In Java we always pass values, never references, at least not in the same sense as in languages like C++ or C#.

In Java there are 2 kinds of values: primitive values and reference values.

When you pass an object as an argument, you are passing a reference value.

And changing the value of a reference type variable inside a method does not change the value of the variable outside.

But changing the state of a reference is not the same thing as changing the value of a variable.

[Sham Vijay](https://hashnode.com/@iamvbenz)

[Apr 5, 2023](https://hashnode.com/posts/pass-by-reference-vs-pass-by-value/64286bb1aa3a8326fa3ac0cd/comment/642cc560480bd310626c0711#reply-642ccbd1480bd310626c07d3)

Hey!! Sorry for the mistake, I'll edit it

[Uday kumar](https://hashnode.com/@Udaykumar2507)

[Apr 1, 2023](https://hashnode.com/posts/pass-by-reference-vs-pass-by-value/64286bb1aa3a8326fa3ac0cd/comment/642879a0d6d859da8c006cc1)

Helped a lot
