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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:33:07+00:00 2026-06-11T18:33:07+00:00

I am a beginner in java and has slowly started to get the feel

  • 0

I am a beginner in java and has slowly started to get the feel of this language.

I am having a hard time understanding “this” variable.

For example, which is better.. and why?

  public class Foo{
   int a;
   public Foo(int _a){
   a = _a;
     }
 }

vs

public class Foo{
   int a;
   public Foo(int _a){
   this.a = _a;
     }
 }

Thanks

  • 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-11T18:33:08+00:00Added an answer on June 11, 2026 at 6:33 pm

    Personally, I hate those conventions that use the underscore or “m_” to distinguish variables. That’s the stuff that IDEs are meant to make clear.

    You use this to clearly delineate variables that belong to the current instance.

    Neither of your examples have any advantage. You can prove it to yourself by looking at the byte code that’s produced. If you use javap, you’ll see that the two compile to identical code.

    It has more to do with readability for yourself and other programmers in my opinion. And good IDEs, like IntelliJ, use highlighting and color coding to make it even clearer.

    The one circumstance where it’s absolutely required is when there’s a name collision between a method parameter and a private member. Then you have to use this to disambiguate which is which for the compiler:

    public class Foo {
        private int x;
        public void setX(int x) {
            this.x = x;  // this is required here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey there. Java beginner here :) Well, I'm having a few troubles with this
i am a beginner at java language and i use text pad. i have
I'm totally beginner in java. In javascript i have this regex: /[^0-9.,\-\ ]/gi How
I have been wandering about this for some time now. I'm still a beginner,
This is a real beginner question (I'm still learning the Java basics). I can
Hi I am beginner in java and my program has 4 for loops: my
Java beginner here who is terribly confused as to why 1) this is valid
I'm beginner in Java but I has the following code limit = con.prepareStatement(SELECT COUNT(*)
I'll preface my question by saying that I'm a beginner Java EE developer. I
Iam a Java beginner and i would like to ask whats the pros and

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.