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

  • SEARCH
  • Home
  • 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 8553515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:40:12+00:00 2026-06-11T14:40:12+00:00

I have read that with a Java version less than 7, Joda Time objects

  • 0

I have read that with a Java version less than 7, Joda Time objects are more reliable than Java’s built-ins. One cited reason is that Joda objects are immutable. Why is this beneficial? If I want to change the year, hour, and timezone of a Joda DateTime object, I need to make three copies!

  • 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-06-11T14:40:14+00:00Added an answer on June 11, 2026 at 2:40 pm

    If I want to change the year, hour, and timezone of a Joda DateTime object, I need to make three copies!

    Yes, indeed. Or you could create one new object, using all the fields you like from the old object, of course.

    This is a thoroughly good thing – because it means when you want to rely on an object not changing, it won’t. Consider this pseudo-code:

    private static final Instant EARLIEST_ALLOWED_ARTICLE = ...;
    
    private Instant creationTimestamp;
    
    public Article(Instant creationTimestamp, ...) {
        if (creationTimestamp.isBefore(EARLIEST_ALLOWED_ARTICLE)) {
            throw new IllegalArgumetnException(...);
        }
        this.creationTimestamp = creationTimestamp;
        ...
    }
    

    That’s fine, because Instant is immutable. If it were mutable, the validation in the constructor would be worthless – unless you created a defensive copy at that point.

    In my experience, you want to pass around references and know that the values won’t change more than you want to actually make changes to existing objects, so immutability leads to fewer bugs (with mutable objects you can forget to take a copy, and any validation is then useless) and fewer copies being made.

    Basically, it allows you to reason about your code locally without making copies of everything you either accept and store, or return to other code. When only your code can change the state of your object, it’s much simpler to work out what will happen over time.

    Joda Time actually fails somewhat because it has both mutable and immutable types – if you just program to the interface (e.g. ReadableInstant) then you don’t get those guarantees. That’s why in Noda Time I made all the types genuinely immutable.

    Out of interest, would you want String to be mutable? If not, try to think about whether there are real differences between the two scenarios.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read that in Java interfaces can't be instantiated ( in the documentation,
I have read up on it a bit and I understand that in java
I have read a document that they say: In java there two types of
I have read in a Java book that says: Because a String is immutable,
I am new to Java. I just read that class variables in Java have
I have a stand-alone java application that makes some database read/write business on a
Almost every article I read told me that you can't have chdir in Java.
I have read that GLSL (specifically v1.0.17: my application is running under WebGL) compilers
I have read that you should keep the number of connections in your database
I have read that for enabling the auto return I have to enable this

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.