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 8348655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:45:30+00:00 2026-06-09T07:45:30+00:00

Today is my first time to try Java language. When I try this code,

  • 0

Today is my first time to try Java language. When I try this code, I feel very strange:

int a =500;
System.out.println(System.identityHashCode(500));
System.out.println(System.identityHashCode(500));
System.out.println(System.identityHashCode(a));
System.out.println(System.identityHashCode(a));

All of these results is different. But when I changed 500 to 50, It become the same result.

Why is it?

  • 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-09T07:45:31+00:00Added an answer on June 9, 2026 at 7:45 am

    But when I changed 500 to 50, It become the same result.

    Autoboxing caches the conversion of primitives to Object. Small values get the same object, larger values do not.

    Note: while values between -128 and 127 are always cached, Higher values can be cached depending on command line settings. See the source for Integer for more details.

    This is also called a Flyweight Pattern


    You can set the maximum size of the Integer cache with

    -Djava.lang.Integer.IntegerCache.high=NNNN
    -XX:AutoBoxCacheMax=NNNN
    -XX:+AggressiveOpts  // sets it higher depending on the version e.g. 10000
    

    http://martykopka.blogspot.co.uk/2010/07/all-about-java-integer-cache.html

    http://www.javaspecialists.eu/archive/Issue191.html

    I feel very strange

    I know what you mean reading this question. 😉

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

Sidebar

Related Questions

Today out of curiosity, i tried something very weird: The Code : int num
Today is the first time I've used Python, so I'm sure this'll be an
My first time using localflavor in django and got a strange thing today! I
I tried Build and Analyze tool of Xcode very first time today. and found
Hi I am trying out meteor for first time today. my symptoms: meteor just
Today is the first time I ever expose to LINQ so to say I
I tried using PHPDoc for the first time today and quickly ran into a
I have been using pil for the first time today. And I wanted to
I came across Side-by-side Assemblies for the first time today while trying to install
Today is my first day using ASP.NET MVC, and I'm finding it very intriguing.

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.