Banner

My Tech Blog (Coding/Java)

package ex01์›”๊ธ‰๊ณ„์‚ฐํ”„๋กœ๊ทธ๋žจ; public abstract class Employee { // ์ ‘๊ทผ์ œํ•œ์ž์˜ ์ข…๋ฅ˜ // public = ์–ด๋””์„œ๋“  ๋ˆ„๊ตฌ๋‚˜ ๋‹ค ์ ‘๊ทผ ๊ฐ€๋Šฅ // default = ๋™์ผํ•œ ํŒจํ‚ค์ง€๋งŒ(์•„๋ฌด๊ฒƒ๋„ ์•ˆ ์ ๋Š” ๊ฒƒ) // private = ํ˜„์žฌ ํด๋ž˜์Šค์—์„œ๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ // protected = ๋™์ผํ•œ ํŒจํ‚ค์ง€๊ฑฐ๋‚˜ ์ƒ์†๊ด€๊ณ„๊นŒ์ง€ ์ ‘๊ทผ ๊ฐ€๋Šฅ // 1. ํ•„๋“œ // private -> public -> protected // ์‚ฌ๋ฒˆ protected String empno; //์ด๋ฆ„ protected String name; //์—ฐ๋ด‰ protected int pay; // default = ๋™์ผํ•œ ํŒจํ‚ค์ง€๋งŒ // protected = ์ƒ์†๊ด€๊ณ„๊นŒ์ง€ ์ ‘๊ทผ ๊ฐ€๋Šฅ // ์ž๋ฐ” ์ €์žฅ๊ณต๊ฐ„ // heap : ์ปค๋‹ค๋ž€..
package ex02๋‹Œํ…๋„๊ฒŒ์ž„๊ธฐ; public class Dongmul extends GameChip { @Override public void start() { System.out.println("๋™๋ฌผ์˜์ˆฒ ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."); } } package ex02๋‹Œํ…๋„๊ฒŒ์ž„๊ธฐ; public class Mario extends GameChip { @Override public void start() { System.out.println("๋งˆ๋ฆฌ์˜ค์นดํŠธ ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."); } } package ex02๋‹Œํ…๋„๊ฒŒ์ž„๊ธฐ; public class Zelda extends GameChip { @Override public void start() { System.out.println("์ ค๋‹ค์˜ ์ „์„ค์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."); }..
package ex01์ƒ์†๊ธฐ์ดˆ; public class Child extends Parent { // ์ž์‹ํด๋ž˜์Šค, ์„œ๋ธŒํด๋ž˜์Šค(์ƒˆ๋กœ์šด ํด๋ž˜์Šค) // extends : ์ƒ์†์„ ๋ฐ›์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํ‚ค์›Œ๋“œ // --> ์—ฐ์žฅํ•˜๋‹ค, ํ™•์žฅํ•˜๋‹ค์˜ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ // class ์„œ๋ธŒํด๋ž˜์Šค extends ์Šˆํผํด๋ž˜์Šค public void makeBong() { System.out.println("๋ง›์žˆ๋Š” ๋ด‰๊ณจ๋ ˆ ํŒŒ์Šคํƒ€๋ฅผ ๋งŒ๋“ ๋‹ค~ ์–!"); } public void makeSteak() { System.out.println("๋ฒ„ํ„ฐ์— ์•„์ŠคํŒŒ๋ผ๊ฑฐ์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ์Šคํ…Œ์ดํฌ๋ฅผ ๊ตฝ๋Š”๋‹ค"); } /* * @author SMHRD(๋งŒ๋“ ์‚ฌ๋žŒ ์ด๋ฆ„) * @since 23.07.12 * @param ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ค๋ช… ๋‹ฌ์•„์ฃผ๋Š” ๊ณณ * @ret..
package ex02_ArrayList; import java.util.ArrayList; public class ArraylistMain { public static void main(String[] args) { // Collection // ์š”์†Œ(Element)๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๊ฐ€๋ณ€ ๊ฐœ์ˆ˜์˜ ๊ฐ์ฒด๋“ค์˜ ์žกํ•ฉ // (๊ธฐ๋ณธ ์ž๋ฃŒํ˜•์„ ์ €์žฅํ•˜๋Š” ๊ฒƒ์€ ๋ถˆ๊ฐ€๋Šฅ int, double, float์•ˆ๋จ) ๊ฐ์ฒด๋งŒ์„ ์ €์žฅ // ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ์ฒด ๋ณด๊ด€ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด์ง„ ํด๋ž˜์Šค๋“ค์˜ ์žกํ•ฉ // ๊ณ ์ • ํฌ๊ธฐ์˜ ๋ฐฐ์—ด์„ ๋‹ค๋ฃจ๋Š” ๋ถˆํŽธํ•จ ํ•ด์†Œ // ์š”์†Œ์˜ ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ์ž๋™ ํฌ๊ธฐ ์กฐ์ ˆ // ์š”์†Œ์˜ ์ถ”๊ฐ€, ์‚ญ์ œ์— ๋”ฐ๋ฅธ ์š”์†Œ์˜ ์ด๋™์ž๋™๊ด€ // ์ œ๋„ค๋ฆญ(generic) ๊ธฐ๋ฒ•์œผ๋กœ ๊ตฌํ˜„ // Collection์˜ ํ•œ ์ข…๋ฅ˜์ธ ArrayList // - ๊ฐ€..
package ex01_๊ฐ์ฒด๋ฐฐ์—ด; public class Pokemon { // ํฌ์ผ“๋ชฌ ์ž๋ฃŒํ˜• // 1. ํ•„๋“œ public static final Pokemon pikachu = null; // ์ด๋ฆ„ private String name; // ํƒ€์ž… private String type; // ๊ณต๊ฒฉ๋ ฅ private int atk; // ์ฒด๋ ฅ private int hp; // ์Šคํ‚ฌ private String skill; // 2. ๋ฉ”์„œ๋“œ // ๋ชจ๋“  ํ•„๋“œ๋ฅผ ์ดˆ๊ธฐํ™”์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์ƒ์„ฑ์ž public Pokemon(String name, String type, int atk, int hp, String skill) { this.name = name; this.type = type; this.atk = atk; thi..
package ex01_๊ฐ์ฒด๋ฐฐ์—ด; import java.util.Arrays; public class Main { public static void main(String[] args) { // 1. ๊ฐ์ฒด ๋ฐฐ์—ด // ๋ฐฐ์—ด์ด๋ž€? // --> ๋™์ผํ•œ ์ž๋ฃŒํ˜•์„ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ // ๋ฐฐ์—ด ์„ ์–ธ ๋ฐฉ๋ฒ• // ์ž๋ฃŒํ˜•[] ๋ณ€์ˆ˜๋ช… = new ์ž๋ฃŒํ˜•[ํฌ๊ธฐ]; // ๋‚˜๋งŒ์˜ ์ž๋ฃŒํ˜• // ํฌ์ผ“๋ชฌ ๋ฐ์ดํ„ฐ๋ฅผ 3๊ฐœ ์ €์žฅ ํ•  ์ˆ˜ ์žˆ๋Š” bag ๋ฐฐ์—ด ์ƒ์„ฑ Pokemon[] bag = new Pokemon[3]; // ํฌ์ผ“๋ชฌ์€ ๋ž˜ํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜ํƒ€์ž… - null(๊ธฐ๋ณธ๊ฐ’) // new๋Š” ๋ž˜ํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜ ์ƒ์„ฑํ•˜๋Š” ํ‚ค์›Œ๋“œ // bag 0๋ฒˆ ๋ฐฉ์— ํ”ผ์นด์ธ„ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ // ํ”ผ์นด์ธ„, ์ „๊ธฐ, 5000, 500, ๋ฐฑ๋งŒ๋ณผํŠธ Pokemon pik..
1. Model (๋ชจ๋ธ) package ex03_๋ฎค์งํ”Œ๋ ˆ์ด์–ด; public class Music { // Model : ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฐ์ฒด private String title; // ๋…ธ๋ž˜์ œ๋ชฉ private String singer; // ๊ฐ€์ˆ˜ private String path; // ๋…ธ๋ž˜ ์ €์žฅ ๊ฒฝ๋กœ public Music(String title, String singer, String path) { this.title = title; this.singer = singer; this.path = path; } // (2) getter ๋ฉ”์†Œ๋“œ public String getTitle() { return title; } public String getSinger() { return singer; }..
์ค€๋น„๋ฌผ : jarํŒŒ์ผ Musicํด๋ž˜์Šค (ํ•„๋“œ๊ฐ’, ๋ฉ”์„œ๋“œ) package ex03๋ฎค์งํ”Œ๋ ˆ์ด์–ด; public class Music { // ์ž๋ฃŒํ˜• // 1. ํ•„๋“œ(์†์„ฑ, ๋ฐ์ดํ„ฐ) private String title; // ๋…ธ๋ž˜์ œ๋ชฉ private String singer; // ๊ฐ€์ˆ˜ private String path; // ๋…ธ๋ž˜์ €์žฅ๊ฒฝ๋กœ // 2. ๋ฉ”์„œ๋“œ(๋กœ์ง, ํ–‰์œ„) //์ƒ์„ฑ์ž public Music(String title, String singer, String path) { this.title = title; this.singer = singer; this.path = path; } //getter์ƒ์„ฑ public String getTitle() { return title; } public String..
์ธ์ ˆ๋ฏธ์˜€๋˜๊ฒƒ
'Coding/Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (3 Page)
์ƒ๋‹จ์œผ๋กœ