Explain testing objects for equality in java, JAVA Programming

Assignment Help:

Explain Testing Objects for Equality in java?

<, >, <= and >= can only be used with numbers and characters. They cannot be used with Strings, booleans, arrays or other compound types since there's no well-defined notion of order for these objects. Is true greater than false? Is "My only regret is that I have but one life to give for my country" greater than "I have a dream"?

Equality is a little easier to test however. true is equal to true and true is not equal to false. Similarly "My only regret is that I have but one life to give for my country" is not equal to "I have a dream." However you might be surprised if you ran this program:
class JackAndJill {

public static void main(String args[]) {

String s1 = new String("Jack went up the hill.");
String s2 = new String("Jack went up the hill.");

if ( s1 == s2 ) {
System.out.println("The strings are the same.");
}

else if ( s1 != s2 ) {
System.out.println("The strings are not the same.");
}
}
}
The result is
The strings are not the same.


Related Discussions:- Explain testing objects for equality in java

Need professional framework coder with coding experience, Need Professional...

Need Professional Framework Coder with Video Coding Experience? Project Description: Professional Framework Coder with Video Coding experience. You must know API, Java, C++,

Javascript validarion, 1. Obtaining the new script: Download and save the a...

1. Obtaining the new script: Download and save the attached comment CGI mailer script form-mail2.pl to your server''s cgi-bin directory, and change the permissions on the script to

write program a, How do I write a program a bout Rotor cipher

How do I write a program a bout Rotor cipher?

Explain ftp-telnet-voip and instant messaging, Write a brief note on each o...

Write a brief note on each of the following. FTP Telnet Instant messaging VoIP FTP: File Transfer Protocol: This protocol is used to upload and download the

Illustrate normalization? , Normalization is a design technique that is m...

Normalization is a design technique that is mostly used as a guide in designing relational databases. Normalization is necessary a two step process that gives data into tabular f

Explain jsp technology?, Java Server Page is a standard Java extension that...

Java Server Page is a standard Java extension that is described on top of the servlet Extensions. The goal of JSP is the simplified formation and management of dynamic Web pages. J

Legal responsibility of nurses, As registered nurses, we often wonder "am I...

As registered nurses, we often wonder "am I responsible for the L.P.N's and the C.N.A. assigned on my floor.  Will I be blamed if someone makes an error or if someone gets hurt?  N

Get info from website using javascript, Get info from website using javascr...

Get info from website using javascript Project Description: I need to extract the text from all the available (red, blue) seats of all the events on this site without getting

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd