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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:33:23+00:00 2026-06-12T10:33:23+00:00

I made a coding mistake while working on an application, it was a test

  • 0

I made a coding mistake while working on an application, it was a test for null reference. It took me hours to discover what the issue was, but what i don’t understand is why the code behaved this way.

String name = null;
String value = null;

if(name != null && value != null);
{
    System.out.println("Values not null");
}

The if Statement ended with ;, that was my mistake and the Values not null was printed even when it is obvious that both values are null. Can anybody explain why?

  • 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-12T10:33:24+00:00Added an answer on June 12, 2026 at 10:33 am

    This semicolon ends a statement (an empty one), so your code is translated by the compiler to something like this:

    if(name != null && value != null)
    {
      //nothing here
    }
    {
      System.out.println("Values not null");
    }
    

    In other words, if if expression is true, it executes empty block of code. Then no matter whether if was true or not, the runtime proceeds and runs the block containing System.out. Empty statement is still a statement, so the compiler accepts your code.

    Another place where such a mistake can happen:

    for(int i = 0; i < 10; ++i);
    {
      System.out.println("Y U always run once?");
    }
    

    or even worse (infinite loop):

    boolean stop = false;
    while(!stop);
    {
      //...
      stop = true;
    }
    

    It took me hours to discover what the issue was

    Good IDE should immediately warn you about such statement as it’s probably never correct (like if(x = 7) in some languages).

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

Sidebar

Related Questions

I made a mistake while writing my Django application in hard coding all the
Upon coding, I realized I had made a mistake. I used git checkout 7e57dbf5a7245...
I have made the mistake when starting the coding an iPhone App of not
I am having trouble coding a hw program that is made to generate test
I am an intermediate C programmer. If you have made any coding mistake that
I might be doing a coding competition soon, I was wondering if anyone made
I made a dll in c# but i need to export the functions. Is
I made an application that passes trough an XML file and extracts the entries
I'm coding a poker hand evaluator as my first programming project. I've made it
I'm coding a GUI using WPF and Expression Blend for an application which is

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.