Explain testing for equality with equals, JAVA Programming

Assignment Help:

Explain Testing for Equality with equals?

That's not what you expected. To contrast strings or any other kind of object you required to use the equals(Object o) techniques from java.lang.String. Below is a corrected version in which works as expected. The purpose for this odd behavior goes fairly deep within Java and the nature of object data types such as strings.
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.equals(s2) ) {
System.out.println("The strings are the same.");
}
else {
System.out.println("The strings are not the same.");
}
}
}

 


Related Discussions:- Explain testing for equality with equals

How to get data from the velocity page in a action class, We can get the va...

We can get the values in the action classes by using data.getParameter("variable name described in the velocity page");

Javaserver faces (jsf) framework, JavaServer Faces (JSF) framework : Ja...

JavaServer Faces (JSF) framework : JavaServer Faces is a new framework for creating Web applications using Java. JSF gives you with the following main features: Basic us

What is a java applet, Question 1: (a) What are the disadvantages of u...

Question 1: (a) What are the disadvantages of using HTML Frames in your web pages? (b) Give five examples of controls used inside HTML forms and the situation in which the

Describe even higer dimensions in java, Describe even higer dimensions in j...

Describe even higer dimensions in java? You don't have to stop along with two dimensional arrays. Java allows arrays of three, four or more dimensions. Therefore chances are pr

Spring application support, JAVA, JSF(primefaces), SPRING Application Suppo...

JAVA, JSF(primefaces), SPRING Application Support Project Description: We require some one to be part of our team's new development , it's small application but in future, ch

Basic difference b/w finalize(), 1.   final - it is a constant declarati...

1.   final - it is a constant declaration. 2.   finally - handles exception. The finally block is optional and gives a mechanism to clean up regardless of what occurs within

Explain the reading documentation for a class in the class, Explain the Rea...

Explain the Reading documentation for a class in the class library For instance, let's suppose you need to use the URL class in the java.net package. Through reading the docume

Difference between static and non-static variable, What is the difference b...

What is the difference between static and non-static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. Non-st

Explain the essential api concepts associated with j2me, Question : (a)...

Question : (a) Class file verification in CLDC is different from class file verification in J2SE. Explain and discuss how and why it is different, illustrating your answer

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