[2023.09.21] 개발자 교육 4일 차 : 강의-무한복습, 메소드, 파라미터, 오버로딩[구디 아카데미/김승수 강사님]

DaramGee·2023년 9월 21일
0

오늘 정

백엔드 개발자란? 보이지 않는 것을 작업하고 해결하는 사람이다.

private 사용하는 이유는? 외부에서 인스턴스 변수를 가지고 위변조를 막고 싶어서 캡슐화를 하는 것이다.

복습

  • 메모리 영역 관련 복습

  • 디버그 복습
    • 값을 불러오기 전에 꼭 디버그를 통해 진행 순서를 확인하기
    • 디버그 후 OS에 메모리 자원 반납을 위해 반드시 오른쪽의 x를 눌러서 종료하기

강의 내용

  • 클래스 내부에 두 개의 클래스가 있는 경우 실습(파라미터 안에 object 있는 경우)

    • NullPointException이 발동

    • 파라미터 안 Param 변수 이름이 바뀌는 것은 결과 값에 영향 x

    • 인스턴스화 시 null값으로 넣어도 오류x

      1. null로 호출될 경우, 주소번지가 생성?? →생성되지 않음
    • JAVA에서는 선언부가 아닌 생성부에서 객체가 생성

      1. 9번에서 생성되어서 가능
    • 9번, 15번이 주소번지가 같은지?

      1. (주소 번지 다름!!, 타입은 같지만 다른 객체를 참고하고 있어서 새로 생긴다)

  • VScode 설정

    • settin.json 생성 설정코드 입력

      {
          "terminal.integrated.defaultProfile.windows": "Git Bash",
          "terminal.integrated.profiles.windows": {
            "Git Bash": {
              "path": "C:\\Program Files\\Git\\bin\\bash.exe"
            }
          },
          "editor.suggestSelection": "first",
          "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
          "files.exclude": {
            "**/.classpath": true,
            "**/.project": true,
            "**/.settings": true,
            "**/.factorypath": true
          },
          "editor.tabSize": 2,
          "editor.lineHeight": 1.6,
          "editor.fontLigatures": false,
          "workbench.colorTheme": "Jetbrains Fleet",
          "java.project.importHint": false,
          "redhat.telemetry.enabled": false,
          "editor.fontFamily": "JetBrains Mono, D2Coding, Consolas, 'Courier New', monospace",
          "workbench.startupEditor": "none",
          "explorer.compactFolders": false,
          "workbench.iconTheme": "material-icon-theme",
          "emmet.variables": {
            "lang": "ko"
          },
          "vsicons.dontShowNewVersionMessage": true,
          "liveServer.settings.donotShowInfoMsg": true,
          "liveServer.settings.CustomBrowser": "chrome",
          "html-css-class-completion.enableEmmetSupport": true,
          "editor.tokenColorCustomizations": {
            //"comments": "#ffc2c2"
            "comments": "#0aef47"
          },
          "[css]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
          },
          "[html]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
          },
          "bracketPairColorizer.depreciation-notice": false,
          "workbench.colorCustomizations": {
            "titleBar.activeBackground": "#3F708D",
            "titleBar.inactiveBackground": "#3F708D",
            "[Material Theme Darker High Contrast]": {
              "activityBarBadge.background": "#F44336",
              "activityBar.activeBorder": "#F44336",
              "list.activeSelectionForeground": "#F44336",
              "list.inactiveSelectionForeground": "#F44336",
              "list.highlightForeground": "#F44336",
              "scrollbarSlider.activeBackground": "#F4433650",
              "editorSuggestWidget.highlightForeground": "#F44336",
              "textLink.foreground": "#F44336",
              "progressBar.background": "#F44336",
              "pickerGroup.foreground": "#F44336",
              "tab.activeBorder": "#F44336",
              "notificationLink.foreground": "#F44336",
              "editorWidget.resizeBorder": "#F44336",
              "editorWidget.border": "#F44336",
              "settings.modifiedItemIndicator": "#F44336",
              "settings.headerForeground": "#F44336",
              "panelTitle.activeBorder": "#F44336",
              "breadcrumb.activeSelectionForeground": "#F44336",
              "menu.selectionForeground": "#F44336",
              "menubar.selectionForeground": "#F44336",
              "editor.findMatchBorder": "#F44336",
              "selection.background": "#F4433640",
              "statusBarItem.remoteBackground": "#F44336"
            }
          },
          "[javascript]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
          },
          "js/ts.implicitProjectConfig.strictNullChecks": true,
          "indentRainbow.colors": [
            "rgba(255,255,64,0.07)",
            "rgba(127,255,127,0.07)",
            "rgba(255,127,255,0.07)",
            "rgba(79,236,236,0.07)"
          ],
          "json.schemas": [],
          "git.enableSmartCommit": true,
          "settingsSync.ignoredExtensions": [],
          "editor.codeActionsOnSave": {},
          "javascript.updateImportsOnFileMove.enabled": "always",
          //"java.jdt.ls.java.home": "C:\\jdk11",
          "java.jdt.ls.java.home": "C:\\Program Files\\Zulu\\zulu-17\\",
          "java.configuration.runtimes": [],
          "rsp-ui.enableStartServerOnActivation": [
            {
              "id": "redhat.vscode-community-server-connector",
              "name": "Community Server Connector",
              "startOnActivation": true
            }
          ],
          //"java.debug.settings.console": "internalConsole",
          "java.test.config": {},
          "java.jdt.ls.vmargs": "-javaagent:\"C:/VsCode-Java2022/lombok.jar\"",
          "window.zoomLevel": 1,
          "editor.accessibilitySupport": "off",
          "boot-java.rewrite.reconcile": true,
          "git.confirmSync": false,
          "files.autoSave": "afterDelay",
          "[python]": {
            "editor.formatOnType": true
          },
          "editor.defaultFormatter": "redhat.java",
          "git.openRepositoryInParentFolders": "never",
          "[javascriptreact]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
          },
          "rsp-ui.rsp.java.home": "C:\\Program Files\\Zulu\\zulu-17\\",
          "terminal.integrated.tabs.enabled": false,
          "editor.fontSize": 16,
        }
    • 확장프로그램 설치 → java, material, rainbow

    • 이클립스 설치경로 복사 (jdk 설치 경로 복사)→ 코드 부분 수정 89번, 114번 수정 (예 : "C:\Program Files\Zulu\zulu-17\”)

    • 프로젝트는 이클립스에서 만들되, vs코드에서 실행해보는 방식으로 진행 예정

    • 오류 해결 경로

      Untitled

    • 에러 참고 : https://oysu.tistory.com/50

    • 이클립스 자동연동(refrash)

      Untitled

      Untitled

  • private을 실행할 수 있는 방법 실습

    • private 사용 이유 : 외부에서 인스턴스 변수를 가지고 위변조를 막고 싶어서 -> 전변으로 만들어 캡슐화!!

    • package com.step2;
      //클래스 안에 여러가지의 변수를 담을 수 있다. 
      public class Dept {  //private을 실행할 수 있는 방법 실습
        private int deptno = 0;//부서번호 
        private String dname = null;//부서명 
        private String loc = null;//근무지역 
        //wirte, save
        public void setDeptno(int deptno){
          this.deptno = deptno; //this -> 이 클래스일 때 사용, 전역변수에 파라미터에 들어간 숫자가 담아질 수 있음.
        }
        public void setDname(String dname){
          this.dname = dname; //this -> 이 클래스일 때 사용, 전역변수에 파라미터에 들어간 숫자가 담아질 수 있음.
        }  
        public void setLoc(String loc){
          this.loc = loc; //this -> 이 클래스일 때 사용, 전역변수에 파라미터에 들어간 숫자가 담아질 수 있음.
        } 
        //read
        public int getDeptno(){
          return deptno;//전역변수
        }
        public String getDname(){
          return dname;//전역변수
        }
        public String getLoc(){
        return loc;//전역변수
        }
      }
      package com.step2;
      
      public class DeptSimulation {
        //Dept 클래스를 설계하고 그 안에 부서집합에 필요한 변수 3개를 선언(부서번호, 이름, 지역)
        //단 접근제한자를 private으로 하여 직접 접근x
        //왜냐하면 외부에서 인스턴스 변수를 가지고 위변조를 막고 싶어서 -> 전변으로 만들어 캡슐화!! 
      
        public static void main(String[] args) {
          Dept dept = new Dept(); //10
          // dept.deptno = 10; //private에 써있기 때문 -> 해결 : 메소드(함수)
          dept.setDeptno(10); //정수만 올 수 있는 자리 -> 전역변수에 저장됨 //20
          int deptno = 30; //30
          dept.setDeptno(deptno);
          System.out.println(dept.getDeptno());
          // dept.dname = "개발부" //private이라서 직접 접근  x, set 메소드 사용
          dept.setDname("개발부");
          String dname = "운영팀";
          dept.setDname(dname);
          System.out.println(dept.getDname());
        }
      }
    • 클래스를 나눠서 연습하는 작업 필요 → 재사용성, 이식성을 높이기 위해

    • Object의 함수

  • Getters and Setters 메소드

    • 넣는 범위 드래그 → source → generate getters and setters
  • 해결해보기

    • 메소드 오버로딩 : 자바에서는 같은 이름의 메소드를 중복 선언할 수 있다.
      • 무조건 파라미터 갯수 or 타입이 달라야 메소드 오버로딩으로 인정된다.
      • 내일 학습예정(관련링크 : https://2018-start.tistory.com/46)
package com.step2;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JPanel2 {
	JFrame jf = new JFrame();
	//화면을 그리는 메소드 선언
	
	public void initDisplay() {
		jf.setSize(width, height); // int 형식
		jf.setVisible(isView); //boolean 형식
	}
	public static void main(String[] args) {
		JPanel2 jp1 = new JPanel2();
		jp1.initDisplay(); //전변으로 이 문제를 해결해 보자 -> 3개의 변수 필요
	}

}
package com.step2;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JPanel2 {
	JFrame jf = new JFrame();
	//화면을 그리는 메소드 선언
	
	public void initDisplay(int width, int height, boolean isView) {//파라미터 많아지면 param 쓰기
 		jf.setSize(width, height); // int 형식
		jf.setVisible(isView); //boolean 형식
	}
	public static void main(String[] args) {
		JPanel2 jp1 = new JPanel2();
		jp1.initDisplay(600, 800, true); //전변으로 이 문제를 해결해 보자 -> 3개의 변수 필요
	}

}
package com.step2;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JPanel2 {
	JFrame jf = new JFrame();
	//화면을 그리는 메소드 선언
	public void initDisplay(int width, int height) {//파라미터 많아지면 param 쓰기
 		jf.setSize(width, height); // int 형식
		jf.setVisible(true); //boolean 형식
	}
	
	public void initDisplay(int width, int height, boolean isView) {//파라미터 많아지면 param 쓰기
 		jf.setSize(width, height); // int 형식
		jf.setVisible(isView); //boolean 형식
	}
	public static void main(String[] args) {
		JPanel2 jp1 = new JPanel2();
		jp1.initDisplay(600, 800); //위에 두개 값을 넣어도 실행되는 메소드가 있기 때문에 두개의 갑만 넣어도 실행 가능
	}

}

0개의 댓글