Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6842689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:07:52+00:00 2026-05-27T00:07:52+00:00

I found an article with an interesting piece of code: public class Employee {

  • 0

I found an article with an interesting piece of code:

public class Employee {

    private String firstName;
    private String lastName;

    //private default constructor
    private Employee(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public static Employee valueOf (String firstName, String lastName) {
        return new Employee(firstName, lastName);
    }
}

I am really curious in understanding the advantage of creating this kind of classes.
I understand that here that an object of this class would be immutable, because there is no way of changing its variable values once initialized. I never did something like this before, and i dont really understand the advantage of it.

  • Why is it a good practice?
  • Could you name a situation where this approach can be used?
  • What about constants or read only variables? Is not that very similar?
  • In the article says, that this is not good for the performance of the application. But why?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:07:52+00:00Added an answer on May 27, 2026 at 12:07 am

    The example you have mentioned is of an Immutable Objects. Its widely used concepts in programming languages.

    Quoting from the link above. The advantages are

    • are simple to construct, test, and use
    • are automatically thread-safe and have no synchronization issues
    • do not need a copy constructor
    • do not need an implementation of clone
    • allow hashCode to use lazy initialization, and to cache its return value
    • do not need to be copied defensively when used as a field
    • make good Map keys and Set elements (these objects must not change state while in the collection)
    • have their class invariant established once upon construction, and it never needs to be checked again
    • always have “failure atomicity” (a term used by Joshua Bloch) : if an immutable object – throws an exception, it’s never left in an undesirable or indeterminate state
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read This article and i found it interesting. To sum it up for
I've found an article on this subject by a Microsoft employee, but has anyone
I was digging around in MSDN and found this article which had one interesting
I've found an interesting article on adding radial gravity to box2d. http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/ To port
I stumbled across this article and found it very interesting, so I ran some
I found this article on how to manipulate the rendering sequence of asp.net controls.:
I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2
I've found this MSDN article that explains how to monitor processes and services with
Here's an interesting article that I found on the web. It talks about how
I found this article explaining how to run MySQL on Amazon EC2. It talks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.