Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,195 members, 7,822,043 topics. Date: Thursday, 09 May 2024 at 03:47 AM

JAVA Gurus, Check This Little Code!!!! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / JAVA Gurus, Check This Little Code!!!! (1373 Views)

Java Gurus Please I Need This Little Assignment Solved ''appreciation Involved" / Java Gurus Help / Excuze Me .... Java Gurus.. Dnt Pass By. (2) (3) (4)

(1) (Reply) (Go Down)

JAVA Gurus, Check This Little Code!!!! by Aphatech: 12:43pm On Apr 02, 2016
Integer a=100, b=100;
System.out.printIn(a == b);
Integer c=200, d=200;
System.out.printIn(c == d);
.
.
.
The use second command print false, why?
Let's see how good you are to detect small error!!!
Re: JAVA Gurus, Check This Little Code!!!! by APHATHEOLOGY(m): 2:01pm On Apr 02, 2016
Where are the JAVA daemons?
Re: JAVA Gurus, Check This Little Code!!!! by Nobody: 3:09pm On Apr 02, 2016
Integer a=200, b=200;
System.out.println(a == b);
this will give you false as well.

int a=200, b=200;
System.out.println(a == b);
this will give you true.



Integer a=100, b=100;
System.out.println(a.equals(b));

Integer c=200, d=200;
System.out.println(c.equals(d));
this will return true in all cases


int a=100, b=100;
System.out.println(a==b);

int c=200, d=200;
System.out.println(c==d);
this will return true in all cases

Reason: you cannot compare 2 integers the same way you will compare int (they are 2 different things entirely). I ain't got time to teach now o jare.

1 Like

Re: JAVA Gurus, Check This Little Code!!!! by Fulaman198(m): 3:55pm On Apr 02, 2016
dhtml18:

this will give you false as well.


this will give you true.




this will return true in all cases



this will return true in all cases

Reason: you cannot compare 2 integers the same way you will compare int (they are 2 different things entirely). I ain't got time to teach now o jare.

To expand upon this, when you declare Integer a = 100; you are creating an instance of Object Integer. To check for object content equality, the .equals() method should suffice.

The reason why Integer a = 100, b = 100;

and (a == b) comes out to false is because they are not pointing or referencing to the same object.

2 Likes

Re: JAVA Gurus, Check This Little Code!!!! by Nobody: 5:28pm On Apr 02, 2016
Just passing by with my 'java bible' text book firmly held in my armpit. grin

1 Like

Re: JAVA Gurus, Check This Little Code!!!! by Fulaman198(m): 7:10pm On Apr 02, 2016
crotonite:
Just passing by with my 'java bible' text book firmly held in my armpit. grin

lol

1 Like

(1) (Reply)

Need Help On My Project / How To Upgrade To Windows 10: What You Need To Know / What You Should Know About Google (great Or Scary?)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.