UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why string objects are immutable?

Asked by Last Modified  

12 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Expert in Java/J2ee technology

We cannot change the String object because String is immutable. Vice-versa is not the same. String is immutable because of the security. Sting is storing the data in String Pool which can be used by multiple reference of String object. So during creation of String it is searching in the Pool the value...
read more
We cannot change the String object because String is immutable. Vice-versa is not the same. String is immutable because of the security. Sting is storing the data in String Pool which can be used by multiple reference of String object. So during creation of String it is searching in the Pool the value is present or not. If present object is pointing to the String. So multiple object can refer to single value. read less
Comments

Computer Classes

String objects are immutable because of we can't change,if you try to alter their values, another object gets created
Comments

12 years of MNC company work experience on java ,J2ee technologies

In java the string objects are immutable ,that we can't change the object value .It provides the security in java.Once we create and passed the parameter as string ,In between the components nobody modify the String objects.It gives the security in communication among components in distribution envir...
Comments

Trainer

If the strings are not immutable, it would lead to serious security threat as it would allow to changes in the file containing it. Mutable strings could cause security problem in Reflection too, as the parameters in the methods being inspected are strings. Therefore in all these cases hashcode of the...
read more
If the strings are not immutable, it would lead to serious security threat as it would allow to changes in the file containing it. Mutable strings could cause security problem in Reflection too, as the parameters in the methods being inspected are strings. Therefore in all these cases hashcode of the string is frequently used in Java to know if its value is changed knowingly or unknowingly. read less
Comments

Tutor

Strings are immutable once created cannot be changed and hence cannot be eliminated but string builders are mutable.
Comments

Expert in Java/J2ee technology

The string is Immutable because String objects are stored in String pool. String pool are shared between multiple clients there is always a risk to updating the data. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead...
read more
The string is Immutable because String objects are stored in String pool. String pool are shared between multiple clients there is always a risk to updating the data. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference. read less
Comments

Java Tutor

String class is made Immutable to provide more efficiency. Its not that all time new object is created , there is concept of String Pool which is used for look up the existing objects
Comments

Trainer

Very good questions thanks for asasking The string is Immutable in Java because String objects are cached in String pool. Since cached String literals are shared between multiple clients there is always a risk, where one client's action would affect all another client. For example, if one client changes...
read more
Very good questions thanks for asasking The string is Immutable in Java because String objects are cached in String pool. Since cached String literals are shared between multiple clients there is always a risk, where one client's action would affect all another client. For example, if one client changes the value of String "Test" to "TEST", all other clients will also see that value as explained in the first example. Since caching of String objects was important from performance reason this risk was avoided by making String class Immutable. read less
Comments

Trainer

String is immutable cause of security parameters are typically represented as String in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed. In Synchronization and concurrency making String immutable automatically makes...
read more
String is immutable cause of security parameters are typically represented as String in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed. In Synchronization and concurrency making String immutable automatically makes them thread safe thereby solving the synchronization issues. Caching: when compiler optimizes your String objects, it sees that if two objects have same value (a="test", and b="test") and thus you need only one string object (for both a and b, these two will point to the same object). Class loading: String is used as arguments for class loading. If mutable, it could result in wrong class being loaded (because mutable objects change their state). read less
Comments

Trainer

In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable. Once string object is created its data or state can't be changed but a new string object is created.
Comments

View 10 more Answers

Related Questions

Which holds the future: Java or Python?
The future success of Java or Python depends on various factors, including industry trends, project requirements, and developer preferences. Both languages are widely used, with Java being prominent in...
Nikhil
0 0
5
If a class contains only a private constructor and no other constructor, is it possible to create object of that class? If yes how?
Yes, It is possible. But, Object can be created only with in that class (either in any method or block).
Shabbir
Who can provide good Java training with real-time but not institute?
I provide industry specific training to students. If interested check my profile. I used to provide training in Big Data, Java, Scala and Spark too.
Sridevi
0 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Observer Pattern in Java.
As I was going through the different source code files of the Java Util package, I found the implementation of the Observer Pattern ( see the Gang of Four books for more information on this pattern) in...

Introduction to Course Content
Video about what we are going to learn throughout the Java Training Session .

Priority in TestNG
public class Priority { @Test (priority=1)public void login() {System.out.println("login");} @Testpublic void email1() {System.out.println("email1");} @Test (priority=-2)public void email2() {System.out.println("email2");} //I...
S

Sarthak C.

0 0
0

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Interview Tip : Q1) Why Strings are immutable in java ? What happen if it was mutable in java?
As we all know that Strings in java are immutabe in nature, now the question comes why the creator made it immutable in nature, although this field used maximum in any java program. The answer to this...

Recommended Articles

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more