Skip to content

Commit

Permalink
chapter 09 : 자바를 배우면 패키지와 접근 제어자는 꼭 알아야 해요 공부 내용 정리 완료
Browse files Browse the repository at this point in the history
- `chapter 09 : 자바를 배우면 패키지와 접근 제어자는 꼭 알아야 해요` 공부 내용 정리 완료
- 이전 틀린 문서 형식, 틀린 내용 수정
- `Run Java`, `Build Java`, `Clean Java class file task` 추가

---

<<< 공부 내용 동기화 `commit`
<<< Merge remote-tracking branch `origin/main` into test
<<< 공부 내용 동기화 `commit` (#16)
<<< Merge branch `main` into `test`

<<< 문맥 수정
<<< 문단 형식 개선

---
  • Loading branch information
jbw9964 authored Feb 19, 2024
1 parent 6bbdbb1 commit c22cda5
Show file tree
Hide file tree
Showing 15 changed files with 456 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .vscode/ChangeSeparator.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off

@REM Usage: get_package_name.bat <relative_path_to_java_file>

set "java_file=%1%"

@REM Convert path separators to dots
set "package_name=%java_file:\=.%"

@REM Remove ".java" extension
set "package_name=%package_name:.java=%"

echo %package_name%
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type" : "java",
"name" : "Debug java",
"request" : "launch",
"mainClass" : "${file}",
"console" : "integratedTerminal",
"cwd" : "${workspaceFolder}",
"internalConsoleOptions" : "neverOpen",
}
],
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"workspaceKeybindings.CustomTasks.enabled": true
}
// User >> keybindings.json
// [
// {
// "key" : "ctrl+shift+j",
// "command" : "workbench.action.tasks.runTask",
// "when" : "config.workspaceKeybindings.CustomTasks.enabled",
// "args" : "Run Java"
// },
// {
// "key" : "ctrl+shift+i",
// "command" : "workbench.action.tasks.runTask",
// "when" : "config.workspaceKeybindings.CustomTasks.enabled",
// "args" : "Clean Java class files"
// }
// ]
128 changes: 128 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format

// List of variables in VsCode :
// https://code.visualstudio.com/docs/editor/variables-reference

"version" : "2.0.0",

// basics for general
"type" : "shell",
"options" : {"cwd" : "${workspaceFolder}"}, // should be project's directory
"problemMatcher": [],

// terminal properties for each platform
"windows" : {"options": {"shell": {
"executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", // absolute path to Powershell
"args" : [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command"
]}}},
"linux" : {},
"osx" : {},

// revealing options for general
"presentation" : {
"echo" : true,
"reveal" : "always",
"focus" : true,
"panel" : "shared",
"showReuseMessage" : true,
"clear" : false,
"revealProblems" : "onProblem"
},
"promptOnClose" : false,

"tasks" : [
{
"label" : "Build Java",
"group" : "build",

"command" : "javac",
"args" : [
"-g",
"${file}"
],

"detail" : "Compile current Java file",
"icon" : {
"id" : "file-code",
"color" : "terminal.ansiBlue"
},
},

{ // Keyboard Shortcuts : cmd + shift + J
"label" : "Run Java",
"group" : "build",

"command" : "java",
"dependsOn" : ["Build Java"],

// CLI for window powershell | in window, `\` is used as separator, causing `java.lang.NoClassDefFoundError`
"windows" : {
"command" : "${workspaceFolder}${/}.vscode${/}ChangeSeparator.bat", // use `ChangeSeparator.bat` to convert separator like unix
"args" : [
"${relativeFileDirname}/${fileBasenameNoExtension}",
"|",
"ForEach-Object",
"{",
"java",
"$_",
"}"
],
},

// CLI for unix shell | in unix, `/` is used as separator
"linux" : {}, "osx" : {},
"args" : ["${relativeFileDirname}/${fileBasenameNoExtension}"],

"presentation" : {"clear": true}, // clear terminal before execution
"detail" : "Compile & Execute current Java file",
"icon" : {
"id" : "run-all",
"color" : "terminal.ansiGreen"
}
},

{ // Keyboard Shortcuts : cmd + shift + I
"label" : "Clean Java class files",
"group" : "none",

// CLI for window powershell
"windows" : {
"command" : "Get-ChildItem",
"args" : [
"${workspaceFolder}",
"-Recurse",
"|",
"Where{$_.Name",
"-Match",
"'class'}",
"|",
"Remove-Item"
]
},

// CLI for unix shell
"linux" : {}, "osx" : {},
"command" : "find",
"args" : [
"${workspaceFolder}",
"-name",
"\\*.class",
"-type",
"f",
"-delete"
],

"detail" : "Clean every Java class files in Working Directory",
"icon" : {
"id" : "clear-all",
"color" : "terminal.ansiCyan"
},
}
],
}
6 changes: 1 addition & 5 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

