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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:09:19+00:00 2026-06-02T08:09:19+00:00

I’m undertaking a ‘static’ code walkthrough of Java code from a colleague (another student)

  • 0

I’m undertaking a ‘static’ code walkthrough of Java code from a colleague (another student)

To me, this doesn’t make sense; reading from top to bottom these ‘component’ objects are instantiated (and later used in the constructor) before they are declared. But, the code happily compiles and runs. Is this bad practice?

Public Class theObject {

    private static final long aVariable = 123123123123123;

    public theObject(...){

        componentOne = new Component(...);
        componentTwo = new Component(...);

        ...
        ...
        componentOne.doSomething(...);
    }

    private Component componentOne;
    private Component componentTwo;
}
  • 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-02T08:09:20+00:00Added an answer on June 2, 2026 at 8:09 am

    Sun Microsystems (now taken over by Oracle) published its Java Coding Style Guide in 1998, in which they recommended a particular organization to class declarations:

    1. Static variable field declarations
    2. Instance variable field declarations
    3. Static initializer
    4. Static member inner class declarations [*]
    5. Static method declarations
    6. Instance initializer
    7. Instance constructor declarations
    8. Instance member inner class declarations [*]
    9. Instance method declarations

    Note that this puts the data declarations at the top of the file. (An earlier Sun publication from 1997 did not cover everything in the above list.) The only important ordering is within the static fields and within the instance fields, and then only if the fields contain initializers that refer to other fields. You cannot use a field in an initializer before it itself has been initialized. Similarly, an initializer (item 3 or 6) cannot make a forward reference to a field, except as the target of an assignment. (See the Java Language Specification, Section 8.3.3, for more information on such forward references.) As far as I know, nothing else about the order matters.

    [*] The terminology in the above list (which is verbatim from the 1998 guide) is out of date with regards to items 4 and 8. Specifically, from the Java tutorial on nested classes:

    Terminology: Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are called static nested classes. Non-static nested classes are called inner classes.

    In modern usage, there is no such thing as a “static member inner class”.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from

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.