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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:20:42+00:00 2026-06-13T04:20:42+00:00

I have just started learning Java. In the online course I am following, I

  • 0

I have just started learning Java. In the online course I am following, I am asked to try the following code:

String email1 = "meme@me.coh";
String email2 = "meme@me.com";
Boolean isMatch = false;

isMatch = email1.equals (email2);

if (isMatch == true){
    System.out.println("Emails match");
}
else{
    System.out.println("Emails don't match");
}

I don’t understand why I’m asked to declare isMatch as false when on the next line i am comparing the email addresses and assigning the value to isMatch.
I’ve tried the following code which seems to work just the same:

String email1 = "meme@me.coh";
String email2 = "meme@me.com";
Boolean isMatch;

isMatch = email1.equals (email2);

if (isMatch == true){
    System.out.println("Emails match");
}
else{
    System.out.println("Emails don't match");
}

On the course it doesn’t explain why I’m declaring isMatch as false first. Is there a reason why I must declare isMatch as false before comparing the email addresses?

  • 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-06-13T04:20:43+00:00Added an answer on June 13, 2026 at 4:20 am

    You don’t have to, but some people like to explicitly initialize all variables (I do too). Especially those who program in a variety of languages, it’s just easier to have the rule of always initializing your variables rather than deciding case-by-case/language-by-language.

    For instance Java has default values for Boolean, int etc .. C on the other hand doesn’t automatically give initial values, whatever happens to be in memory is what you end up with unless you assign a value explicitly yourself.

    In your case above, as you discovered, the code works just as well without the initialization, esp since the variable is set in the next line which makes it appear particularly redundant. Sometimes you can combine both of those lines (declaration and initialization – as shown in some of the other posts) and get the best of both approaches, i.e., initialize the your variable with the result of the email1.equals (email2); operation.

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

Sidebar

Related Questions

First of all, this is my code (just started learning java): Queue<String> qe =
I Have just started learning Android, this is the code of my java file.
I have just started learning java, and know only a small amount of code,
I have just started learning java. I modified the client side code for a
G'Day Programmers, I am from Java background however I have just started learning C++
I have just started learning java and i have about 8 months time. My
I just started learning Java and I'm having trouble formatting string. In the problem
I am just starting out learning Java, GAE etc. I have started a project
I have just started learning java. I downloaded eclipse for linux and had an
I've just started learning Java and have come across a little quirk I'm not

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.