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 6204935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:11:01+00:00 2026-05-24T05:11:01+00:00

I have a socket which is currently connected. Socket s; //Connected socket If I

  • 0

I have a socket which is currently connected.

Socket s; //Connected socket

If I use:

 Socket d = s;

Will socket d be the same, connected socket? It depends if java is assigning by value or reference, in this case I would like it to assign by reference. I’m not sure what it’s going to do exactly so I’m asking here.

  • 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-24T05:11:02+00:00Added an answer on May 24, 2026 at 5:11 am

    Will socket d be the same, connected socket?

    Yes

    It depends if java is assigning by value or reference

    Java is entirely pass-by/assign-by value. The value being assigned here is a reference to the object. Think of it as an int that tells us what slot in memory the object is in.

    Continuing the int analogy:

    int a;
    int b;
    
    a = 5;
    b = a;
    a = 6;
    

    What’s b‘s value? 5, of course, the later assignment of 6 to a has nothing to do with the value stored in b.

    And so similarly:

    Socket d;
    Socket s;
    
    d = /* ... create and connect a socket... */;
    s = d;
    d = null;
    

    What’s the value of s? Right! It’s the reference to the connected socket object. The value in s (a reference to the socket) is completely unaffected by your assigning a different value to d.

    Now, of course, when d and s are pointing (referring) to the same object, naturally any time that object changes, you can see the change via d or s. All that d and s do is tell us where the object is, they don’t contain the object at all. They point to the memory that contains the object.

    Once you grasp that object references are primitives just like ints and have exactly the same behavior, understanding Java code gets a lot easier.

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

Sidebar

Related Questions

I have a socket application which I can use in local network, at home.
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
Say I have a resource (e.g. a filehandle or network socket) which has to
I have a flash (ActionScript 3.0) which uses socket connection to send data to
I have a call to Read on NetworkStream objeck, which uses Socket.Receive internally. Say
I have a class which I'm serialising to send over a unix socket and
I have a tcp socket sending three lines like this out2.println(message1\n); out2.println(message2\n); out2.println(message3\n); and
I currently have a WebSocket server (C#) and a client (JavaScript / HTML5). This
I have the DWORD socket in windows. I need to know if it is
I have an open socket to a remote terminal. Using the answer to Force

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.