2013년 5월 10일 금요일

Initializing a static variable

Static variables are initialized when a class is loaded. A class is loaded because the JVM decides it's time to load it.
Typically, the JVM loads a  class because somebody's trying to make a new instance of the class. As a programmer, you also have the option of telling the JVM to load a class, but you're  not likely to need to do that, In nearly all case, you're better off letting the JVM decide when to load the class.

And there are two guarantees about static initialization:

  1. Static variables in a class are initialized before any object of that class can be created.
  2. Static variables in a class are initialized before any static method of the class runs.
Static variables are initialized when the class is loaded. If you don't explicitly initialize a static variable(by assigning it a value at the time you declare it), it gets a default value, so int variables are initialized to zero.
Declaring, but not initializing, a static variable means the static variable will get the default value for that variable type, in exactly the same way that instance variables are given default values when declared.

댓글 없음:

댓글 쓰기

블록체인 개요 및 오픈소스 동향

블록체인(block chain) 블록체인은 공공 거래장부이며 가상 화폐로 거래할때 발생할때 발생할 수 있는 해킹을 막는 기술. 분산 데이터베이스의 한 형태로, 지속적으로 성장하는 데이터 기록 리스트로서 분산 노드의 운영자에 의한 임의 조작이 불가...