Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
general knowledge
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
beans
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 


In Java how can we create immutable class?
Question Posted on 13 May 2021

Home >> Java >> Java Questions >> In Java how can we create immutable class?




In Java how can we create immutable class?
Below are the some important facts about how to create immutable class
(1)First we declare class as final so that it cannot be extended.
(2)Second we create all fields as private so that direct access is not allowed.
(3)Third we will not provide setter methods for variables.
(4)Fourth create all mutable fields final so that its value can be assigned only once.
(5)Fifth we will initialize all fields via a constructor performing the deep copy.
(6)Sixth we will Perform cloning of objects in the getter methods to return a copy rather than returning the actual object reference.
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
What are the main difference between Array and Arraylist
What is classloader in Java and name of some classloader
Different modules of the Spring framework
Difference between Object and Class
Most important 15 aspects that Java Developer should learn in year 2020






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |