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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:06:55+00:00 2026-05-25T15:06:55+00:00

Maybe I’ve been working too long on Java without really understanding some of its

  • 0

Maybe I’ve been working too long on Java without really understanding some of its basics.
I do understand that == is for object reference equality and .equals() is for object value equality.

  1. Comparing Integers:

    Integer x = 1, y = 1;  
    System.out.println(x == y); // true
    

    Why? Since object reference equality is used, it should be false since they are both different objects.

  2. Comparing getClass() return values:

    String s1 = "a", s2 = "b";  
    System.out.println(s1.getClass() == s2.getClass()); // true 
    

    Why? Again as per above, object reference is used. Both using getClass will return separate Class objects.

Did I miss something or is my mind is too tired of coding in Java?

  • 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-25T15:06:55+00:00Added an answer on May 25, 2026 at 3:06 pm

    Integer objects

    Integer x = 1, y = 1;
    System.out.println(x==y); // true, why?
    

    This happens because for values in the byte range (-128 to +127), java uses cached Integer objects, stored in Integer‘s inner class, IntegerCache. Every time an Integer object is created with value between -128 and +127, the same object will be returned (instead of creating the new object).

    Conversely, for values outside the byte range, the comparison is false:

    Integer x = 999, y = 999;
    System.out.println(x==y); // false
    

    Class objects

    String s1 = "a", s2 = "b";
    System.out.println(s1.getClass() == s2.getClass()); // true. Why?
    

    This is true because the class of both objects is String, and there is only one copy of each class object per JVM (it’s like a singleton). The class object returned from getClass() of each String is the same class object (String.class).

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

Sidebar

Related Questions

Maybe it's useful if calling a method that MyClass doesn't understand on a something
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe my understanding of agile development isn't as good as it should be, but
Maybe that's only possible with SQLITE but is there also a trick to let
maybe you could help me understand why I get an unhandled exception Invalid XAML
Maybe someone that has experience with the Jquery Add to Calendar Widget (https://github.com/tardate/jquery.addtocalendar) can
maybe I am being stooped... but the fact is that I am a bit
maybe someone could recommend some good examples concerning thread executions, thread management. Maybe not
maybe a few others already asked that but I couldn't find any answer to
Maybe it's just me, but I cannot understand the documentation regarding Junit test integration

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.