inblog logo
|
Coding's note
    computer basics

    final 변경불가

    이소연's avatar
    이소연
    Aug 03, 2024
    final 변경불가
    💡
    final은 최초에 값이 할당되면, 값 변경이 불가능하다.
    package ex02; public class ConstEx01 { public static void main(String[] args) { int num = 1; // 변수 final int sum = 10; // 상수(변경 불가능) num = 2; //sum = 20; } }
    💡
    캐스팅
    package ex02; public class CastEx01 { public static void main(String[] args) { int n1 = 1; double d1 = 1.5; n1 = 2; n1 = d1; //업 캐스팅(작은걸 -> 큰걸로) d1 = n1; // 묵시적 형변환 System.out.println(d1); n1 = (int)d1;//다운 캐시팅(큰 걸 -> 작은걸로) System.out.println(n1); } }
     
    💡
    변수 사용법
    변수 띄어쓰기 x
    변수는 카멜 표기법
    변수는 키워드 단어도 쓰지 x-v
    주석 /**
     
    package ex02; /** * 변수 작성법 * 1. 카멜(낙타)표기법 사용 * 2. 숫자를 먼저 사용하지 않는다. * 3. 특수문자는 사용하지 않는다. */ public class IdenEx01 { public static void main(String[] args) { //int public = 1; int abc__; // 절대 사용 안함!!! int user_money; // 절대 사용안함! int userMoney; // 낙타 표기법 //int abc#; int method; double abc$$; // 그냥 특수문자 사용하지 말자. int 1stMoney; // 숫자로 변수를 시작할 수 없다. } }
     
    jvm은 분석할 때 static을 먼저 찾음
     
     
    메모리를 효율적으로 관리하기 위해 동적할당/정적할당 나눔
     
    힙
    : 동적 할당(new), 여러 번 띄울 수 있음, 변수를 만들어야 함.
    package ex04; class Person2 { int age = 10; char gender = '남'; } public class MemEx02{ public static void main(String[] args) { System.out.println("1년 지남"); System.out.println("2년 지남"); System.out.println("3년 지남"); Person2 p = new Person2(); System.out.println("메인 종료"); } }
    static : 정적 할당
    문자 ‘’ 문자열 “”
    git 강제 형상 push : git push -f origin master
     
    package ex04; /** * 커스텀 자료형(내가 정의한 자료형) */ class Person1{ static int age = 20; static char gender = '여'; } public class MemEx01 { public static void main(String[] args) { System.out.println(Person1.age); System.out.println(Person1.gender); } }
    notion image
    notion image
    package ex04; class Person2 { int age = 10; char gender = '남'; } public class MemEx02{ public static void main(String[] args) { System.out.println("1년 지남"); System.out.println("2년 지남"); System.out.println("3년 지남"); Person2 p2 = new Person2(); System.out.println(p2.age); System.out.println(p2.gender); System.out.println("메인 종료"); } }
    notion image
    notion image
    Share article

    Coding's note

    RSS·Powered by Inblog