Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


bhaskarreddy
IMMUTABLE
2 Answer(s)      4 years and 10 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

October 13, 2009 at 4:11 PM


Hi Friend,

To make a class immutable we must restrict changing the state of the class object.We can achieve this through a final and private modifier.Therefore,make all fields final and private.Don't provide any methods that modify the object.

for example,

final class ImmutableClass{
private final int count;
public ImmutableClass(int cout){
count = cout;
}
public int getCount(){
return count;
}
}
public class Immutable{
public static void main(String[] args) {
ImmutableClass cl = new ImmutableClass(5);
System.out.println(cl.getCount());
}
}

Thanks


October 24, 2010 at 10:35 AM


Please see here **Deleted**



Related Tutorials/Questions & Answers:
immutable class
immutable class  How to make a class immutable
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
Advertisements
IMMUTABLE - Java Interview Questions
IMMUTABLE  How To Make A Class Immutable?  Hi Friend, To make a class immutable we must restrict changing the state of the class...; } } public class Immutable{ public static void main(String[] args
Mutable and immutable Objects - Java Beginners
Mutable and immutable Objects  Hi, Please tell me about Mutable and immutable Objects. What is mutable object and immutable object and how... we can alter. like any primitive. Immutable are those object whcih we can
STRING IMMUTABLE - Java Interview Questions
STRING IMMUTABLE  Why string objects are immutable? what is the region behind?i want regione plz replyyyyyyyyy  Hi Friend, JVM maintains... object is immutable. Thanks
what is mutable and immutable object in java ?difference ?
what is mutable and immutable object in java ?difference ?  what is mutable and immutable object in java ?difference
Immutable Image using Canvas Class
Immutable Image using Canvas Class       This is the immutable image example which shows how to create the immutable image using canvas. In this example ImageCanvas class
Immutable Image MIDlet Example
Immutable Image MIDlet Example       This is the immutable image example, which shows how to create a immutable image in MIDlet. In this example we are creating
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
core java - Java Beginners
core java  hi, we know that String object is immutable in nature so like string object can we create our own object and that object should be immutable i mean we cant modify our own object plzzzzzzzzzzzzz tell me the answer
CORE JAVA
CORE JAVA  Static methods can be participated in inheritance? What is static keyword? What is static keyword? How to write code for static factory method? What is mutable and immutable
j2me image application
j2me image application  i can not get the image in my MIDlet .........please tell me the detailed process for creating immutable image without Canvas class
java interview
java interview  what is infterface? and it is uses? what is ast class? and it is uses? what is ast methods? what is immutable? what is mutable? what are the final class in java? what is the static methods
(ii) String and String Buffer Class
between String and StringBuffer 1) String object is immutable
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after... after it is created. The basic way to create an immutable object is to make all
What is ROWID?
of the Oracle ROWID datatype. It is intended to be immutable. The user should not try
Session Factory
Session Factory  Define the session factory interface in hibernate?   Hi Samar, It creates new hibernate sessions by referencing immutable... sessions by referencing immutable and thread safe objects. Application using
Wrapper Class
of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper... are immutable i.e. once assigned a value to a wrapper class instance cannot be changed
wrapper classes
of the primitive wrapper classes in Java are immutable i.e. once assigned a value
String and stringbuffer object - Java Beginners
are constants and immutable while StringBuffer objects are not. 4)StringBuffer
java code - Java Beginners
java code  write a program for immutable class  Hi Friend, Try the following code: final class ImmutableClass{ private final String product; private final double price; public ImmutableClass(String
'String' vs 'StringBuffer' - Java Beginners
'String' vs 'StringBuffer'  What should i use String or StringBuffer?  Hi, First you need to rectify the question. Because StringBuffers append the data, and Strings concatenate the data. Since Strings are immutable
STRINGS - Java Interview Questions
STRINGS  1.Why string objects are immutable? 2.why java is pass by value?  Hi Friend, 1) To save memory, java can refer two string... program.Therefore String objects are made immutable. This provides better memory
java - JDBC
are immutable i.e. once assigned a value to a wrapper class instance cannot be changed
java basics
are immutable i.e. once assigned a value to a wrapper class instance cannot be changed
java - Java Beginners
java  it is define that in wapper class implements immutable object that means that after the primitive value is initilized in the wapper object then there is no way to change that value.but i could not understand what it mean
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
Java Interview Questions       Core java Interview Question page1 An immutable class is a class to which values assigned to the variables can not be altered
java - JDBC
String objects are immutable they can be shared. For example: String str
Wrapper Classes
classes in Java are immutable i.e. once assigned a value to a wrapper class
Few of the familiar Design Patterns in Java
particular class. 5. Immutable The Immutable pattern reduces the overhead... state information to change after it is constructed. The Immutable pattern also... to a shared object. The Immutable object pattern can be used to avoid the need
Wrapper
in Java are immutable. Converting primitive types into the corresponding wrapper
NSString in objective c
for an objects(that manages immutable strings). The objects later ..can be used...: Immutable string are those strings that can be defined at the time of creating
Java interview questions and answers
between string and stringbuffer object? Ans. String is an immutable object
j2me - MobileApplications
(this); exit = new Command("Exit", Command.EXIT, 1); form = new Form("Immutable Image
j2me - MobileApplications
(this); exit = new Command("Exit", Command.EXIT, 1); form = new Form("Immutable Image
Java final keyword
be modified. It must be made immutable so that modifcations are not made. The final
Sitemap J2ME Tutorial
Animation using repaint( ) method | Immutable Image MIDlet  | Immutable Image
Summary - Data
have corresponding "wrapper" class whose objects are immutable... methods for working with characters. String immutable 0 or more characters
String and StringBuffer - Java Beginners
. Simply stated, objects of type String are read only and immutable. The StringBuffer
StringBuilder v/s StringBuffer - Java Beginners
; Hi friend,Strings are immutable (can't be changed), so manipulating strings
Keywords - Java Beginners
and the concept of immutable Objects. volatile : It is used on variables that may
java - Java Interview Questions
are immutable i.e. once assigned a value to a wrapper class instance cannot
How to make a file in java
Description: This example demonstrate how to make a file and write string in it. To create a file in java we use the File Class. The instance of the File class is immutable that means the pathname represented by the File object
Java Hibernate
to the immutable and threadsafe object to create new Hibernate sessions. Only
Differences between the String, StringBuilder, and StringBuffer classes
be changed. Simply stated, objects of type String are read only and immutable... method is called at location 23. Because the String class is immutable
Hibernate Architecture
with the database. SessionFactory object is a thread safe (immutable) and it is created once
How to create LineDraw In Java
drawing attributes. The BasicStroke() objects are immutable, So its can be safely
Wrapper Classes
are immutable i.e. once assigned a value to a wrapper class instance cannot be changed
Summary - java.util.StringBuilder and java.util.StringBuffer
of java.util.StringBuilder class. Strings are immutable (can't be changed), so
J2ME Tutorial
and implements the CommandListner class.    Immutable Image MIDlet Example This is the immutable image example, which shows how to create a immutable image in MIDlet. In this example we are creating a image
Advertisements
 

 

 

DMCA.com