Skip to content
Snippets Groups Projects
Unverified Commit 0d7099cb authored by Joylish's avatar Joylish Committed by GitHub
Browse files

Merge pull request #1 from Joylish/kotlin-programming-unit2

인텔리제이, 변수 및 타입관련 코틀린 마크다운 그리고 실습 코틀린 파일
parents 8fc00db8 22da70d4
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
2. 프로젝트 생성 대화상자에서 'Kotlin/JVM' 선택하고 Next를 누른다.
이를 통해 kotlinc-jvm컴파일러를 사용해서 코틀린 코드를 JVM(Java Virtual Machine)에서 실행할 수 있는 바이트코드로 변환할 수 있다. 우리는 이 과정을 '컴파일'이라고 부른다.
이를 통해 kotlinc-jvm 컴파일러를 사용해서 <u>코틀린 코드</u>를 JVM(Java Virtual Machine)에서 실행할 수 있는 바이트코드로 변환할 수 있다. JVM은 변환된 <u>바이트 코드</u>를 콘솔에 출력한다. 우리는 이 과정을 <strong>컴파일</strong>이라고 부른다.
![NewProjectsBox](./captures/NewProjectsBox.png)
......@@ -32,9 +32,9 @@
<strong> 실행하고자 하는 코드를 작성 → ctrl + enter</strong>
![ExecutingKotlinREPL](./captures/ExecutingKotlinREPL.png)
### 인텔리제이 기능 단축키
* *ctrl + shift + f10*: 프로그램 실행 (Run '~~~.kt')
*
\ No newline at end of file
# 인텔리제이 사용법 (2)
### 인텔리제이 기능 단축키
- <u>*'main' 작성 + tab*</u>: fun main(){ } 자동 생성
- *ctrl + shift + f10*: 프로그램 실행 (Run '~~~.kt')
-
\ No newline at end of file
# 코틀린 정리하면서 공부하기 (1)
## 변수, 상수, 타입
#### 1. 정의
- <b>변수(variable)</b><b>상수(constant)</b>
애플리케이션에서 값을 저장하고 데이터를 전달할 수 있는 어떤 공간
- <b>데이터 타입</b>
상수나 변수에 저장된 데이터 유형
#### 2. 변수
* 변수 생성
##### [변수 정의 키워드] [변수이름] : [타입 정의] [대입 연산자] [대입값]
*예시) var experiencePoints : Int = 5*
* 변수 정의 키워드 종류
**런타임 생성 변수**
프로그램이 실행되는 동안 변수들이 생성되어 값이 지정된다.
* **var - <u>값이 변경</u>되는 변수**
variable 라고 한다.
* **val - <u>값이 변경되지 않는</u> 변수**
**(단, 상수(constant)는 아니다)**
value (= read-only variable) 라고 한다.
var이 필요하지 않을 때는 val을 사용하는 것이 바람직하다.
**컴파일 상수** (컴파일시 생성되는 변수)
모든 함수의 외부에 정의되어 값이 지정된다. 따라서 프로그램 실행 전에 컴파일러가 알 수 있어야하기 때문에 [기본타입](#기본타입)중 하나여야 한다.
* **constant val **
```kotlin
const val MAX: Int = 100000
fun main (){
...
}
```
* if 대입값의 타입이 타입 정의 에 정의한 타입과 다르면
**인텔리제이**는!
<u>정적 타입 검사(static type checking)</u> 를 하여 프로그램이 컴파일하기 전에 오류를 알려준다.
컴파일 후 **코틀린 컴파일러**는!
코틀린이 <u>정적 타입 시스템</u>이기 때문에 코틀린 컴파일러가 컴파일 시점에 코드의 적합 여부를 알려준다.
#### 3. 타입
* 기본타입
| String | Float | Byte |
| ---------- | --------- | ----------- |
| **Int** | **Long** | **Char** |
| **Double** | **Short** | **Boolean** |
자바에서 기본타입은 소스코드 파일로 정의되지 않으며 키워드로 나타내진다. 반면에 참조 타입은 별 개의 소스 코드 파일로 정의된다. 자바와 다르게 코틀린에서는 기본타입도 참조타입으로 지원한다.
* **타입 추론**
​ 변수를 선언할 때는 타입을 생략해도 된다. 코틀린 컴파일러가 변수 타입을 알고 처리해준다.
```kotlin
val username01: String = "Joylish" // 기본 변수 생성; 타입 String 선언
val username02 = "Happy" // 타입 생략
```
documents/captures/ExecutingKotlinREPL.png

19.4 KiB

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="ce152a44-3679-4b6f-b288-a2eb11b5ddac" name="Default Changelist" comment="" />
<list default="true" id="ce152a44-3679-4b6f-b288-a2eb11b5ddac" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../../documents/AboutInteliJ.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/sandbox/TypeIntroKt.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/sandbox/TypeIntroKt.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TypeIntro.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/TypeIntro.kt" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -10,16 +15,15 @@
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DefaultGradleProjectSettings">
<option name="testRunner" value="GRADLE" />
<option name="delegatedBuild" value="true" />
<option name="isMigrated" value="true" />
</component>
<component name="FileEditorManager">
<leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/TypeIntro.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="57">
<caret line="3" column="1" lean-forward="true" selection-start-line="3" selection-start-column="1" selection-end-line="3" selection-end-column="1" />
<state relative-caret-position="209">
<caret line="11" column="32" selection-start-line="11" selection-start-column="32" selection-end-line="11" selection-end-column="32" />
</state>
</provider>
</entry>
......@@ -34,6 +38,9 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
......@@ -46,11 +53,14 @@
<option name="width" value="980" />
<option name="height" value="1040" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
......@@ -62,25 +72,14 @@
<item name="sandbox" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
</path>
<path>
<item name="sandbox" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="&lt; 1.8 &gt;" type="70bed36:NamedLibraryElementNode" />
</path>
<path>
<item name="sandbox" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="KotlinJavaRuntime" type="70bed36:NamedLibraryElementNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
</component>
<component name="RunDashboard">
......@@ -128,49 +127,53 @@
</task>
<servers />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
<is-autoscroll-to-source value="true" />
</todo-panel>
<todo-panel id="all">
<are-packages-shown value="true" />
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="-7" y="-7" width="1550" height="838" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24966443" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25302014" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Terminal" weight="0.3286119" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Messages" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
<window_info id="UI Designer" order="4" />
<window_info id="Capture Tool" order="5" />
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.3286119" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32765958" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Maven" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32907802" />
<window_info anchor="bottom" id="Terminal" order="7" weight="0.32765958" />
<window_info anchor="bottom" id="Event Log" order="8" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="9" weight="0.32907802" />
<window_info anchor="bottom" id="Messages" order="10" weight="0.32907802" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Palette" order="3" />
<window_info anchor="right" id="Maven" order="4" />
<window_info anchor="right" id="Theme Preview" order="5" />
<window_info anchor="right" id="Capture Analysis" order="6" />
<window_info anchor="right" id="Palette&#9;" order="7" />
</layout>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/TypeIntro.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="22" selection-start-column="22" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/TypeIntro.java" />
<entry file="file://$PROJECT_DIR$/src/TypeIntro.kt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="57">
<caret line="3" column="1" lean-forward="true" selection-start-line="3" selection-start-column="1" selection-end-line="3" selection-end-column="1" />
<state relative-caret-position="209">
<caret line="11" column="32" selection-start-line="11" selection-start-column="32" selection-end-line="11" selection-end-column="32" />
</state>
</provider>
</entry>
......
No preview for this file type
fun main() {
var experiencePoints: Int = 5
println(experiencePoints)
val playerName = "에스트라곤"
val barName = "Unicorn's Horn"
val barOwnerName = "디오니소스"
var hasSteed = "false"
var experiencePoints = 5
val alcoholList = listOf("honey beer", "wine", "Lacroix")
var goldfinich = 0
experiencePoints += 5
goldfinich += 50
println(playerName + "의 점수는 " + experiencePoints)
println("현재 말을 소유하고 있는지 여부: " + hasSteed)
println(barName + "에 도착했다.")
println(playerName + "은 이렇게 말했다")
println("나는 금화 "+ goldfinich+ "개가 있으니 술을 먹겠다.")
println("술집주인 " + barOwnerName + "는 말한다")
println("현재 " + alcoholList +"가 있습니다. 무엇을 드릴까요?")
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment