Results 1 to 4 of 4

Thread: Static keyword

  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default Static keyword

    Hi,

    What is the function of the static keyword without paramater.
    I know what "Public static void FunctionName()" means,
    but i found a class in examples with only the word "Static { ...... }"

    Java Code:
    public class LoggingExample {
        private static Logger logger = Logger.getLogger("test");
    
    static {
        try {
            logger.setLevel(Level.INFO);
    So, what is the meaning of this static keyword ?

    Kind regards
    Dipke

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Static keyword

    Get in the habit of using standard Java naming conventions!

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Static keyword

    Quote Originally Posted by Dipke View Post
    Hi,

    What is the function of the static keyword without paramater.
    I know what "Public static void FunctionName()" means,
    but i found a class in examples with only the word "Static { ...... }"

    Java Code:
    public class LoggingExample {
        private static Logger logger = Logger.getLogger("test");
    
    static {
        try {
            logger.setLevel(Level.INFO);
    So, what is the meaning of this static keyword ?

    Kind regards
    Dipke
    It's a static initializer block; it is run when the class code itself is loaded. People think that the code is only run once, but it is run once per class loader. If another class loader loads the same class, the static initialization block is run again. At the jvm level this is the <cinit> block of code (compared with the <init> block which is a non-static initialization block, i.e. run once for each instance).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default Re: Static keyword

    Hi Jos and kjkrum,

    Thanks for the answer.
    It's all clear now.

    Kind regards
    Dipke

Similar Threads

  1. Use of Static Keyword !
    By Jack_Tauson_Sr in forum New To Java
    Replies: 3
    Last Post: 04-18-2013, 08:24 AM
  2. Can the class be instantiated with the static keyword ?
    By kashyapkeshav in forum New To Java
    Replies: 2
    Last Post: 11-04-2012, 01:57 PM
  3. static keyword
    By lala in forum New To Java
    Replies: 19
    Last Post: 01-11-2011, 08:06 PM
  4. use of static keyword
    By venkatallu in forum New To Java
    Replies: 2
    Last Post: 06-25-2009, 07:53 AM
  5. Replies: 1
    Last Post: 08-07-2007, 05:05 AM

Tags for this Thread

Posting Permissions

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