MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค JAVA ๊ฐœ๋…์ •๋ฆฌ 9

[JAVA] ์ปดํŒŒ์ผ / ๋Ÿฐํƒ€์ž„ / JVM ๊ตฌ์กฐ

์ปดํŒŒ์ผ (Compile)์†Œ์Šค์ฝ”๋“œ๊ฐ€ ๊ธฐ๊ณ„์–ด๋กœ ๋ณ€ํ™˜๋˜๋Š” ๊ณผ์ • (์ปดํŒŒ์ผ๋Ÿฌ javac๊ฐ€ ์ž๋ฐ” ๋ฐ”์ดํŠธ ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜)`.java` -> `.class`  ๋Ÿฐํƒ€์ž„ (Runtime)ํ”„๋กœ๊ทธ๋žจ์ด ์‹ค์ œ๋กœ ์‹คํ–‰๋˜๋Š” ์‹œ๊ฐ„ ์ปดํŒŒ์ผ๋œ ๋ฐ”์ดํŠธ ์ฝ”๋“œ๊ฐ€ JVM ์— ์˜ํ•ด ์‹คํ–‰๋˜๋Š” ์‹œ์   ์ปดํŒŒ์ผ๊ณผ ๋Ÿฐํƒ€์ž„์˜ ์ฐจ์ด์ ์‹œ์ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์ „์—, ์ฝ”๋“œ ์ž‘์„ฑ ํ›„ ์ปดํŒŒ์ผ ์‹œ์ ์— ๋ฐœ์ƒํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์ค‘์— ๋ฐœ์ƒ๋ชฉ์ ์†Œ์Šค ์ฝ”๋“œ์˜ ์˜ค๋ฅ˜๋ฅผ ๋ฏธ๋ฆฌ ํ™•์ธํ•˜๊ณ , ๋ฐ”์ดํŠธ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜์‹ค์ œ๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•˜๊ณ  ๋™์  ์˜ค๋ฅ˜๋ฅผ ์ฒ˜๋ฆฌ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๋ฌธ๋ฒ• ์˜ค๋ฅ˜, ํƒ€์ž… ์˜ค๋ฅ˜, ์ฒดํฌ ์˜ˆ์™ธ ๋ฏธ์ฒ˜๋ฆฌ ๋“ฑ (์ปดํŒŒ์ผ ์‹œ ๋ฐœ์ƒ)๋Ÿฐํƒ€์ž„ ์˜ˆ์™ธ(๋ฐฐ์—ด ์ธ๋ฑ์Šค ์ดˆ๊ณผ, null ์ฐธ์กฐ ๋“ฑ) (์‹คํ–‰ ์‹œ ๋ฐœ์ƒ)์˜ˆ์‹œ ์˜ค๋ฅ˜๊ตฌ๋ฌธ ์˜ค๋ฅ˜, ํƒ€์ž… ์˜ค๋ฅ˜, ์ฒดํฌ ์˜ˆ์™ธ ๋ฏธ์ฒ˜๋ฆฌNullPointerException, ArrayIndexOutO..

[JAVA] Exception ์˜ˆ์™ธ ์ฒ˜๋ฆฌ

