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




Have Programming Question? Ask it here!
 
 
 


neelam
Java object
1 Answer(s)      3 years and 6 months ago
Posted in : Java Interview Questions


What is mutable object and immutable object?

Advertisement
View Answers

October 16, 2010 at 1:10 PM


An Immutable object is a kind of object whose state cannot be modified after it is created.
This is as opposed to a mutable object, which can be modified after it is created.
The basic way to create an immutable object is to make all of its data fields private and don't create any methods which can change any of the data fields once the object has been constructed.
this code helps you to understands-

package roseindia;

import java.awt.Point;

public class test {

public static void main(String[] args) {
Point point1 = new Point(0, 0);// mutable object
System.out.println(point1);
point1.setLocation(1.1, 1.0);
System.out.println(point1);
String str = new String("Gyan Singh");// immutable object
System.out.println(str);
str.replaceAll("Gyan", "Samar");
System.out.println(str);
}

}

Output of the code is as follows-
java.awt.Point[x=0,y=0]
java.awt.Point[x=1,y=1]
Gyan Singh
Gyan Singh


Related Tutorials/Questions & Answers:
Java object
Java object  Which class should you use to obtain design information about an object
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 it is created. This is as opposed to a mutable object, which can be modified
Advertisements
Object in java - Java Beginners
Object in java  Hi deepak, I am new to java, can u tell me what is class ,object and instance with example. For example : class raja , raja r.../java/master-java/java-object-oriented-language.shtml http
java object - Java Beginners
java object  i want a complete memory description of objects,methods... of objects. The primitive data type and keyword void is work as a class object. Object: Object is the basic entity of object oriented programming language
Java object clone
Java object clone  What is criteria for a object to get cloned
Java object's lock
Java object's lock  What is an object's lock and which object's have locks
java object - Java Beginners
java object  i want to where in the memory the java objects,local... are stayed  Hi friend, Instance Variables (Non-static fields): In object... fields" that is declared without the static keyword. Each object of the class has its
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
java object class methods
java object class methods  What are the methods in Object class?  There are lots of methods in object class. the list of some methods are as- clone equals wait finalize getClass hashCode notify notifyAll
java is pure object oriented
java is pure object oriented  java is pure object oriented or not.? reason.?   Java is not pure object oriented language because... are not object 2)It does not support operator overloading multiple inheritance. 3
object conversion - Java Beginners
object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your query, otherwise u may got help from here, http://www.roseindia.net/java
Object class in java
Object class in java  want an example and with an explaination about equals() method in object class? Is equals() is similar
object creation - Java Beginners
object creation  I need object creation in depth(with stack,pc registers).Any one can provide me if possible with video/audio
java : object oriented
java : object oriented   (a) Write a class named CarRental... the user for the data needed for a rental and creates an object of the correct... an object of the correct type. Display the total rental fee
Object serialization - Java Beginners
Object serialization  Design classes for Currency, Rupee, and Dollar. Write a program that randomly generates Rupee and Dollar objects and write them into a file using object serialization. Write another program to read
vector object - Java Beginners
vector object  hi i have created a Vector vec=new Vector(); vec.addElement(o); o is an object of group(acl.group) what i have to do to read contents of this object? can it be possible to convert it into string arrays
object - Java Interview Questions
?   Hello, i know only two wayes of object instansiations 1.... Thankx   Hi Friend, Yes we can create an object in the following... of creating an object. ClassName classObject = new ClassName(); 2. Using
Java Object
Java Object      ... properties of the class or its group. Java object is an instance of the class. It takes.../java-object-oriented-language.shtml  
Is Java a pure object oriented language?
Is Java a pure object oriented language?   Hi, Is Java a pure object oriented language? thanks   Hi No, Java is an object oriented programming language but not purely a object oriented language. In OOPs programming
Deserializing an Object in java
Deserializing an Object in java     .... The given program shows how to read any data or contents from the serialized object or file. It takes a file name and then converts into java object. If any exception
Serializing an Object in Java
Serializing an Object in Java   ... of object i.e. reused by the JVM (Java Virtual Machine). This process... of saving an object in a storage medium (such as a file, or a memory buffer
object 2 string - Java Beginners
object 2 string  hi sir,how to convert object to string and how 2 compare object with null value to string with null value plz provide a program 4 this sir,plzzzzzzzzz
object retun type - Java Beginners
object retun type  Hi, i have to create a method which should have return type of object . The object should contain 'list of filenames' array and a boolean field 'isVal'. Can anybody help
What are the methods in Object? - Java Beginners
What are the methods in Object?   Hi, What are the methods in Object? Give example of methods in Object. Thanks   Hello, There are lot of method in object class some of are as follows toString(); wait
object oriented programming - Java Beginners
object oriented programming  sir, i read in the book tat object oriented program exhibits recurring structures. i want to know "what is meant by recurring structures?"  Hi Friend, Any structure to be occurred over
ResultSet object initialization - Java Beginners
ResultSet object initialization  How to initialize resultset object  Hi friend, public interface ResultSet A ResultSet object maintains a cursor pointing to its current row of data. A default ResultSet object
OBJECT CLASS - Java Interview Questions
OBJECT CLASS  How To Find Out How many Objects Create?How Many Object Are Reachabule To Garbage Collector?i want Source code Plz Help me........?urgentttttttttttttt  To find the number of objects created
String and stringbuffer object - Java Beginners
String and stringbuffer object  Hi, What is the basic difference between string and stringbuffer object? Thanks   Hi Friend, Differences: 1)String class is used to manipulate character strings that cannot
Object-Oriented programming - Java Beginners
Object-Oriented programming  Write a program to display the names and salaries of 5 employees.Make use of a class and an array.The salary of each employee should increase by 5% and displayed back.  Hi friend, Code
Object oriented program - Java Beginners
Object oriented program  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
object oriented program.. - Java Beginners
object oriented program..  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
Creating Java Object in Vbscript - Development process
Creating Java Object in Vbscript  How to create a java object in Vbscript. Please give the detailed steps to create a java Object in Vbscript
Accessing the object information - Java Beginners
Accessing the object information  Authors.java import java.util.*; import jsns.model.AbstractAgent; import jsns.model.IAgentActor; import jsns.model.IAgentSensor; import jsns.model.IEnvironment; import
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
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
Java I/O Object Streams
Java I/O Object Streams In this section we will discuss the Java IO Object Streams. To work with the I/O of objects Java provided the support of Object stream. Object stream classes implements either ObjectInput or the ObjectOutput
Java Value Object Pattern
-left: 440px; } Value Object Pattern Some entities contains a group.... To come out from this problem you can Value Object Design Pattern. It encapsulate all the data as a single object and provide a single method to send
Difference between object and instance? - Java Beginners
Difference between object and instance?  What is the difference between object and instance in java
About Object cloning. - Java Interview Questions
About Object cloning.  what is Object cloning? can u explain with example?  Hi Friend, The way to make an identical copy of an object is said to be object cloning.In java, it has to be done using clone() method
Java - Class, Object and Methods in Java
Java - Class, Object and Methods in Java   ... the things are a object. And all the objects are categorized in a special... with its class that mean almost all the properties of the object should be matched
fully object oriented language - Java Beginners
fully object oriented language  Is java is a fully object oriented language?if no,why?  Hi Friend, Java is not a fully object oriented... int,float which are not object 2)It does not support operator overloading
Reference type Vs Object type. - Java Beginners
. They never contain the object. C++ object variables may be either, but Java supports only object references. For Example : Book bookvar = new Book("Java...Reference type Vs Object type.  Can anyone explain the exact
Core java interview question, object creation.
Core java interview question, object creation.  How can we restrict to create objects for more than five? That means i want only 5 objects, how to restrict to create 6th objects
Import object in Excel using java swing
Import object in Excel using java swing  Hi sir, I want to make a swing application where I can import a object by clicking a button. I am using... in 'Insert' ribbon. first select a cell (cell no will be inside java code) then go
how to get session object in simple java class??
how to get session object in simple java class??  i am fallowing...) GroupDetailsDao.java (it is also a simple java class which have the jdbc logic... the value to GroupPojo.java and set this pojo object into session. sending control
regarding object references - Java Interview Questions
regarding object references  How can we find the number of instances created to an object in java? Write a program for this?  Hi Friend, Try the following code: class Example { static int ob = 0; public Example
Object Oriented Programming in Java
and C++ and also easy to code in. Everything in Java is object or can be made... the wrapper class. In Java class is a group of similar object. Objects here can have same behavior, properties, type or identity. Object in Java is an instance
More than 1 preparedStatement object - Java Beginners
one prepared Statement object using batch update.. Explain with a code using java... Thanks  Hi Friend, You can use more than one prepared Statement object in the java class.Try the following code: import java.sql.
 

 

 

DMCA.com