- Q What is the role of community resources in developing the communicative skills of students?
- Q What is the function of the collagen fibers of the connective tissue?
- Q Following is the syntax of the method to read a directory: fs.readdir(path, callback) Parameters Here is the description of the parameters used: path - This is the directory name including path. callback - This is the callback function which gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.
- Q What is an antonym?
- Q Who painted The Card Players, at Feb 2012 the most expensive artwork in the world?
- Q What is a conversion constructor c++?
- Q What is a meeting workspace?
- Q Where is the Head Office of Syndicate Bank located?
- Q A virtual image larger than the object can be formed by which mirror?
- Q The only crator lake in India:
- Q A screwdriver becomes a fuzzy screw when you add what
Answers
To create an immutable class following steps should be followed:
1.Create a final class.
2.Set the values of properties using constructor only.
3.Make the properties of the class final and private
4.Do not provide any setters for these properties.
5.If the instance fields include references to mutable objects, don't allow those objects to be changed:
1.Don't provide methods that modify the mutable objects.
2.Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.
public final class FinalPersonClass
{
private final String name;
private final int age;
public FinalPersonClass(final String name, final int age)
{
this.name = name;
this.age = age;
}
public int getAge()
{
return age;
}
public String getName()
{
return name;
}
} Your Comment
1.Create a final class.
2.Set the values of properties using constructor only.
3.Make the properties of the class final and private
4.Do not provide any setters for these properties.
5.If the instance fields include references to mutable objects, don't allow those objects to be changed:
1.Don't provide methods that modify the mutable objects.
2.Don't share references to the mutable objects. Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.
public final class FinalPersonClass
{
private final String name;
private final int age;
public FinalPersonClass(final String name, final int age)
{
this.name = name;
this.age = age;
}
public int getAge()
{
return age;
}
public String getName()
{
return name;
}
} Your Comment
- 0
- 0
- New Answer
- Contributors: *,
More Software,Java Questions..
What is the inputsplit in map reduce software?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Can variables be used in Java without initialization?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Java,
What is the difference between java bean and enterprise java bean?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Java,
What is software configuration management?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How does the java database connectivity (jdbc) work?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Java,
What are the advantages of threads in java?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 0 )
- Tags: Java,
What Is Java Api For Xml-based Rpc (jax-rpc)?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
How can you implement fine-grained auditing?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is IBM’s simple explanation for Big Data’s four critical features?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is static synchronized method in JDBC API? Give an example?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
What does the NULLIF function do?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What happens if a start method is not invoked and the run method is directly invoked?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Should we override finalize method
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
what is the difference between mysql_fetch_array and mysql_fetch_object?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How will XML affect my document links?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is object cloning in Java?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 0 )
- Tags: Java,
Why to use Style Sheets?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are Filters in MVC?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Can you explain Application layer in OSI model?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How to define new testplan attributes?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,