๋ชฉ์ฐจ    ์˜ˆ์™ธ ๋ž€?ํ”„๋กœ๊ทธ๋žจ์˜ ์ •์ƒ์ ์ธ ํ๋ฆ„์„ ๋ฐฉํ•ดํ•˜๋Š” ๋ฌธ์ œ ์ƒํ™ฉ (ํ”„๋กœ๊ทธ๋žจ ์ฝ”๋“œ์—์„œ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ , ๋…ผ๋ฆฌ์  ์˜ค๋ฅ˜) ์—๋Ÿฌ๋Š” ๊ทธ๋ณด๋‹ค ๋” ์‹ฌ๊ฐํ•œ ๋ฌธ์ œ (ํ”„๋กœ๊ทธ๋žจ ์ค‘๋‹จ ๋“ฑ์˜ ์‹ฌ๊ฐํ•œ ๋ฌธ์ œ , JVM / ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ)  ์˜ˆ์™ธ ์ข…๋ฅ˜์ฒดํฌ ์˜ˆ์™ธ : ์ปดํŒŒ์ผ ์‹œ์ ์—์„œ ์˜ˆ์™ธ ๊ฐ•์ œ ์ฒ˜๋ฆฌ์–ธ์ฒดํฌ ์˜ˆ์™ธ : ๋Ÿฐํƒ€์ž„ ์‹œ์ ์—์„œ ๋ฐœ์ƒ (์ปดํŒŒ์ผ ์‹œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๊ฐ•์ œ ๋˜์ง€ ์•Š์Œ)    ์˜ˆ์™ธ ๊ณ„์ธต ๊ตฌ์กฐ  `Throwable` ํด๋ž˜์Šค๋Š” ๋ชจ๋“  ์˜ˆ์™ธ์™€ ์˜ค๋ฅ˜์˜ ๋ถ€๋ชจ ํด๋ž˜์Šค  `getMessage()`: ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.`printStackTrace()`: ์˜ˆ์™ธ ๋ฐœ์ƒ ์‹œ ์Šคํƒ ํŠธ๋ ˆ์ด์Šค๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.`getCause()`: ์˜ˆ์™ธ์˜ ์›์ธ(๋‹ค๋ฅธ ์˜ˆ์™ธ)์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.   ๊ธฐ๋ณธ ์˜ˆ์™ธ์ฒ˜๋ฆฌ  (try-catch) `try`  ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ`cat..

[JAVA 8+] java.time ํŒจํ‚ค์ง€

https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html java.time (Java Platform SE 8 )Class Summary  Class Description Clock A clock providing access to the current instant, date and time using a time-zone. Duration A time-based amount of time, such as '34.5 seconds'. Instant An instantaneous point on the time-line. LocalDate A date withoudocs.oracle.com  java.time ํŒจํ‚ค์ง€ ๊ธฐ์กด `java..

[JAVA 8+] Optional ๊ฐ์ฒด

https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html Optional (Java Platform SE 8 )A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value. Additional methods that depend on the presence or absence of a contained value are provided, such as orEldocs.oracle.com   Optional ๊ฐ์ฒด๋ž€? Java 8 ์—์„œ ๋„์ž…๋œ..

[JAVA 8+] Stream API

๋ชฉ์ฐจ    Stream API ๋ž€ ?Java 8 ์—์„œ ๋„์ž…๋œ ๊ธฐ๋Šฅ์œผ๋กœ, ์ปฌ๋ ‰์…˜ / ๋ฐฐ์—ด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์Šคํƒ€์ผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š”๋‹ค.๋ฐ์ดํ„ฐ ์›๋ณธ์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ , ์›๋ณธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ƒˆ๋กœ์šด ์ŠคํŠธ๋ฆผ์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html w.getColor() == RED) .mapToInt(w -> w.getWeight()) " data-og-host="docs.oracle.com" data-og-source-url="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html" data-og-url="https..

[JAVA 8+] ๋žŒ๋‹ค์‹ ๊ฐœ๋… / ์˜ˆ์ œ

