Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By jim829

Thread: What Does 'static, private....' Actually Mean?

  1. #1
    OxigEN. is offline Member
    Join Date
    Nov 2014
    Posts
    28
    Rep Power
    0

    Default What Does 'static, private....' Actually Mean?

    So I'd like to know what all the statement, not sure if it's the correct way of calling them but I'd like to know what
    like all of those purple-ish colored words in eclipse actually mean.

    Here's what I know so far, so if you can add some stuff to it or just correct me:

    public - can be accessed by different classes.
    private - can't be accessed by different classes.
    static - adds a '.' which pretty much lets you like use methods on it? Not really sure about this one.
    final - a final value of a variable meaning it couldn't and willn't change?
    super - I have no clue, maybe something that has to be executed first? Not sure.
    void - bassicly you don't have to use return as it doesn't return any value.
    this - Uh-.. I think it has something to do with the class this keyword has been entered into, not quite sure what it does though.

    I assume there are alot more but I am just not sure about these common ones, can anyone tell me what the actually do and what's their purpose? Aswell as if I get some of them right.
    Last edited by OxigEN.; 03-19-2015 at 05:57 PM.

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    384
    Rep Power
    10

    Default Re: What Does 'static, private....' Actually Mean?

    Your question has many different components. All of the terms you listed are considered keywords in JAVA, so they have a predefined meaning in the language. For that reason, you cannot use them as names for your variables, methods, or classes, or in general, as an identifier. That is the reason IDE's generally display them in some other color. At some point as you learn JAVA, you will come across all of them, and knowing when and how to use them is important.

    To answer one of your questions, the static keyword, when used with a variable or a method, indicates that that variable or method belongs to the CLASS as opposed to a particular INSTANCE of that class. An example of a static method would be the square root method (sqrt) that is a member of the Math class in JAVA. This method is marked as static, which means that in order to use that method, you do not have to create an INSTANCE of the Math class, you simply call the method on the Math CLASS:

    Java Code:
    double answer = Math.sqrt(81);
    Because the method sqrt is being called on the class itself, you use the class name followed by a period, then the method name, instead of actually creating an instance of the Math class (an object of type Math).

    As opposed to an INSTANCE method, that is tied to a particular instance of an object, for example, the length() method in the String class.

    Java Code:
    String exampleString = "ABCDefg";
    int wordLen = exampleString.length();
    Because the result of the call to the length method is very much tied to a particular INSTANCE of a String (in this case, exampleString), that method is NOT static, it is instead, an instance method. We are calling the length() method on an actual String, instead of on the class.
    Last edited by sehudson; 03-19-2015 at 06:33 PM.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: What Does 'static, private....' Actually Mean?

    Most of what you are asking can be answered in this section. I recommend you read it in its entirety.

    Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

    Regards,
    Jim
    DarrylBurke likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    OxigEN. is offline Member
    Join Date
    Nov 2014
    Posts
    28
    Rep Power
    0

    Default Re: What Does 'static, private....' Actually Mean?

    Thanks guys.

Similar Threads

  1. Replies: 15
    Last Post: 06-18-2014, 05:51 PM
  2. Retriving string from private static final class
    By KarlNorway in forum New To Java
    Replies: 9
    Last Post: 12-21-2011, 09:49 PM
  3. Replies: 2
    Last Post: 11-16-2010, 05:51 PM
  4. private static setter method problem
    By kyussy in forum New To Java
    Replies: 7
    Last Post: 01-27-2010, 04:02 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •