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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:52:58+00:00 2026-05-24T13:52:58+00:00

I am using the OpenJDK Java compiler under Ubuntu. I wanted to convert a

  • 0

I am using the OpenJDK Java compiler under Ubuntu. I wanted to convert a character array to a string and when that seemed to have ended up giving ambiguous results, I tried to write a toString method of my own. In the process, I wrote a test program wherein (out of the fun of it) I tried to compile the following code.

class toString{
    public static void main(String[] args){
        string = "abc";
        string = string + "bcd";
        System.out.println(string);
    }
}

Now, I know that String objects in Java are immutable and the code should have in fact generated an error but to my surprise, it printed abcbcd to the console. Does this mean that String objects in Java are mutable or is there something wrong with the implementation of OpenJDK compiler in this case?

  • 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-24T13:53:00+00:00Added an answer on May 24, 2026 at 1:53 pm

    The difference is between References to an object and the object itself.

    String XXX = "xxx";
    

    Means:
    Make a new variable and assign the reference to an instance of object String that contains the literal string “xxx”.

    XXX = XXX + "yyy";
    

    Means:

    Get the reference to the object we have in variable named XXX.
    Make a new object of type String that contains the string literal “yyy”.
    Add them together executing the string + operator.
    This operation will create a new String object that contains the literal string “xxxyyy”.
    After all this, we put the reference to the new object again in the variable XXX.

    The old referenced object containing “xxx” is not used anymore but the content of it was never modified.

    As a counter proof, there is an example:

    String a = "abc";
    String b = "def";
    String c = a;
    
    a = a + b;
    
    System.out.println(a); // will print "abcdef".
    System.out.println(b); // will print "def".
    System.out.println(c); // will print "abc".
    
    // Now we compare references, in java == operator compare references, not the content of objects.
    
    System.out.println(a == a); // Will print true
    System.out.println(a == c); // Will print false, objects are not the same!
    
    a = c;
    
    System.out.println(a == c); // Will print true, now a and b points on the same instance.
    

    Object instance are something “abstract” that live in a portion of memory of your program. A reference variable is a reference to that portion of memory.
    You can access objects only through variables (or return values).

    A single object can have more than one variable pointing at it.

    String is immutable means that you cannot modify the content of that area of memory used by the String object, but of course, you are free to change and exchange references to it as you prefer.

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

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Configuration: I'm running stock Fedora 12 with the ant that Fedora ships: ant-1.7.1-12.fc12 java-1.6.0-openjdk-1.6.0.0-33.b16.fc12
I am a java newbie. I have been using Eclipse to test a simple
I'm running the following code on Ubuntu 10.10, using OpenJDK 1.6.0_18: package mypkg; public
Hi I installed openjdk1.6 in my machine using yum. yum install java-1.6.0-openjdk-devel it is
I have a web service application that I deployed successfully on Apache Tomcat using
We have problems playing audio files using JavaZoom's libraries on OpenJDK in Linux, although
I installed openjdk-6-jdk on my ubuntu box using apt-get. In system info jenkins is
I've made an app init function that I'm using both in Java and GWT
Using online interfaces to a version control system is a nice way to have

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.