Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 07-27-2017, 01:46 AM   #1
bhavnasingh482
Registered User
 
Join Date: Dec 2014
Posts: 98
Why String is final in Java?

Hi friends,
I would like to know,
Why String is final in Java?
bhavnasingh482 is offline   Reply With Quote

Old 02-12-2018, 04:12 AM   #2
spurtcommerce
Registered User
 
Join Date: Oct 2017
Posts: 29
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
__________________
Node js Ecommerce | Angularjs Ecommerce
spurtcommerce is offline   Reply With Quote
Old 02-13-2018, 10:40 PM   #3
GeorgeAlbie
Registered User
 
Join Date: Nov 2017
Posts: 305
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode)
GeorgeAlbie is offline   Reply With Quote
Old 02-16-2018, 03:01 AM   #4
albertomorrison
Registered User
 
Join Date: Dec 2017
Location: Santa Clara, California, USA
Posts: 91
Though true reasons of why String class was made final is best known to Java designers, and apart from that hint on security by James Gosling, I think following reasons also suggest Why String is Final or Immutable in Java.
1) String Pool
2) Security
3) Use of String in Class Loading Mechanism
4) Multithreading Benefits
5) Optimization and Performance
albertomorrison is offline   Reply With Quote
Old 02-20-2018, 10:20 PM   #5
samaron
Registered User
 
Join Date: Sep 2017
Posts: 314
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
samaron is offline   Reply With Quote
Old 02-23-2018, 03:07 AM   #6
smmexpertss
Registered User
 
Join Date: Sep 2015
Location: UK
Posts: 625
Once you assign a string object, that object can not be changed in memory. In summary, what you did is to change the reference of "a" to a new string object. Java String is immutable, String will Store the value in the form of object.
smmexpertss is offline   Reply With Quote
Old 02-26-2018, 02:04 AM   #7
samaron
Registered User
 
Join Date: Sep 2017
Posts: 314
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
samaron is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA Projects 2016 AcademicProject Java 2 09-21-2017 02:05 AM
Is String a data type in java? Kunal Java 2 04-02-2016 02:39 AM
Final Year JAVA Projects AcademicProject Post your ad here 0 02-01-2016 01:12 AM
The conclusion provided by the Black Hat Java Script andrebreton2121 Search Engine Optimization 6 10-17-2012 11:06 PM
biggest teature of String in java? cianfie Java 0 12-08-2011 08:03 PM


All times are GMT -7. The time now is 04:56 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.