The comments in the program below are self explanatory and should help you figure out the subtleties of new object creation and the == operator versus equals() method.
public class CompareQuestion { public static void main(String[] args) { String s1 = new String("A"); //not recommended, use String s1 = "A" String s2 = new String("A"); //not recommended, use String s2 = "A" //standard: follows the == and equals() rule like plain java objects. if (s1 == s2) { //shallow comparison, never reaches here System.out.println("references/identities are equal"); } if (s1.equals(s2)) { //deep comparison, this line is printed System.out.println("values are equal"); } //variation: does not follow the == and equals rule String s3 = "A"; //goes into a String pool. String s4 = "A"; //refers to String already in the pool. if (s3 == s4) { //shallow comparison, this line is printed System.out.println("references/identities are equal"); } if (s3.equals(s4)) { //deep comparison, this line is also printed System.out.println("values are equal"); } } }
Ever since their invention computers have become an essential part of our lives. We use computers and computer related devices in everyday life. They have acquired supreme importance in every walk of life.
ReplyDeleteStartPoint
It's Really A Great Post. Looking For Some More Stuff
ReplyDeleteBest Oracle SQL Training institute in Bangalore
Best Java Training in Bangalore
Hi There,
ReplyDeleteWhat a brilliant post I have come across and believe me I have been searching out for this similar
kind of post for past a week and hardly came across this.
I have two methods and they do almost same thing, but at some most inner nested level one of method have additional command.
Java Code:
method2(){
... same code ...
for {
... same code ...
if{
... same code ...
}
}
}
Follow my new blog if you interested in just tag along me in any social media platforms!
Shukran,
Munni
Thanks for sharing a worthy information. This is really helpful. Keep doing more.
ReplyDeleteSpoken English Classes in Chennai
Spoken English in Chennai
Top 10 Spoken English Classes in Chennai
Best IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Classes in Mumbai
English Speaking Classes in Mumbai
Best IELTS Coaching in Mumbai
IELTS Coaching in Mumbai
Spoken English Classes in Anna Nagar
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... Kopar at Newton Condo
ReplyDeleteThe most important thing that a new programmer needs to know is that the "Learn Programming in 24 hours" sort of books are simply not true. A more accurate title would be "Learn Programming in 10,000 hours".best ergonomic chair
ReplyDeletedfgh
ReplyDeleteHere at this site really the fastidious web design studio material collection so that everybody can enjoy a lot.
ReplyDeleteYou can do this by finding the module in the WordPress Module Catalog and checking the similarity confine the correct hand section. error establishing a database connection
ReplyDeleteIt will be essential that each progression of advancement stake its natural incentive to society via flawlessly sticking to social, environmental, and financial boundaries. excel vba training london
ReplyDeleteBut the web developers use a variety of add-on modules to write modern web applications in Python. While writing web applications in Python, programmers have option to use several high-level web frameworks unindent does not match any outer indentation level python
ReplyDeleteI got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. targonca szállítás Debrecen Europa-Road Kft.
ReplyDeleteAivivu đại lý vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ tháng nào rẻ nhất
vé máy bay từ mỹ về vn
các chuyến bay từ đức về việt nam hôm nay
vé máy bay từ nga về việt nam bao nhiêu
mua vé máy bay từ anh về việt nam
mua vé máy bay giá rẻ từ pháp về việt nam
khách sạn cách ly đà nẵng
chi phí vé máy bay cho chuyên gia nước ngoài
It's not my very first time to visit this blog; I’m visiting this daily and acquire superb info from here day by day.
ReplyDeleteapp designing company
Nobody can reject the info you have given in the blogs, this is actually a great work.
ReplyDeleteUI design firms
The HP ENVY Pro 6455 is an all-in-one printer that performs like most models in HP's ENVY lineup. It's rather compact and feels fairly well-built overall. However, its cartridge system yields a very low number of pages, so you may have to buy new cartridges quite often, resulting in a disappointing cost-per-print. read more this article
ReplyDeleteinformative blog , keep posting and dont forget to checkout our blog full stack course in satara
ReplyDeleteSuperb article.
ReplyDeletealso, join Java classes in Pune