국비 지원 개발자 과정 _Day 3
작업환경 설정
JVM17 버전 설치-https://adoptium.net/ //시스템 속성-고급-환경변수-시스템 변수-path-좌표 확인
cmder-https://cmder.app/ (참고- [CMDER] 💽 cmder 설치 & 설정 (+ 문자 깨짐 해결법) (tistory.com))
VSCode(git과 연동)-https://code.visualstudio.com/download //시스템 인스톨러 x64, 기타 체크박스 전부 체크
설치-Extension Pack for Java/Spring Initializr Java Support/Gradle for Java/Material Icon Theme/Material Theme/GitLens — Git supercharged/indent-rainbow/Korean Language Pack for Visual Studio/Live Server/Lombok Annotations Support for VS/Prettier - Code formatter/Eclipse Keymap/Getter and Setter Generator
//f1 - create java project - gradle - 폴더(vscode_java → dev_java) - groovy - setting.jason 바꾸기(103경로확인/맘에들게편집-vsc어둡게’글자15’주석9fd0b4) - 깃 로그 세팅
Git설치-https://git-scm.com/download/win
setting.jason
물리적인 위치 : C:\Users\master\AppData\Roaming\Code\User\settings.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.fontSize": 18,
"editor.fontLigatures": null,
"workbench.colorTheme": "Material Theme Darker High Contrast",
"java.project.importHint": false,
"redhat.telemetry.enabled": false,
"editor.formatOnSave": true,
"editor.fontFamily": "CookieRun, D2Coding, Consolas, 'Courier New', monospace",
"workbench.startupEditor": "none",
"explorer.compactFolders": false,
"python.analysis.extraPaths": [
"./myvenv/Chapter9",
"./myvenv/Chapter9/startcoding"
],
"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"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"bracketPairColorizer.depreciation-notice": false,
"files.autoSave": "afterDelay",
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#3F708D",
"titleBar.inactiveBackground": "#3F708D"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"js/ts.implicitProjectConfig.strictNullChecks": true,
"peacock.favoriteColors": [
{
"name": "Angular Red",
"value": "#DD0531"
},
{
"name": "Azure Blue",
"value": "#007FFF"
},
{
"name": "JavaScript Yellow",
"value": "#F9E64F"
},
{
"name": "Mandalorian Blue",
"value": "#1857A4"
},
{
"name": "Node Green",
"value": "#215732"
},
{
"name": "React Blue",
"value": "#61DAFB"
},
{
"name": "Something Different",
"value": "#832561"
},
{
"name": "Svelte Orange",
"value": "#FF3D00"
},
{
"name": "Vue Green",
"value": "#42B883"
}
],
"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": [],
"window.zoomLevel": 1,
"git.enableSmartCommit": true,
"settingsSync.ignoredExtensions": [],
"editor.codeActionsOnSave": {},
"javascript.updateImportsOnFileMove.enabled": "always",
"java.jdt.ls.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.5.8-hotspot",
"java.configuration.runtimes": [],
"rsp-ui.enableStartServerOnActivation": [
{
"id": "redhat.vscode-community-server-connector",
"name": "Community Server Connector",
"startOnActivation": true
}
],
"java.debug.settings.console": "internalConsole"
}
깃로그
git config --global -e 엔터치고
[core]
editor = code
[user]
name = 이름
email = 이메일
[core]
autocrlf = true
editor = code --wait
[pull]
rebase = false
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code --wait $MERGED
[alias]
st = status
hist = log --graph --all --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(white)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --date=short
vsc-git연동(vsc로 repository 생성)
로컬 스토리지(↔웹스토리지) 설정해야 함
git설정 파일을 추가하고 숨김 파일 처리함(git init)
vsc터미널(gitconfig)에 git init
커멘더에 ls -al / git add . / git status / git commit -m "코멘트입력” / git hist
소스 제어에서 게시 - public - 정기실행 아니요
git workflow
working directory(이하 w.d) → staging area(s.a) →git diregtory(g.d) ==⇒ git server
w.d에 파일 추가(내 컴퓨터에 존재)
git add . 파일명(파일이 s.a로 이동/아직에 존재 로컬)
git add *.txt(모든 txt 파일이 s.a로 이동/로컬)
git rm --cached 파일명(다시 w.d로 이동/로컬)
git commit 파일명 “코멘트 입력”(a파일이 g.d에 올라감/로컬)
git hist(히스토리 확인)
echo hello world > a.txt(hello world를 넣은 a.txt 파일 생성)
echo java >> a.txt(내용을 java로 변경/add와 commit 다시 해줘야 함)
git log --pretty(자세한 로그)
package dev_java.ch01;
public class Hello {
int methodA(int i, int j) {
int hap;
hap = i + j;
return hap;
}
public static void main(String[] args) {
Hello hello = new Hello();
hello.methodA(2, 3);
System.out.println("git 설정 추가");
System.out.println("Hello Java!!!");
}
}
// git 설정 추가
// Hello Java!!!
package dev_java.ch01;
// static은 변수 앞에, 메소드 앞에 올 수 있다.
// static이 있으면 정적변수, 정적 메소드라 한다.
// static은 인스턴스화 없이 어디서나 호출할 수 있다.
// static은 non-static에서 호출할 수 있다.
public class StaticExam1 {
int i; // 전역변수는 초기화를 생략할 수 있다. 그러면 디폴드값은 0이다.
static int j;
void methodA() {
i = i + 1;
j = i * 2;
System.out.println("i: " + i); // 1
System.out.println("j: " + (StaticExam1.j)); // 2
}
public static void main(String[] args) {
StaticExam1 staticExam1 = new StaticExam1();
staticExam1.methodA();
}
}
// i: 1
// j: 2
메모리 영역
stack / heap
stack안에 지역변수 int i
heap안에 클래스, methodA(), 전역 변수 int x
인스턴스 변수명.변수명 → 오직 전역 변수만 가능하다!!(variable1.x)
static이 붙어있으면 → 클래스타입.변수명(아래의 코드에서 public class Variable1부분의 Variable1이 클래스타입)
package dev_java.ch01;
public class Variable1 {
static int x; // 전역변수
// 나는 파라미터가 없는 메소드.(소통x)
// 나는 반환형이 없다.(대답x)
void methodA() {
int i; // 지역변수는 초기화를 생략할 수 없다!(사용하지 않았기에 컴파일에러X)
i = 1;
x = i; // 전역변수x를 이용해 지역변수를 메소드 밖에서 다룰 수 있다.
System.out.println("i: " + i);
}
public static void main(String[] args) {
Variable1 variable1 = new Variable1(); // 선언이 사용보다 앞에 와야한다.
System.out.println("x: " + variable1.x); // static 영역 안에서는 non-static 타입을 호출할 수 없다.
variable1.methodA(); // i의값
// System.out.println(variable1.x); // 1, 순서가 중요(i값을 대입해 x가 1)
}
}
// x: 0
// i: 1
package dev_java.ch01;
public class StaticExam2 {
public static void main(String[] args) {
StaticExam1 staticExam1 = new StaticExam1(); // 다른 클래스인 StaticExam1을 인스턴스화
staticExam1.methodA();
}
}
// i: 1
// j: 2
package dev_java.ch01;
public class StaticExam3 {
public static void main(String[] args) {
StaticExam1 staticExam1 = new StaticExam1();
StaticExam1 staticExam2 = new StaticExam1();
StaticExam1 staticExam3 = new StaticExam1(); // 여러번 인스턴스화 가능
staticExam1.methodA();
staticExam2.i = 5;
staticExam3.i = 3; // 전역변수 재정의 가능
System.out.println(staticExam1.i); // 1
System.out.println(staticExam2.i); // 5
System.out.println(staticExam3.i); // 3
}
}
package dev_java.ch01;
class Param {
int ival;
}
public class TestParam {
void effectParam(Param p) { // 직접 정의한 Class Param을 파라미터로 사용
// insert here-아래에 p = new Param()이 있으면 결과가 달라진다.(없을땐 같은 주소이기에 둘 다 500이 나온다.)
p = new Param(); // 다시 인스턴스화해서 주소값이 달라짐
p.ival = 500;
System.out.println("sub ival ===> " + p.ival); // 500
}
public static void main(String[] args) {
TestParam tp = new TestParam();
Param cp = new Param();
tp.effectParam(cp);
System.out.println("main ival ===>" + cp.ival); // 0, 디폴트값
}
}
// sub ival ===> 500
// main ival ===>0