The other answers seem to have focused on explaining why immutability is good. This is very good, and I use it whenever possible. However, this is not your question. I will take your question to try to make sure that you get the answers and examples that you need.
I cannot get what are scripts where we need an immutable class.
"Need" is a relative term here. Immutable classes are a design pattern that, like any paradigm / pattern / tool, makes it easy to create software. Likewise, a lot of code was written before the OO paradigm appeared, but count me among programmers who "need" OO. Immutable classes, such as OO, are not strictly needed, but I will act the way I need them.
Have you ever faced such a requirement?
If you do not view objects in the problem domain with the correct perspective, you may not see the requirements for an immutable object. It would be easy to think that the problem area does not require any immutable classes if you are not familiar when it is beneficial to use them.
I often use immutable classes, where I think of a given object in my problem area as a value or a fixed instance . This concept sometimes depends on the perspective or point of view, but ideally it will be easy to switch to the correct perspective in order to identify good candidate objects.
You can better understand where immutable objects are really useful (if not strictly necessary) by making sure you read in different books / online articles to develop common sense how to think about immutable classes. One good article to get you started: Java theory and practice: mutate or not mutate?
I will try to give a few examples below about how you can see objects in different perspectives (mutable and immutable) to clarify what I mean by perspective.
... could you give us some real example where we should use this template.
Since you asked for real examples, I will give you some, but first, start with some classic examples.
Classic value objects
Strings and integers are often considered values. Therefore, it is not surprising that the String class and the Integer wrapper class (as well as other wrapper classes) are immutable in Java. Color is usually considered a value, therefore the immutable class is Color.
Counterexample
In contrast, a car is not usually regarded as an object of value. Modeling a car usually means creating a class that changes state (odometer, speed, fuel level, etc.). However, there are some domains where a car can be an object of value. For example, a car (or, in particular, a car model) can be considered as an object of value in the application for finding the right engine oil for a given car.
Playing cards
Have you ever written a game card program? I did. I could imagine a playing card as a volatile object with a volatile suit and rank. A draw poker hand can be 5 fixed copies, where replacing the fifth card in my hand would mean mutating the fifth copy of the game card into a new card, changing its suit and ivars ranks.
However, I tend to think that a playing card is an immutable object that has a fixed, unchanging suit and rank after creation. My poker hand will be 5 copies, and replacing the card in my hand will discard one of these copies and add a new random copy to my hand.
Map projection
The last example is when I worked on some map code where the map could be displayed in various projections . In the source code, the map used a fixed but mutable copy of the projection (for example, a modified game map above). Changing the map projection meant mutating the projection of the projection map instance (projection type, center point, scaling, etc.).
However, I felt that the design was simpler if I thought of projection as an immutable value or a fixed instance. Changing the map projection meant having a link to the map of another instance of the projection, rather than mutating a fixed instance of the map projection. It also made it easier to capture named projections such as MERCATOR_WORLD_VIEW .