public class VariableType {
int num;//인스턴스 변수
static int num2;//클래스 변수
public void method1(int num3) {//매개변수
int num4;//지역변수
}
}

public class Test {
public static void main(String[] args) {
//long longMax = 9223372036854775807;//컴파일 에러
long longMax = 9223372036854775807L;
}
}0.2 + 0.2 => 0.00110011....+ 0.00110011....//0.4값으로 계산되지 않음인텔리제이서 지역변수 값을 셋팅 하지않았을 경우 초기화 하라는 경고 메세지를 띄운다.

기본 자료형 이외의 자료형 타입.
참조 자료형은 생성자를 통해 생성하는데 생성자가 없을경우 컴파일 시 자동으로 기본생성자를 만들어준다.
public class Test {
public Test() {}
public static void main(String[] args) {
Test test = new Test();
}
}
단, 다른 매개변수를 받는 생성자가 있다면 기본생성자를 자동으로 만들어주지 않으므로 따로 생성해야한다.
public class Test {
public Test() {}
public Test(String str) {}
public static void main(String[] args) {
Test test = new Test();
}
}
new키워드를 통해 초기화 한다.
Caculator caculator = new Calculator();
예외 케이스로 String 초기화 시에는 String test = “test”;와 같이 초기화 한다. String은 참조자료형 생성방법과 동일하게 String test = new String(”test”); 도 가능하지만 리터럴 방식을 사용한다.
IDE에서 문법적 오류라고 알려주지만 개발자가 이 객체를 생성할 때 어떤 타입의 매개변수로 객체가 생성되는지 확인해야한다.
public class Test {
private String test;
public Test(String str) {
this.test = str;
}
public static void main(String[] args) {
int tmp = 0;
Test test = new Test(tmp);
}
}
public class ProfilePrint {
String name;
byte age;
boolean isMarried;
public byte getAge() {
return age;
}
public String getName() {
return name;
}
public boolean isMarried() {
return isMarried;
}
public void setName(String name) {
this.name = name;
}
public void setAge(byte age) {
this.age = age;
}
public void setMarried(boolean married) {
isMarried = married;
}
public static void main(String[] args) {
ProfilePrint profile = new ProfilePrint();
profile.setName("Min");
profile.setAge((byte)20);
profile.setMarried(false);
System.out.println("profile.getName() = " + profile.getName());
System.out.println("profile.getAge() = " + profile.getAge());
System.out.println("profile.isMarried = " + profile.isMarried);
}
}
일반 변수의 이름을 지을 때 대문자로 시작하는 것은 일반적인 명명규칙이다.
char a = ‘a’;참조