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

  • Home
  • SEARCH
  • 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 6322779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:23:47+00:00 2026-05-24T16:23:47+00:00

Possible Duplicate: What is the difference between these (bCondition == NULL) and (NULL==bCondition)? please

  • 0

Possible Duplicate:
What is the difference between these (bCondition == NULL) and (NULL==bCondition)?

please see the below code:-

if(myVariable==5)
   {
     //some logic
   }

one of my friends says that this is not a good way to write the code as its not per guidelines, however he dont have any reason to it. Is there is a chance of exception with above code or accidental modification?? According to him the better way would have been

if(5==myVariable)
       {
         //some logic
       }

please let me know which is a better way and why??? Do provide links if u have any.

  • 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-05-24T16:23:48+00:00Added an answer on May 24, 2026 at 4:23 pm

    The only reason to write:

    5 == variable
    

    instead of

    variable == 5
    

    is that in the former case if you incorrectly put an assignment (single =) in place you will get a compile time error because you are trying to overwrite a constant.

    However any decent compiler will give you a warning if you do:

    if (variable = 5)
    

    so IMHO it’s not worth worrying about. I always use the latter if (var == num) form.


    However in Java there is a common pattern that is worth using. When testing a string for equality, one should use:

    if ("constant".equals(variable)) { ... }
    

    instead of:

    if (variable.equals("constant")) { ... }
    

    since the latter can trigger a null pointer exception, and the former cannot.

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

Sidebar

Related Questions

Possible Duplicate: What is the difference between these (bCondition == NULL) and (NULL==bCondition)? Why
Possible Duplicate: What is the difference between these (bCondition == NULL) and (NULL==bCondition)? I
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN
Possible duplicate Debug Visual Studio Release in .NET What is the difference between Debug
Possible Duplicate: difference between http.context.user and thread.currentprincipal and when to use them? What's the
Possible Duplicate: C#: Difference between ' += anEvent' and ' += new EventHandler(anEvent)' What
Possible Duplicate: Difference between using var and not using var in JavaScript What is
Possible Duplicate: What is the difference between a field and a property in C#
Possible Duplicate: C#: Difference between ' += anEvent' and ' += new EventHandler(anEvent)' In

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.