Project_directory = ~/Desktop/Coding/God_of_java_practice
Practice_directory = ${Project_directory}/Practice
Scripts_directory = ${Project_directory}/scripts
Code_directory = ${Scripts_directory}/*/code

clean:
rm -rf ${Practice_directory}/*.class ${Code_directory}/*.class
find ${Project_directory} -name \*.class -type f -delete
2 changes: 1 addition & 1 deletion scripts/ch_03/extra/reserved_words_in_java.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
###### `private`, `protected`, `public` : `접근 제어자`, `access modifier`
- `접근 제어자` 키워드는 클래스 내 메서드, 필드, 내부 클래스 등의 접근을 제어하는 키워드이다.
- `private` 키워드를 이용할 시, 해당 클래스의 내부에서만 접근 가능하다.
- `protected` 키워드를 이용할 시, 해당 클래스의 내부와 해당 클래스를 상속받은 클래스 내부에서만 접근 가능하다.
- `protected` 키워드를 이용할 시, 해당 클래스의 내부와 해당 클래스를 상속받은 클래스 내부에서만 접근 가능하다. 더불어 같은 `package` 에 속한 경우에도 접근 가능하다.
- `public` 키워드를 이용할 시, 해당 클래스 외부에서도 접근 가능하다.

###### `abstract`
Expand Down
1 change: 1 addition & 0 deletions scripts/ch_08/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [`10. Pass by value, Pass by reference`](./section_10_11.md)
- [`11. 매개 변수를 지정하는 특이한 방법`](./section_10_11.md)

---

### What I learned from this chapter

Expand Down
18 changes: 18 additions & 0 deletions scripts/ch_09/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

### Chapter 09 : 자바를 배우면 패키지와 접근 제어자는 꼭 알아야 해요

- [`1. 패키지는 그냥 폴더의 개념이 아니에요`](./section_01_04.md)
- [`2. 패키지 이름은 이렇게 지어요`](./section_01_04.md)
- [`3. import 를 이용하여 다른 패키지에 접근하기`](./section_01_04.md)
- [`4. 자바의 접근 제어자`](./section_01_04.md)

---

### What I learned from this chapter

이번 챕터에서는 `Java``package` 에 관해 배웠다.

애초에 큰 관점에서 봤을 때, 다른 언어의 모듈, 라이브러리와 다른 점이 없기에 어려운 점은 없었다.
다만 세부적으로 봤을 때, 어느 클래스들이 같은 `package` 에 속해있으면 참조 가능하다는 점, `import` 구문은 `class body` 속에 선언될 수 없다는 점 등이 달랐다.

그리고 내용이 조금 널널한 김에 `Run Java`, `Clean Java class files` 같은 `task` 를 만들었다. 이를 단축키로 지정했고 좀 더 편하게 공부할 수 있을 것 같다.
9 changes: 9 additions & 0 deletions scripts/ch_09/code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

### Chapter 09 : 자바를 배우면 패키지와 접근 제어자는 꼭 알아야 해요 - 정리해 봅시다.

- `[1]` : `godofjava` 폴더 아래에 `b` 라는 폴더를 만들자.
- `[2]` : `b` 폴더 아래에 `array`, `control`, `operator`, `variable` 이라는 폴더를 만들자.
- `[3]` : `ArrayMain.java` 파일을 `godofjava/b/array` 폴더로 옮기자.
- `[4]` : `ArrayMain.java` 파일을 열어 `b.array` 라는 패키지로 선언하자.
- `[5]` : `ArrayMain` 클래스가 제대로 컴파일 되는지 확인해 보자.
- `[6]` : `b.control` 폴더에는 `ControlIf`, `b.operator` 폴더에는 `OperatorConditional`, `b.variable` 폴더에는 `VariableTypes` 클래스를 각각 이동하고, 패키지를 선언한 뒤 컴파일해 보자.
7 changes: 7 additions & 0 deletions scripts/ch_09/code/b/array/ArrayMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scripts.ch_09.code.b.array;

// file compiles successfully

public class ArrayMain {

}
7 changes: 7 additions & 0 deletions scripts/ch_09/code/b/control/ControIf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scripts.ch_09.code.b.control;

// file compiles successfully

public class ControIf {

}
7 changes: 7 additions & 0 deletions scripts/ch_09/code/b/operator/OperatorConditional.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scripts.ch_09.code.b.operator;

// file compiles successfully

public class OperatorConditional {

}
9 changes: 9 additions & 0 deletions scripts/ch_09/code/b/variable/VariableTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scripts.ch_09.code.b.variable;

// file compiles successfully

public class VariableTypes {
public static void main(String[] args) {

}
}
9 changes: 9 additions & 0 deletions scripts/ch_09/code/solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

### Chapter 09 : 자바를 배우면 패키지와 접근 제어자는 꼭 알아야 해요 - 정리해 봅시다.

- [`문제 설명`](./README.md)

---

문제에서 제시한 그대로 만들면 된다.
다만 `"정리해 봅시다"``import 는 클래스 내에 선언해도 되나요?` 문항이 있는데, 이는 사용될 수 없다.
Loading

0 comments on commit c22cda5

Please sign in to comment.