public static void main(String[] args) {
int a; // 4byte(32bit) memory instance 생성
System.out.println("Local Variable a = " + a);
}
⭐ The local variable a may not have been initialized
→ java.lang.Error: Unresolved compilation problem 발생
Error 원인
int a 선언 후, 초기값을 지정하지 않음
: method 내부의 지역 변수(Local value)의 경우, garbage value가 초기에 저장되어있으므로 초기값 설정이 필요
해결방법
int a 선언 후, 초기값 지정
public static void main(String[] args) {
int a=0; // 4byte(32bit) memory instance 생성
System.out.println("Local Variable a = " + a);
}
➕ 전역 변수의 초기값 설정
public class Variable02 {
int a; // Field, Global Variable: Class 내부에서 사용 가능
// Field는 초기화가 되어있으므로 변수값 지정없이 사용 가능
double b;
static int c;
// static variable의 경우, memory 할당이 필요없이 자동으로 메모리에 공간이 부여되어있음(메모리 할당 선언 필요X)
public static void main(String[] args) {
Variable02 v = new Variable02(); // Variable Class memory 생성
// v: Variable02의 address 보유(Class_name@16진수_참조주소값)
System.out.println("Variable02: " + v);
// Variable02: basic.Variable02@515f550a (pkg.Class@ref_address)
System.out.println("Field a = " + v.a); // field 출력: Default 0
// Variable02의 주소값을 가진 v에서 해당 클래스의 필드값 a를 출력
System.out.println("Field b = " + v.b); // field 출력: Default 0.0
System.out.println("Field c = " + c); // field 출력: Default 0
// Variable02.c와 동일
// v.c 사용 필요 X
}
}
class에서 직접 선언되는 전역변수(Global value)의 경우에는 초기값 설정이 되어있으므로 초기값 설정 불요
public class Exam {
private char[] ox=null;
public void compare() {
for(int i=0; i<JUNG.length(); i++) {
if(dap.charAt(i)==JUNG.charAt(i)) {
ox[i] = (char)'O';
} else {ox[i] = (char)'X';}
} // for
} // compare
}
⭐ Exception in thread "main" java.lang.NullPointerException: Cannot store to char array because "this.ox" is null
→ NullPointerException 발생
Exception 원인
char[]를 선언 후, 배열의 크기를 지정해주는 초기화 작업을 진행하지 않음
해결 방법
public class Exam {
private char[] ox=null;
public void compare() {
ox = new char[JUNG.length()];
for(int i=0; i<JUNG.length(); i++) {
if(dap.charAt(i)==JUNG.charAt(i)) {
ox[i] = (char)'O';
} else {ox[i] = (char)'X';}
} // for
} // compare
}
/*
Result
O X X O O
*/
[root@hj0216 ~]# rdate
-bash: rdate: command not found # uninstalled
[root@hj0216 ~]# gcc
-bash: rdate: command not found # uninstalled
[root@hj0216 ~]# javac
-bash: rdate: command not found # uninstalled
[root@hj0216 ~]# locate
-bash: rdate: command not found # uninstalled
3. Network Test
[root@hj0216 ~]# ping -c3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=33.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=31.4 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=31.7 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 31.442/32.097/33.088/0.712 ms
4. ssh server connect
[root@hj0216 ~]# systemctl stop firewalld # 해당 session에서만 방화벽 끄기
[root@hj0216 ~]# systemctl disable firewalld # 모든 session에서 방화벽 끄기
[root@hj0216 ~]# systemctl start sshd # 해당 session에서만 ssh service 실행
[root@hj0216 ~]# systemctl enable sshd # 모든 session에서 ssh service 실행
[설정] -> [네트워크] -> [고급] -> [포트 포워딩]
포트 번호: 22, 80 추가
[파일] -> [환경설정] -> [입력] -> [가상머신] 호스트키 조합: F11 입력
(마우스 포인터를 리눅스에서 꺼내주는 역할)
PuTTY login
[root@hj0216 ~]# date
2023. 02. 05. (일) 14:18:32 KST
[root@hj0216 ~]# date -s "2000-12-12 21:30"
# 일자 및 시간 임의 지정