Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:59:20+00:00 2026-05-30T11:59:20+00:00

I read this comment here: Passing a String by Reference in Java? Yes, it’s

  • 0

I read this comment here: Passing a String by Reference in Java?

Yes, it’s a misconception. It’s a huge, widespread misconception. It
leads to an interview question I hate: (“how does Java pass
arguments”). I hate it because roughly half of the interviewers
actually seem to want the wrong answer (“primitives by value, objects
by reference”). The right answer takes longer to give, and seems to
confuse some of them. And they won’t be convinced: I swear I flunked a
tech screen because the CSMajor-type screener had heard the
misconception in college and believed it as gospel. Feh. – CPerkins
Aug 13 ’09 at 14:34

Can someone please explain, in terms that a new programmer can grasp, what is the difference between saying:

“In Java primitives are passed by value and objects are passed by reference.”

and:

“In Java nothing is passed by reference and references are passed by value.”?

Are both of these statements true in some sense? I don’t want to invite a rant parade, but this sounds like a really important concept, and one I still do not completely understand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:59:21+00:00Added an answer on May 30, 2026 at 11:59 am

    I believe the misconception lies in the fact that a variable can not contain an object to begin with. If you grasp that, then obviously variables can only contain references to objects (or primitive values). The step from there to realizing that references are passed by value (just as primitive values) is quite small.

    There is a really easy test you can do to figure out if a language supports pass by reference. Ask yourself if you can write a swap function in the language, i.e. something that works like

    x == A, y == B
    
    swap(x, y);
    
    x == B, y == A
    

    As a Java programmer you realize quickly that you can’t implement this in Java, thus you (correctly) draw the conclusion that Java does not have pass by reference.

    Returning to your sentences:

    • In Java primitives are passed by value and objects are passed by reference.

    This is false. I would argue that you can only pass something that is contained in a variable, and as I stated above, a variable can’t contain an object, thus you can’t pass an object at all in Java.

    • In Java nothing is passed by reference and references are passed by value.

    This is true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this comment in the OpenID post on the stackoverflow blog. Kibbee says
I have an XML string like this: <Summary>Foo</Summary><Description>Bar</Description> I want to read this into
I'm using this block of code (mostly copied from a PHP.net comment here -
I read this answer and its comments and I'm curious: Are there any reasons
Since I got TLDR (too long didn't read) comments, I stripped 90% of this
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read this post last night, and I noticed it was from 2006. I
I read This article and i found it interesting. To sum it up for
I read this story on slashdot today where they announce a new parallel programming
Having read this link on RBAR and this , my understanding of RBAR amounts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.