user-img
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java 26
thumbnail
[JAVA] Object ํด๋ž˜์Šค ๊ธฐ๋ณธ ์‚ฌ์šฉ
class Point{ int x, y; Point(int x, int y){ this.x = x; this.y = y; } } public class ObjectEx { static void print(Object obj) { System.out.println(obj.getClass()); System.out.println(obj.hashCode()); System.out.println(obj.toString()); System.out.println(obj); } public static void main(String[] args) { Point p = new Point(2, 3); print(p); } } ๊ฒฐ๊ณผ
2023.12.21
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ์ƒ์„ฑ์ž ๋งŒ๋“ค๊ธฐ ์˜ˆ์ œ
ํ•™์ƒ ์ •๋ณด ํด๋ž˜์Šค ๊ตฌํ˜„ํ•˜๊ณ , 2๊ฐœ์˜ ๊ฐ์ฒด ์ƒ์„ฑํ•˜๊ธฐ ํด๋ž˜์Šค ์ƒ์„ฑ ํด๋ž˜์Šค ์ด๋ฆ„: Student ๋ฉค๋ฒ„๋ณ€์ˆ˜: num, name, c, java, net(์ ์ˆ˜) ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ์ž(num, name, c, java, net ์ดˆ๊ธฐํ™”) ์ด์ ๊ณ„์‚ฐ(getTot()) ์ถœ๋ ฅ(printinfo()) class Student{ int num, c, java, net, tot; String name; Student(){//์ƒ์„ฑ์ž๋กœ ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™” num = 0; name = ""; c = 0; java = 0; net = 0; } Student(int num, String name, int c, int java, int net){ this.num = num; this.name = name; this.c = c; this.java ..
2023.12.21
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ๋ฐฐ์—ด์˜ ์„ ์–ธ๊ณผ ์‚ฌ์šฉ
public class ExampleEx { public static void main(String[] args) { int[] arr = new int[5]; String[] s = new String[5]; float[] f = new float[5]; for(int i=0; i
2023.12.21
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
thumbnail
[JAVA] ์ธํ„ฐํŽ˜์ด์Šค ์˜ˆ์ œ
* ๋‹ค์Œ์˜ ์ƒ์† ๊ด€๊ณ„๋ฅผ ๊ฐ–๋Š” ์ธํ„ฐํŽ˜์ด์Šค์™€ ํด๋ž˜์Šค๋“ค์„ ์ž‘์„ฑํ•˜์„ธ์š”. Student
2023.12.21
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ์ธํ„ฐํŽ˜์ด์Šค
์ถ”์ƒ ๋ฉ”์†Œ๋“œ์™€ ์ƒ์ˆ˜๋งŒ์œผ๋กœ ๊ตฌ์„ฑ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ๋Š” abstract public์ด๋ฉฐ ์ƒ๋žต ๊ฐ€๋Šฅ ์ƒ์ˆ˜๋Š” public static final ํƒ€์ž…์ด๋ฉฐ ์ƒ๋žต ๊ฐ€๋Šฅ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ฐ์ฒด ์ƒ์„ฑ ๋ถˆ๊ฐ€ ๋‹ค๋ฅธ ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์† ๊ฐ€๋Šฅ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๋‹ค์ค‘ ์ƒ์† ๊ฐ€๋Šฅ ์ธํ„ฐํŽ˜์ด์Šค ํƒ€์ž…์˜ ๋ ˆํผ๋Ÿฐ์Šค ๋ณ€์ˆ˜ ์„ ์–ธ ๊ฐ€๋Šฅ implements public interface Phone {//interface๋กœ ์ƒ์„ฑ void sendCall(); void receiveCall(); } interface MobilePhone extends Phone{ void sendSMS(); void receiveSMS(); } interface MP3{ void play(); void stop(); } class PDA{ int calc(int a, int b) { ..
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ์˜ค๋ฒ„๋ผ์ด๋”ฉ ์˜ˆ์ œ
๋‹ค์Œ์˜ ์ƒ์† ๊ด€๊ณ„๋ฅผ ๊ฐ–๋Š” ํด๋ž˜์Šค๋“ค์„ ์ž‘์„ฑํ•˜์„ธ์š”. ํŠนํžˆ ๋ฉ”์†Œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ๊ทœ์น™๊ณผ, super() ๋ฐ super๋ฅผ ์ ์šฉํ•ด์„œ ์ค‘๋ณต์ด ์ตœ์†Œํ™”๋˜๋„๋ก ์ž‘์„ฑํ•˜์„ธ์š”. Shape – Line - Square – Rect – Circle 1) Shape - ๋ฉค๋ฒ„๋ณ€์ˆ˜: String name - ์ƒ์„ฑ์ž: name์„ ์ดˆ๊ธฐํ™” - ๋ฉ”์†Œ๋“œ: void printInfo() //name์„ ์ถœ๋ ฅ 2) Line - ๋ฉค๋ฒ„๋ณ€์ˆ˜: int length - ์ƒ์„ฑ์ž: name๊ณผ length๋ฅผ ์ดˆ๊ธฐํ™” - ๋ฉ”์†Œ๋“œ: void printInfo() //name๊ณผ length๋ฅผ ์ถœ๋ ฅ 3) Square - ๋ฉค๋ฒ„๋ณ€์ˆ˜: int area; - ์ƒ์„ฑ์ž: name๊ณผ length๋ฅผ ์ดˆ๊ธฐํ™” - ๋ฉ”์†Œ๋“œ: void getArea(int, int) //์‚ฌ๊ฐํ˜•์˜ ๋„“์ด๋ฅผ ๊ตฌํ•จ=> ..
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ๊ธฐ๋ณธ ๊ตฌ์กฐ, C์™€ ๋‹ค๋ฅธ ์ 
๊ธฐ๋ณธ ๊ตฌ์กฐ public class ์ด๋ฆ„ {//ํด๋ž˜์Šค public static int ์ด๋ฆ„(๋ฐ›๋Š” ๊ฑฐ){//๋ฉ”์†Œ๋“œ ์‹คํ–‰ํ•˜๋Š” ๊ฑฐ } } ctrl+shift+o ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค ์ž„ํฌํŠธ ์ž๋™ ๋„ฃ๊ธฐ Scanner ํด๋ž˜์Šค scanf ๊ฐ™์€ ๊ฑฐ ๋Œ€์‹  Scanner๋ฅผ ๋“ฑ๋กํ•ด์ค˜์„œ ๊ฑฐ๊ธฐ ์žˆ๋Š” ๊ฑฐ ์‚ฌ์šฉํ•ด์•ผ ํ•จ. //์ด ์˜ˆ์‹œ๋Š” ๋ฉ”์ธ ๋ฉ”์†Œ๋“œ์—์„œ ํ•จ Scanner sc = new Scanner(System.in); int num; num = sc.nextInt(); //String(C์—์„  char) ๊ฐ™์€ ๊ฒฝ์šฐ sc.next()๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  //floot, boolean ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์—ญ์‹œ sc.nextFloot(), sc.nextBoolean() for-each for(int i=0; i
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ์ถ”์ƒ ๋ฉ”์†Œ๋“œ, ํด๋ž˜์Šค
์ƒ˜ํ”Œ์„ ๋งŒ๋“ค์–ด๋†“๊ณ  ๋‚˜์ค‘์— ๊ฐ€์ ธ๋‹ค๊ฐ€ ์“ฐ๊ธฐ ์œ„ํ•œ ์šฉ๋„. ์ถ”์ƒ ๋ฉ”์†Œ๋“œ๋ฅผ ๋ฐ›์•„ ๊ตฌํ˜„ํ•˜๋ ค๋Š” ์„œ๋ธŒ ํด๋ž˜์Šค์—์„œ๋Š” ๋ฌด์กฐ๊ฑด ์˜ค๋ฒ„๋ผ์ด๋”ฉ์„ ํ•ด์•ผ ํ•œ๋‹ค.(๊ตฌํ˜„ ์•ˆ ํ•  ๊ฒฝ์šฐ ๊ทธ ํด๋ž˜์Šค๋„ abstract๋ฅผ ๋ถ™์—ฌ์›Œ์„œ ์ถ”์ƒ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด์ค˜์•ผ ํ•œ๋‹ค.) abstract class Shape{ abstract void draw(); } class Line extends Shape{ @Override void draw() { System.out.println("Line"); } } class Circle extends Shape{ @Override void draw() { System.out.println("Circle"); } } class Rect extends Shape{ @Override void draw() { System.ou..
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ์˜ค๋ฒ„๋กœ๋”ฉ vs ์˜ค๋ฒ„๋ผ์ด๋”ฉ ์ฐจ์ด
์˜ค๋ฒ„๋กœ๋”ฉ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ๊ฐ™์€ ํด๋ž˜์Šค๋‚˜ ์ƒ์† ๊ด€๊ณ„์—์„œ ๋™์ผ ์ด๋ฆ„ ๋ฉ”์†Œ๋“œ ์ค‘๋ณต ์‚ฌ์šฉ ๊ฐ€๋Šฅ ์„œ๋ธŒ ํด๋ž˜์Šค์—์„œ ์Šˆํผ ํด๋ž˜์Šค์— ์žˆ๋Š” ๋ฉ”์†Œ๋“œ์™€ ๋™์ผํ•œ ์ด๋ฆ„์˜ ๋ฉ”์†Œ๋“œ ์žฌ์ž‘์„ฑ ๋™์ผ ํด๋ž˜์Šค or ์ƒ์† ๊ด€๊ณ„ ์ƒ์† ๊ด€๊ณ„ ์ค‘๋ณต ์ž‘์„ฑํ•ด ํŽธ๋ฆฌํ•˜๊ณ , ๋‹ค์–‘ํ•˜๊ฒŒ ์‚ฌ์šฉ ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์€ ๋ฐ˜๋“œ์‹œ ๋™์ผ, ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž…์ด๋‚˜ ๊ฐœ์ˆ˜ ๋‹ฌ๋ผ์•ผ ํ•จ ์ด๋ฆ„, ํƒ€์ž…๊ณผ ๊ฐœ์ˆ˜, ๋ฆฌํ„ด ํƒ€์ž…์ด ๋ชจ๋‘ ๋™์ผํ•ด์•ผ ํ•จ ์ปดํŒŒ์ผ ์‹œ ๊ฒฐ์ • ์‹คํ–‰ ์‹œ์ ์— ๊ฒฐ์ •
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] ๋ฉ”์†Œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ
์ดํด๋ฆฝ์Šค ์•ŒํŠธ ์‰ฌํ”„ํŠธ ์—์Šค override/implement methods class Shape{ void draw() { System.out.println("Shape"); } } class Line extends Shape{ @Override void draw() { System.out.println("Line"); } } class Rect extends Shape{ @Override void draw() { System.out.println("Rect"); } } class Circle extends Shape{ @Override void draw() { System.out.println("Circle"); } } public class MethodOverEx { static void paint(..
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] instanceof
instanceof ์–ด๋–ค ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์•˜๋Š”์ง€ ํ™•์ธ class Person{ String name; Person(String name){ this.name = name; } void printInfo() { System.out.println(name); } } class Student extends Person{ int snum; Student(String name, int snum){ super(name); this.snum = snum; } void printStudent() { System.out.println("snum: "+snum); } } class Researcher extends Person{ int rnum; Researcher(String name, int rnum){ super(na..
2023.12.20
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java
[JAVA] HashMap ์‚ฌ์šฉ๋ฒ•
import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; import java.util.Set; public class HashMapEx { public static void main(String[] args) { HashMap h = new HashMap(); //ํ•œ ์Œ์„ ๋ฐ›์Œ Scanner sc = new Scanner(System.in); h.put("Python","ํŒŒ์ด์ฌ"); h.put("Java", "์ž๋ฐ”"); h.put("Database", "๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค"); Set keys = h.keySet();//์•ž์— ์žˆ๋Š” String์œผ๋กœ ํ‚ค๋ฅผ ์ง€์ • Iterator it = keys.iterator(); while(it..
2023.12.14
๐Ÿ‘ฉ‍๐Ÿ’ปํ”„๋กœ๊ทธ๋ž˜๋ฐ&DB/Java