-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9765145
commit 51e3981
Showing
1 changed file
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
title: "Hello, Java!" | ||
toc: true | ||
toc_sticky: true | ||
categories: ["Kafka"] | ||
excerpt: "βοΈ" | ||
--- | ||
|
||
# Javaμλ νμ€ μ€νκ³Ό ꡬνμ²΄κ° μμ. | ||
|
||
Javaλ μ΄λ°μ΄λ° κΈ°λ₯μ λ§μ‘±ν΄μΌ νλ€λ νμ€ μ€νμ΄ μμ! κ·Έλ¦¬κ³ κ·Έλ° μ€νμ λ§κ² ꡬνν "ꡬν체"κ° μμ. | ||
|
||
- OpenJDK (Oracle) | ||
- Corretto (Amazon) | ||
|
||
ꡬν체 λ§λ€ λμμ λμΌνμ§λ§, λ΄λΆμ μΌλ‘ κ°μμ μ λ§μ λ§κ² μ΅μ νν λΆλΆλ€μ΄ μμ κ²μ. Corretto κ°μ κ²½μ°λ AWS μλΉμ€λ κΆν©μ΄ μ’λ€κ³ ν¨. | ||
|
||
Java νμ€ μ€νμλ `javac` μ»΄νμΌλ¬, Run Lib, JVMκ³Ό κ°μ κ²λ€μ΄ μμ΄μΌ νλ€κ³ λͺ μ λμ΄ μμ. | ||
|
||
# Java μ»΄νμΌ | ||
|
||
`javac` μκ² Javaμμμ μ»΄νμΌλ¬μ. Cμμμ `gcc` κ°μ λ μμ. | ||
|
||
`java`λ java 컨νμΌλ `.class` νμΌμ μ€ννλ λ μμ. | ||
|
||
# Static Method & Variable | ||
|
||
ν΄λμ€ μΈμ€ν΄μ€κ° μλλΌ ν΄λμ€ μ체μ κ³ μ λ λ©€λ²μ. κ·Έλμ ν΄λμ€ μΈμ€ν΄μ€λ₯Ό λ§λ€μ§ μκ³ λ Methodλ Variableμ νΈμΆν μ μμ΅λλ€. | ||
|
||
`static` Variableμ λͺ¨λ ν΄λμ€μμ 곡μ νκ² λ©λλ€. λ©λͺ¨λ¦¬ μΈκ·Έλ¨ΌνΈ κ΄μ μμ 보면 `DATA` μΈκ·Έλ¨ΌνΈμ μ μ₯λλ λ³μλΌκ³ λ³Ό μ μκ³ , ν΄λμ€λΌλ μμμ λ°μΈλ©λ Global Variableλ‘ λ°μλ€μ΄λ©΄ λ κ² κ°μ΅λλ€. | ||
|
||
Staticμ non-static Methodμ μ°¨μ΄λ κ·Έ Methodλ₯Ό νΈμΆν λ, `this` ν€μλκ° νμνλ μλλ μ λλ€. λ§μ½ `this`λ₯Ό ν΅ν΄ ν΄λμ€ μΈμ€ν΄μ€κ° κ°λ κ°μ μ κ·Όν νμκ° μλ€λ©΄, 그건 instance method μ λλ€. λ§μ½ κ·Έλ΄ νμκ° μλ€λ©΄ static methodλ‘ κ΅¬νν΄λ λ©λλ€! | ||
|
||
# CLASSPATH | ||
|
||
`java`μ `javac`μμ μ΄λ€ ν΄λμ€λ₯Ό νΈμΆν κ²μΈμ§ μ§μνλ νκ²½ λ³μ μ λλ€. | ||
|
||
Kafka Connectorλ₯Ό λμΈ λ, μ΄λ€ Connector Pluginμ μ¨μΌ ν μ§λ μ `CLASSPATH` νκ²½ λ³μλ‘ κ²½λ‘λ₯Ό μ λ¬νμμ΅λλ€. [[ref]](/2024/12/17/kafka-connector-standalone-mode/) | ||
|
||
λ§μ½ CLI νκ²½μμ μ¬μ©νλ€λ©΄, | ||
|
||
```bash | ||
$ javac --class-path /path/to/class MyClass.java | ||
$ java --class-path /path/to/class MyClass | ||
``` | ||
|
||
μ κ°μ νμμΌλ‘ μ¬μ©ν©λλ€. | ||
|
||
|
||
# λ°°μ΄ μ μΈ | ||
|
||
```java | ||
ArrayList<Integer> numbers = new ArrayList<>(); | ||
``` | ||
|
||
μ΄λ, `int`λΌλ μ μνμ΄ μλλ°, μ `Integer`λ₯Ό μ¬μ©νλλμ. μ΄μ λ `ArrayList`λ Javaμ Generic ν΄λμ€μ΄κΈ° λλ¬Έμ, κ°μ²΄ νμ λ§ μ§μνλ€κ³ ν¨. κ·Έλμ `int` native νμ μ΄ μλλΌ `Integer`λΌλ κ°μ²΄ νμ μ μ¨μΌ νλ€κ³ ν¨. | ||
|
||
|
||
# `java.lang` ν¨ν€μ§ | ||
|
||
- `System` | ||
- `Integer`, `Double`, `String` | ||
- `Object` | ||
|
||
"ν¨ν€μ§"μ§λ§, λͺ¨λ μλ° μ΄ν리μΌμ΄μ μμ μλμΌλ‘ `import` λ¨. κ·Έλμ `System.out.println()`μ μΈ λ, | ||
|
||
|
||
# Java 11 | ||
|
||
[[10λΆ ν μ½ν‘] νΈνΈμ Java 11](https://youtu.be/LcIyHlE2NlA?si=W9-4PvfezZYmLYZW) | ||
|
||
|
||
|
||
# μ΄λ»κ² 곡λΆνκ³ μλμ§? | ||
|
||
μΈνλ°μμ μ κ°μκ° λ¬΄λ£λ‘ νλ €μκΈΈλ μΌλ¨ μ κ°μλ‘ μμ νμ΅λλ€. | ||
|
||
"[κΉμνμ μλ° μ λ¬Έ - μ½λλ‘ μμνλ μλ° μ²«κ±Έμ](https://www.inflearn.com/course/%EA%B9%80%EC%98%81%ED%95%9C%EC%9D%98-%EC%9E%90%EB%B0%94-%EC%9E%85%EB%AC%B8)" | ||
|
||
무λ£λΌμ λΆλ΄κ° μμ΄ μμν΄λ³Έ κ² κ°κ³ , μ²μμ JavaλΌλ μΈμ΄μ μνκ³λ₯Ό μ€λͺ νλ λΆλΆμ΄ μ°Έ μ’μμ΅λλ€. κ·Έ μΈμ λ·λΆλΆμ κ°λ°μ μμ μ²μ νλ μ¬λ μμ£Όλ‘ λ§μΆ°μ Έ μμ΄μ λΉ λ₯΄κ² λκ²Όμ΅λλ€. μμ κ°μ¬λΆμ΄ μ€λͺ νλ κ²λ€ μ€μλ μ€κΈ ~ κ³ κΈ λΆλΆμ΄ μ κ° λ μ¬λ°κ² κ³΅λΆ ν΄λ³Ό μ μλ μ£Όμ λ€μΈ κ² κ°μ΅λλ€ γ γ | ||
|
||
μ§κΈμ λ°±μ€μμ λ¬Έμ λ₯Ό νλ©΄μ μΈμ΄μ λ§μ λκ»΄λ³΄κ³ μμ΅λλ€ γ γ | ||
|
||
# λ°±μ€μμ Java μ μΆλ ₯ | ||
|
||
λ°±μ€μ ν λλ μ μΆλ ₯μ λ°κΈ° μν΄ κ³ λ €ν΄μΌ ν μ λ€μ΄ νμ μλ€. | ||
|
||
## Scanner | ||
|
||
```java | ||
Scanner sc = new Scanner(System.in) | ||
int a = sc.nextInt(); | ||
int b = sc.nextInt(); | ||
System.out.println(a + b); | ||
sc.close(); | ||
``` | ||
|
||
## BufferedReader, BufferedWriter | ||
|
||
λ°±μ€ λ¬Έμ λ₯Ό νλ€λ³΄λ©΄, λΆλͺ λ‘μ§κ³Ό μκ°λ³΅μ‘λκ° μ΅μ μΈλ°λ "μκ°μ΄κ³Ό"κ° λ¨λ κ²½μ°κ° μλ€. | ||
|
||
μ΄κ²μ `Scanner`μ `System.out.print()`κ° μ μΆλ ₯μ μ²λ¦¬νλ μκ°μ΄ λλ €μ κ·Έλ° κ²μΌλ‘ "λ²νΌλ§" κΈ°μ μ μ°λ `BufferedReader`μ `BufferedWriter`λ₯Ό μ¬μ©νλ©΄ λλ€. μ λ²νΌλ§μ μ΄λ²μ 볡νν΄μ λ€μ μ΄μ체μ (OS) μμ μμ λ°°μ λ λ΄μ©μΈλ°, μ΄λ κ² κΈλ°© λ€μ λ§λλ€λ γ γ λ°κ°λ€. | ||
|
||
```java | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
||
int n = Integer.parseInt(br.readLine()); | ||
|
||
br.close(); | ||
bw.flush(); | ||
bw.close(); | ||
``` | ||
|
||
μ΄λ, μ£Όμν μ μ `bw.write(int n)`μ κ°μ΄ μ μλ₯Ό `bw.write()` ν κ²½μ° μ΄κ±Έ μ«μ Stringμ΄ μλλΌ μμ€ν€μ½λλ‘ ν΄μν΄ μΆλ ₯νλ€. κ·Έλμ μ μ μΆλ ₯ λλ `String.valueOf(int n)`μΌλ‘ StringμΌλ‘ λ³νν νμ μΆλ ₯ ν΄μ€μΌ νλ€. | ||
|
||
<hr/> | ||
|
||
# Spring | ||
|
||
https://start.spring.io/ | ||
|
||
- Springboot? | ||
- λ΄λΆμ tomcat μλ²? | ||
|
||
|
||
## Spring Bootκ° μ§±μ΄λ€ | ||
|
||
κ·Έλ₯ Springμ μ°κ² λλ©΄, λ΄μ₯ μλ²κ° μμ΄μ λ³λμ tomcat μλ²λ₯Ό λμμΌ ν¨. | ||
|
||
λ°λ©΄μ Spring Bootμλ tomcat μλ²κ° λ΄μ₯ λμ΄ μμ(embedded server). κ·Έλμ μλΉ λ μ΄μ΄λ₯Ό λ°λ‘ λνλ‘μ΄ ν νμ μμ. | ||
|
||
## Getter, Setter | ||
|
||
μκ² μλ κ±Έ Java Bin? κ·μ½ μ΄λΌκ³ ν¨. |