java oop : 여러 API 사용
This commit is contained in:
BIN
JavaOOP/lib/gson-2.8.6.jar
Normal file
BIN
JavaOOP/lib/gson-2.8.6.jar
Normal file
Binary file not shown.
@@ -1,2 +1,12 @@
|
||||
import object.OverLoad;
|
||||
|
||||
public class Java16 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
OverLoad ov = new OverLoad();
|
||||
|
||||
ov.hap(20, 50); // hap_int_int(20, 50)
|
||||
ov.hap(23.4f, 56); // hap_float_int(23.4f, 56)
|
||||
ov.hap(56.7f, 78.9f); // hap_float_float(56.7f, 78.9f)
|
||||
}
|
||||
}
|
||||
|
||||
28
JavaOOP/src/Java17.java
Normal file
28
JavaOOP/src/Java17.java
Normal file
@@ -0,0 +1,28 @@
|
||||
import com.google.gson.Gson;
|
||||
import object.BookVO;
|
||||
import object.MyUtil;
|
||||
|
||||
public class Java17 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 1. Java 에서 제공해주는 class 들 -> API
|
||||
String str = new String("apple");
|
||||
// new String 생략 가능
|
||||
String str1 = "apple";
|
||||
System.out.println(str1.toUpperCase()); // 소문자 -> 대문자 변환 메소드
|
||||
|
||||
// 2. 직접 만들어서 사용하는 class 들 -> DTO/VO, DAO, Utility ... API
|
||||
MyUtil my = new MyUtil();
|
||||
int sum1to10 = my.hap();
|
||||
System.out.println(sum1to10);
|
||||
|
||||
// 3. 다른 회사(사람) 에서 만들어 놓은 class
|
||||
// Gson 사용해보기 : object -> json 형태로 바꿔주는 API
|
||||
Gson g = new Gson();
|
||||
BookVO vo = new BookVO("자바", 13000, "출판사", 800);
|
||||
String json = g.toJson(vo);
|
||||
|
||||
System.out.println(json);
|
||||
}
|
||||
}
|
||||
|
||||
11
JavaOOP/src/object/MyUtil.java
Normal file
11
JavaOOP/src/object/MyUtil.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package object;
|
||||
|
||||
public class MyUtil {
|
||||
public int hap() {
|
||||
int sum = 0;
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
14
JavaOOP/src/object/OverLoad.java
Normal file
14
JavaOOP/src/object/OverLoad.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package object;
|
||||
|
||||
public class OverLoad {
|
||||
// 동작(method)으로만 이루어진 객체
|
||||
public void hap(int a, int b){
|
||||
System.out.println(a+b);
|
||||
}
|
||||
public void hap(float a, int b){
|
||||
System.out.println(a+b);
|
||||
}
|
||||
public void hap(float a, float b){
|
||||
System.out.println(a+b);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user