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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:36:05+00:00 2026-06-06T12:36:05+00:00

I was reading Code Conventions for Java from http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-137265.html#587 . In that, they have

  • 0

I was reading Code Conventions for Java from http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-137265.html#587.

In that, they have mentioned that we should avoid the use of objects to access a class variable or a method and should we use the class name instead.

Avoid using an object to access a class (static) variable or method.
Use a class name instead. For example:

classMethod();             //OK 
AClass.classMethod();      //OK
anObject.classMethod();    //AVOID!

Is there a particular reason for this in terms or performance or something else?

  • 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-06T12:36:07+00:00Added an answer on June 6, 2026 at 12:36 pm

    By class variables I assume you mean static variables.

    The use of static variables/methods through instance variables should be avoided because it’s confusing to the reader. Since you can only use instances to access instance variables, reading a code that calls static methods through an instance can confuse the reader about what’s going on.

    Image this case, with Thread.sleep, which is a static method:

    Thread.sleep(1000);
    

    Since the method is static and we are calling it through the class name, it’s intuitive to the reader to deduce that the effect is to put the current thread to sleep.

    Now if we did this:

    Thread t = new Thread(...);
    t.sleep(1000);
    

    Now which thread is put to sleep? The current one “obviously”. Someone not knowing about how sleep works might think that the child thread is somehow put to sleep.

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

Sidebar

Related Questions

I was reading the code in the following link http://www.cosc.canterbury.ac.nz/tad.takaoka/alg/graphalg/sc.txt I kept bumping into
I'm reading code from GraphServer . And there is this function that has weird
I know from reading Microsoft documentation that the "primary" use of the IDisposable interface
I am reading Code Complete. In that book, Steve McConnell warns that Developer tests
I have a simple text reading code for Visual Basic: Dim fileReader As String
Context Sometimes, I like reading code on paper rather than on screen (so I
Reading existing code at work, I wondered how come this could work. I have
I`m reading the code of some open source project. I see that in one
While reading a code I came across, the following definition and initialization of a
I'm reading this code sample : And since I don't know C#, I decided

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.