๋žŒ๋‹ค์‹์ต๋ช… ํ•จ์ˆ˜(anonymous function) ํ˜•ํƒœ๋ฅผ ๊ฐ€์ง„ ํ‘œํ˜„์‹  ๋žŒ๋‹ค์‹ ๊ธฐ๋ณธ ๋ฌธ๋ฒ•(๋งค๊ฐœ๋ณ€์ˆ˜) -> { ์‹คํ–‰์ฝ”๋“œ } ๋งค๊ฐœ๋ณ€์ˆ˜ : ๋ฉ”์„œ๋“œ์— ์ „๋‹ฌํ•  ์ž…๋ ฅ๊ฐ’ ์ •์˜(->) : ๋žŒ๋‹ค ์—ฐ์‚ฐ์ž (arrow operator){ ์‹คํ–‰์ฝ”๋“œ } : ๋ฉ”์„œ๋“œ์˜ ์‹คํ–‰ ๋‚ด์šฉ์„ ์ž‘์„ฑ  int add(int x, int y) { return x + y; } // ๋ฉ”์„œ๋“œ ๋ฐ˜ํ™˜ ํƒ€์ž… , ๋ฉ”์„œ๋“œ๋ช… ์ƒ๋žต (int x , int y ) -> { return x + y; } // ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž… ์ƒ๋žต (x,y) -> { return x + y ; } // ๋ฆฌํ„ด๋ฌธ๋งŒ ์žˆ๋Š”..

๋ฌธ์ž ๋ฐฐ์—ด <-> ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

String ์ƒ์„ฑ์ž ์‚ฌ์šฉ: ์ž๋ฐ”์˜ String ํด๋ž˜์Šค๋Š” ๋ฌธ์ž ๋ฐฐ์—ด์„ ์ธ์ž๋กœ ๋ฐ›์•„ ๋ฌธ์ž์—ด์„ ์ƒ์„ฑํ•˜๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.String.valueOf() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ: String ํด๋ž˜์Šค์˜ valueOf ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.StringBuilder ์‚ฌ์šฉ: StringBuilder๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.Arrays.toString() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ: ์ด ๋ฐฉ๋ฒ•์€ ๋ฌธ์ž ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ ๋งŽ์ด ์‚ฌ์šฉ๋˜์ง€ ์•Š์ง€๋งŒ, ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ํ‘œํ˜„ํ•  ๋•Œ ์œ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ๋ฐฐ์—ด ์š”์†Œ๋“ค์ด ์‰ผํ‘œ์™€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋œ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค. String.toCharArray() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ:charAt() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜๋™์œผ๋กœ ๋ณ€ํ™˜:

์„œ๋ฒ„-ํด๋ผ์ด์–ธํŠธ ์ฑ„ํŒ… ํ”„๋กœ๊ทธ๋žจ

์„œ๋ฒ„ - ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฒˆ๊ฐˆ์•„์„œ ์ฑ„ํŒ…ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค.  ํด๋ผ์ด์–ธํŠธpackage chat;import java.io.*;import java.net.*;import java.util.*;public class ClientEx { public static void main(String[] args){ BufferedReader in =null; BufferedWriter out =null; Socket socket = null; Scanner sc = new Scanner(System.in); try { socket = new Socket("localhost",9999); // ํด๋ผ์ด์–ธํŠธ ์†Œ์ผ“ ์ƒ..

์ž๋ฐ” ์ถœ๋ ฅ๋ฌธ ์ •๋ฆฌ (println,print, printf)

System.out.println(): System.out.println()์€ ์ž๋ฐ”์—์„œ ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์ถœ๋ ฅ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. println()์€ ๊ด„ํ˜ธ ์•ˆ์— ์ „๋‹ฌ๋œ ์ธ์ž๋ฅผ ์ถœ๋ ฅํ•œ ํ›„ ์ž๋™์œผ๋กœ ์ค„์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด: javaCopy code System.out.println("Hello, world!"); System.out.print(): System.out.print()๋„ println()๊ณผ ์œ ์‚ฌํ•˜์ง€๋งŒ ์ค„ ๋ฐ”๊ฟˆ์„ ํ•˜์ง€ ์•Š๊ณ  ์ถœ๋ ฅ๋งŒ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด: javaCopy code System.out.print("Hello, "); System.out.print("world!"); System.out.printf(): System.out.printf()๋Š” C ์–ธ์–ด์˜ printf()์™€ ์œ ์‚ฌํ•œ ํฌ๋งท์„ ..