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

How do I learn Java? From book or internet or a coaching?
It is good to learn Java from Coaching where you will get more exposure in learning at faster pace.
Suresh
0 0
7
Can you use abstract and final both with a method? Why?
No because we have to provide an abstract method with implementation in the subclass (the child class of the parent class in which the abstract method was declared). And for providing this implementation...
Sushil
Why Operator Overloading in not allowed in JAVA?
Java does not support operator overloading by programmers. This is not the same as stating that Java does not need operator overloading. Operator overloading is syntactic sugar to express an operation...
Ashish

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

Ask a Question

Related Lessons

What Is Java? Explain The History Of Java
i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java...

Demand of java in industry
Java is one of the widest use language in the industry all around the world As in software market more than 80% software, platform developed using java. Java comes in three flavours:- j2se for window based...

Prashant Tomer

0 0
0

CoreJAVA
Core Java Training High Level Course Content Trained by Java Architect 1. Core Java Programming Introduction of Java 2. Data types and Operators 3. Control Flow statements 4. OOPS and its application...
A

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

Software Testing
Software testing is a process of executing a program or application with the intent of finding the software bugs. It can also be stated as the process of validating and verifying that a software program...

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