자바/안드로이드에서 정확한 변수의 이름!


Android/안드로이드 프로그래밍 2014.02.04 11:11




http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

http://leepoint.net/notes-java/data/variables/45local-inst-class.html

  • Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in "non-static fields", that is, fields declared without thestatic keyword. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
  • Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.
  • Local Variables Similar to how an object stores its state in fields, a method will often store its temporary state in local variables. The syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;). There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
  • Parameters You've already seen examples of parameters, both in the Bicycle class and in the main method of the "Hello World!" application. Recall that the signature for the main method is public static void main(String[] args). Here, the args variable is the parameter to this method. The important thing to remember is that parameters are always classified as "variables" not "fields". This applies to other parameter-accepting constructs as well (such as constructors and exception handlers) that you'll learn about later in the tutorial.


전역변수, 멤버변수, 로컬변수 등 다양한 이름의 변수들이 존재한다. 물론 의미만 통하면 개발자들 끼리 큰 문제는 없겠지만 정확한 명칭은 위와 같습니다. (Oracle Refrence 자료) 


 '인스턴스 변수'는 Static 이 아닌 변수를 의미합니다. 

 '클래스 변수'는 Static 으로 선언한 변수를 의미합니다. 

 '로컬 Variable' 변수는 method 안에서만 처리 되는 등 지역변수를 의미합니다. (쓰고 버려지는 변수를 의미합니다.) 



 

 

저작자 표시 비영리 변경 금지
신고

WRITTEN BY
ShakeJ

0 ,