change directory

This commit is contained in:
haerong22
2022-08-27 01:42:54 +09:00
parent 79efea26d1
commit 676e539c28
60 changed files with 0 additions and 1081 deletions

Binary file not shown.

View File

@@ -1,6 +0,0 @@
public class Java01 {
public static void main(String[] args) {
System.out.println("hello world");
}
}

View File

@@ -1,21 +0,0 @@
import myObject.Book;
public class Java02 {
public static void main(String[] args) {
// 프로그래밍 3대 요소 - 변수, 자료형, 할당
// {자료형} {변수} = {할당}
int a = 1, b = 1, c = a + b;
System.out.println(c);
float f = 34.5f;
System.out.println(f);
char d = 'A';
System.out.println(d);
boolean g = true;
System.out.println(g);
Book book;
}
}

View File

@@ -1,35 +0,0 @@
import myObject.Book;
import myObject.Person;
public class Java03 {
public static void main(String[] args) {
// 관계를 이해하라. PDT vs UDDT
// 정수 1개를 저장하기 위한 변수를 선언하시오.
int a = 10;
// 책 1권을 저장하기 위한 선언하시오.
Book b = new Book();
b.title = "자바";
b.price = 15000;
b.company = "한빛미디어";
b.page = 700;
System.out.println(b.title);
System.out.println(b.price);
System.out.println(b.company);
System.out.println(b.page);
Person p = new Person();
p.name = "홍길동";
p.age = 20;
p.weight = 78.9f;
p.height = 184.8f;
System.out.println(p.name);
System.out.println(p.age);
System.out.println(p.weight);
System.out.println(p.height);
}
}

View File

@@ -1,32 +0,0 @@
public class Java04 {
public static void main(String[] args) {
// 변수 VS 배열
int a = 10, b = 20, c = 30;
// a + b + c = ? 메소드 처리 -> hap()
hap(a, b, c);
int[] arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
hap(arr);
}
// 하나의 값마다 파라미터로 받아야함 -> 데이터 이동이 불편
public static void hap(int a, int b, int c) {
int sum = a + b + c;
System.out.println(sum);
}
// 여러 값을 배열로 한번에 이동
public static void hap(int[] arr) {
int sum = 0;
for (int i : arr) {
sum += i;
}
System.out.println(sum);
}
}

View File

@@ -1,40 +0,0 @@
public class Java05 {
public static void main(String[] args) {
// 2차원 배열
int[][] a = new int[3][3];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 1;
a[1][1] = 2;
a[1][2] = 3;
a[2][0] = 1;
a[2][1] = 2;
a[2][2] = 3;
for (int i = 0; i < a.length ; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
// 가변길이 배열
int[][] star = new int[5][];
star[0] = new int[1];
star[1] = new int[2];
star[2] = new int[3];
star[3] = new int[4];
star[4] = new int[5];
for (int i = 0; i <star.length ; i++) {
for (int j = 0; j < star[i].length ; j++) {
star[i][j] = '*';
System.out.print((char) star[i][j]);
}
System.out.println();
}
}
}

View File

@@ -1,33 +0,0 @@
public class Java06 {
public static void main(String[] args) {
// 메소드 -> 동작(method), 기능(function)
int a = 67;
int b = 98;
int result = sum(a, b);
System.out.println(result);
int[] arr = makeArr();
int hap = 0;
for (int i = 0; i < arr.length; i++) {
hap += arr[i];
}
System.out.println(hap);
}
// 정수 2개를 매개변수로 받아서 합을 리턴하는 메소드를 정의하시오.
// static 메소드에서는 static 메소드만 호출 가능
public static int sum(int a, int b) {
return a + b;
}
// 값은 하나만 리턴이 가능하다.
// 여러 값을 리턴 받고 싶다면? -> 배열
public static int[] makeArr() {
int[] arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
return arr;
}
}

View File

@@ -1,29 +0,0 @@
public class Java07 {
public static void main(String[] args) {
int a = 20;
float b = 56.7f;
// call by value
float v = sum(a, b);
System.out.println(v);
int[] arr = {1, 2, 3, 4, 5};
// call by reference
int vv = arrSum(arr);
System.out.println(vv);
}
public static float sum(int a, float b) {
return a + b;
}
public static int arrSum(int[] arr) {
int sum = 0;
for (int i : arr) {
sum += i;
}
return sum;
}
}

View File

@@ -1,13 +0,0 @@
public class Java08 {
public static void main(String[] args) {
int a = 30;
int b = 50;
int v = add(a, b); // static method call
System.out.println(v);
}
public static int add(int a, int b) {
int sum = a + b;
return sum;
}
}

View File

@@ -1,15 +0,0 @@
public class Java09 {
public static void main(String[] args) {
int a = 56;
int b = 40;
Java09 java09 = new Java09(); // heap area 에 객체 생성
int v = java09.add(a, b);
System.out.println(v);
}
public int add(int a, int b) {
int sum = a + b;
return sum;
}
}

View File

@@ -1,23 +0,0 @@
import myObject.BookVO;
public class Java10 {
public static void main(String[] args) {
/**
* 책 (BookVO) 이라는 자료형 만들기 -> class 를 통해 만든다.
* class 를 만들면 디폴트 생성자가 자동 생성된다. (생략)
* 생성자는 객체를 생성하는 작업을 한다. (기계어코드)
* 객체를 생성하면 이 객체를 가리키는 this 객체도 자동 생성된다.
*/
BookVO b = new BookVO(); // 객체 생성
b.title = "자바";
b.price = 20000;
b.company = "출판사";
b.page = 670;
System.out.println(b.title);
System.out.println(b.price);
System.out.println(b.company);
System.out.println(b.page);
}
}

View File

@@ -1,14 +0,0 @@
import myObject.BookVO;
public class Java11 {
public static void main(String[] args) {
// 생성자 -> 생성 + 초기화 -> 중복정의
BookVO b = new BookVO("자바",20000,"길벗",790);
System.out.println(b.title);
System.out.println(b.price);
System.out.println(b.company);
System.out.println(b.page);
}
}

View File

@@ -1,16 +0,0 @@
import myObject.PrivateConstructor;
public class Java12 {
public static void main(String[] args) {
// // 생성자가 private 이므로 객체 생성 불가
// PrivateConstructor pc = new PrivateConstructor();
//
// // non-static-method 사용 불가
// PrivateConstructor.nonStaticMethod();
// static-method 만 사용가능
PrivateConstructor.staticMethod();
}
}

View File

@@ -1,25 +0,0 @@
import myObject.BookDTO;
public class Java13 {
public static void main(String[] args) {
// 책 -> class(BookDTO) -> 객체 -> 인스턴스
String title = "자바";
int price = 25000;
String company = "출판사";
int page = 890;
// 데이터 이동을 쉽게 하기 위한 DTO
BookDTO dto; // dto (Object : 객체)
dto = new BookDTO(title, price, company, page); // dto (Instance : 인스턴스)
// 데이터 이동
bookPrint(dto);
}
public static void bookPrint(BookDTO dto) {
System.out.println(dto.title);
System.out.println(dto.price);
System.out.println(dto.company);
System.out.println(dto.page);
}
}

View File

@@ -1,19 +0,0 @@
import myObject.MemberVO;
public class Java14 {
public static void main(String[] args) {
MemberVO m = new MemberVO();
m.setName("홍길동");
m.setAge(20);
m.setTel("010-1234-1234");
m.setAddr("서울");
System.out.println(m.getName());
System.out.println(m.getAge());
System.out.println(m.getTel());
System.out.println(m.getAddr());
}
}

View File

@@ -1,11 +0,0 @@
import myObject.MemberVO;
public class Java15 {
public static void main(String[] args) {
MemberVO m = new MemberVO("홍길동", 20, "010-1123-1123", "서울");
System.out.println(m.toString());
System.out.println(m); // toString 생략 가능
}
}

View File

@@ -1,12 +0,0 @@
import myObject.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)
}
}

View File

@@ -1,28 +0,0 @@
import com.google.gson.Gson;
import myObject.BookVO;
import myObject.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);
}
}

View File

@@ -1,17 +0,0 @@
import myObject.Animal;
import myObject.Cat;
import myObject.Dog;
public class Java18 {
public static void main(String[] args) {
// Dog dog = new Dog();
// Cat cat = new Cat();
Animal dog = new Dog();
Animal cat = new Cat();
dog.eat();
cat.eat();
}
}

View File

@@ -1,13 +0,0 @@
import myObject.Animal;
import myObject.Cat;
import myObject.Dog;
public class Java19 {
public static void main(String[] args) {
Animal dog = new Dog(); // 상속 관계 : 자동 형변환 -> Object casting 부모 클래스 = 자식클래스 (Up casting)
Animal cat = new Cat();
dog.eat();
cat.eat();
}
}

View File

@@ -1,23 +0,0 @@
import myObject.Animal;
import myObject.Cat;
import myObject.Dog;
public class Java20 {
public static void main(String[] args) {
// upcasting
Animal cat = new Cat();
Animal dog = new Dog();
// 오버라이딩 한 메소드 사용
// cat 에만 있는 메소드는 사용 하지못함 -> cat.say() X
cat.eat(); // 컴파일 시점 -> Animal 의 eat(), 실행 시점 -> Cat 의 eat()
dog.eat(); // 컴파일 시점 -> Animal 의 eat(), 실행 시점 -> Dog 의 eat()
// downcasting
// Cat c = (Cat) ani;
// c.night();
((Cat) cat).say(); // . 연산자가 casting 연산자 보다 우선순위가 높다.
}
}

View File

@@ -1,22 +0,0 @@
import myObject.Animal;
import myObject.Cat;
import myObject.Dog;
public class Java21 {
public static void main(String[] args) {
// 1. 다형성 인수
Dog dog = new Dog();
Cat cat = new Cat();
display(dog);
display(cat);
}
public static void display(Animal animal) { // 다형성 인수 upcasting
animal.eat();
// Cat 타입 인지 확인 instanceof -> Cat 타입 일때만 실행
if (animal instanceof Cat) {
((Cat) animal).say(); // downcasting
}
}
}

View File

@@ -1,19 +0,0 @@
import myObject.Animal;
import myObject.Cat;
import myObject.Dog;
public class Java22 {
public static void main(String[] args) {
// 2. 다형성 배열
Animal[] animals = new Animal[2];
animals[0] = new Dog();
animals[1] = new Cat();
for (Animal animal : animals) {
animal.eat();
if (animal instanceof Cat) {
((Cat) animal).say();
}
}
}
}

View File

@@ -1,19 +0,0 @@
import poly.Animal;
import poly.Cat;
import poly.Dog;
public class Java23 {
public static void main(String[] args) {
// 추상클래스
// Animal animal = new Animal; (X)
// upcasting 으로 활용
Animal cat = new Cat();
Animal dog = new Dog();
cat.eat();
cat.move();
dog.eat();
dog.move();
}
}

View File

@@ -1,20 +0,0 @@
import poly.Radio;
import poly.RemoCon;
import poly.TV;
public class Java24 {
public static void main(String[] args) {
// 인터페이스
// 객체 생성 X : RemoCon r = new RemoCon(); (X)
RemoCon r = new TV();
r.chUp();
r.chDown();
r.internet();
r = new Radio();
r.chUp();
r.chDown();
r.internet();
}
}

View File

@@ -1,16 +0,0 @@
import poly.Radio;
import poly.RemoCon;
import poly.TV;
public class Java25 {
public static void main(String[] args) {
RemoCon r = new TV();
for (int i = 0; i < 10; i++) {
r.chUp();
}
for (int i = 0; i < 10; i++) {
r.chDown();
}
r.internet();
}
}

View File

@@ -1,15 +0,0 @@
import myObject.DBConnect;
import myObject.JavaMySQLDriver;
import myObject.JavaOracleDriver;
public class Java26 {
public static void main(String[] args) {
// Oracle, MySQL 등을 사용하기 위해 Driver class 가 필요
DBConnect conn = new JavaOracleDriver();
conn.getConnection("url", "id", "password");
conn = new JavaMySQLDriver();
conn.getConnection("url", "id", "password");
}
}

View File

@@ -1,10 +0,0 @@
import poly.A;
public class Java27 {
public static void main(String[] args) {
Object o = new A();
((A) o).display();
System.out.println(o.toString());
}
}

View File

@@ -1,20 +0,0 @@
import myObject.A;
import myObject.B;
public class Java28 {
public static void main(String[] args) {
A a = new A();
display(a);
B b = new B();
display(b);
}
private static void display(Object o) {
if (o instanceof A) {
((A) o).go();
} else {
((B) o).go();
}
}
}

View File

@@ -1,31 +0,0 @@
import myObject.A;
import myObject.B;
public class Java29 {
public static void main(String[] args) {
// A, B 클래스를 저장할 배열
Object[] o = new Object[2];
o[0] = new A();
o[1] = new B();
for (int i = 0; i < o.length; i++) {
if (o[i] instanceof A) {
((A) o[i]).go();
} else {
((B) o[i]).go();
}
}
printGo(o);
}
private static void printGo(Object[] o) {
for (int i = 0; i < o.length; i++) {
if (o[i] instanceof A) {
((A) o[i]).go();
} else {
((B) o[i]).go();
}
}
}
}

View File

@@ -1,9 +0,0 @@
import kr.study.MyClass;
public class Java30 {
public static void main(String[] args) {
MyClass myClass = new MyClass();
int sum = myClass.sum(3, 4);
System.out.println(sum);
}
}

View File

@@ -1,13 +0,0 @@
public class Java31 {
public static void main(String[] args) {
String str = "apple"; // java.lang.String str = new java.lang.String("apple");
// String 클래스의 다양한 메소드들
System.out.println(str.toUpperCase());
System.out.println(str.charAt(3));
System.out.println(str.length());
System.out.println(str.indexOf("pl"));
System.out.println(str.indexOf("px"));
System.out.println(str.replaceAll("p", "x"));
}
}

View File

@@ -1,21 +0,0 @@
public class Java32 {
public static void main(String[] args) {
// new 로 생성
String str1 = new String("APPLE");
String str2 = new String("APPLE");
// str1과 str2는 객체 이므로 heap 영역에 저장된 번지수가 저장됨
// new 로 생성하면 각각 다른 객체를 생성하여 가리키므로 다름
System.out.println(str1 == str2);
// 번지수가 아닌 값을 비교 하려면 equals 사용
System.out.println(str1.equals(str2));
// 문자열 상수로 생성
String str3 = "APPLE";
String str4 = "APPLE";
System.out.println(str3 == str4);
}
}

View File

@@ -1,19 +0,0 @@
import kr.study.IntArray;
import java.util.ArrayList;
import java.util.List;
public class Java33 {
public static void main(String[] args) {
IntArray arr = new IntArray(5);
arr.add(10);
arr.add(20);
arr.add(30);
for (int i = 0; i < arr.size(); i++) {
System.out.println(arr.get(i));
}
}
}

View File

@@ -1,64 +0,0 @@
public class Java34 {
public static void main(String[] args) {
int a = 1; // 기본자료형
Integer b = new Integer(1); // 객체자료형
System.out.println(a);
System.out.println(b.intValue()); // 1
System.out.println(b.toString()); // "1"
System.out.println("=======================");
int c = new Integer(1); // unboxing
Integer d = 1; // boxing
System.out.println(c);
System.out.println(d.intValue()); // 1
System.out.println(d.toString()); // "1"
System.out.println("=======================");
Object[] obj = new Object[3];
obj[0] = new Integer(1);
obj[1] = new Integer(2);
obj[2] = new Integer(3);
System.out.println(obj[0].toString());
System.out.println(obj[1].toString());
System.out.println(obj[2].toString());
System.out.println("=======================");
Object[] obj2 = new Object[3];
obj2[0] = 1;
obj2[1] = 2;
obj2[2] = 3;
System.out.println(obj2[0].toString());
System.out.println(obj2[1].toString());
System.out.println(obj2[2].toString());
System.out.println("=======================");
// "100" + "100" = 200
String x = "100";
String y = "100";
System.out.println(x + y); // "100100"
System.out.println("=======================");
int i = Integer.parseInt(x);
int j = Integer.parseInt(y);
System.out.println(i + j); // 200
System.out.println("=======================");
// 100 + 100 = "100100"
String v1 = String.valueOf(i);
String v2 = String.valueOf(j);
System.out.println(v1 + v2);
}
}

View File

@@ -1,29 +0,0 @@
package kr.study;
public class IntArray {
private int count; // 배열의 현재 인덱스
private int[] arr; // 배열 생성
// 생성자
public IntArray(){
this(10); // 입력값이 없으면 길이 10
}
public IntArray(int init){
arr=new int[init]; // 입력한 값의 길이를 생성
}
// 배열에 데이터 추가
public void add(int data){
arr[count++]=data;
}
// 배열의 값 반환
public int get(int index){
return arr[index];
}
// 배열의 길이 출력
public int size(){
return count;
}
}

View File

@@ -1,11 +0,0 @@
package kr.study;
public class MyClass { // 패키지가 있을 경우 public 을 생략하면 default 접근권한을 가진다.
public int sum(int a, int b){
int hap=0;
for(int i=a;i<=b;i++){
hap+=i;
}
return hap;
}
}

View File

@@ -1,7 +0,0 @@
package myObject;
public class A {
public void go() {
System.out.println("A의 go 메소드");
}
}

View File

@@ -1,7 +0,0 @@
package myObject;
public class Animal {
public void eat() {
System.out.println("냠냠");
}
}

View File

@@ -1,7 +0,0 @@
package myObject;
public class B {
public void go() {
System.out.println("B의 go 메소드");
}
}

View File

@@ -1,8 +0,0 @@
package myObject;
public class Book {
public String title;
public int price;
public String company;
public int page;
}

View File

@@ -1,18 +0,0 @@
package myObject;
public class BookDTO {
public String title;
public int price;
public String company;
public int page;
public BookDTO() {
}
public BookDTO(String title, int price, String company, int page) {
this.title = title;
this.price = price;
this.company = company;
this.page = page;
}
}

View File

@@ -1,18 +0,0 @@
package myObject;
public class BookVO {
public String title;
public int price;
public String company;
public int page;
public BookVO() {
}
public BookVO(String title, int price, String company, int page) {
this.title = title;
this.price = price;
this.company = company;
this.page = page;
}
}

View File

@@ -1,12 +0,0 @@
package myObject;
public class Cat extends Animal{
@Override
public void eat() {
System.out.println("고양이가 먹는다");
}
public void say() {
System.out.println("냐옹옹");
}
}

View File

@@ -1,6 +0,0 @@
package myObject;
public interface DBConnect {
// 규약
void getConnection(String url, String user, String password);
}

View File

@@ -1,8 +0,0 @@
package myObject;
public class Dog extends Animal{
@Override
public void eat() {
System.out.println("개가 먹는다");
}
}

View File

@@ -1,8 +0,0 @@
package myObject;
public class JavaMySQLDriver implements DBConnect{
@Override
public void getConnection(String url, String user, String password) {
System.out.println("MySQL DB에 접속합니다.");
}
}

View File

@@ -1,8 +0,0 @@
package myObject;
public class JavaOracleDriver implements DBConnect{
@Override
public void getConnection(String url, String user, String password) {
System.out.println("Oracle DB에 접속합니다.");
}
}

View File

@@ -1,59 +0,0 @@
package myObject;
public class MemberVO {
private String name;
private int age;
private String tel;
private String addr ;
public MemberVO(){}
public MemberVO(String name, int age, String tel, String addr) {
this.name = name;
this.age = age;
this.tel = tel;
this.addr = addr;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
@Override
public String toString() {
return "MemberVO{" +
"name='" + name + '\'' +
", age=" + age +
", tel='" + tel + '\'' +
", addr='" + addr + '\'' +
'}';
}
}

View File

@@ -1,11 +0,0 @@
package myObject;
public class MyUtil {
public int hap() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
return sum;
}
}

View File

@@ -1,14 +0,0 @@
package myObject;
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);
}
}

View File

@@ -1,8 +0,0 @@
package myObject;
public class Person {
public String name;
public int age;
public float weight;
public float height;
}

View File

@@ -1,15 +0,0 @@
package myObject;
public class PrivateConstructor {
private PrivateConstructor() {
}
public void nonStaticMethod() {
System.out.println("non-static-method");
}
public static void staticMethod() {
System.out.println("static method");
}
}

View File

@@ -1,13 +0,0 @@
package poly;
public class A{
public void display() {
System.out.println("A 클래스");
}
@Override
public String toString() {
return "재정의 메소드";
}
}

View File

@@ -1,11 +0,0 @@
package poly;
// 추상 클래스 -> 불완전 클래스 : 객체 생성 불가 new Animal() (X)
public abstract class Animal {
public abstract void eat(); // 추상 메소드 -> 불완전 메소드
public void move() { // 일반 메소드도 작성 가능
System.out.println("이동한다.");
}
}

View File

@@ -1,12 +0,0 @@
package poly;
public class Cat extends Animal {
@Override
public void eat() {
System.out.println("고양이가 먹는다");
}
public void say() {
System.out.println("냐옹옹");
}
}

View File

@@ -1,8 +0,0 @@
package poly;
public class Dog extends Animal {
@Override
public void eat() {
System.out.println("개가 먹는다");
}
}

View File

@@ -1,18 +0,0 @@
package poly;
public class Radio implements RemoCon{
@Override
public void chUp() {
System.out.println("Radio 채널이 올라간다.");
}
@Override
public void chDown() {
System.out.println("Radio 채널이 내려간다.");
}
@Override
public void internet() {
System.out.println("Radio는 인터넷 사용 불가");
}
}

View File

@@ -1,13 +0,0 @@
package poly;
public interface RemoCon { // 객체 생성 X : RemoCon r = new RemoCon(); (X)
// 상수를 사용가능 ( public static final 생략 )
int MAXCH = 100;
int MINCH = 1;
// public abstract 생략
void chUp();
void chDown();
void internet();
}

View File

@@ -1,29 +0,0 @@
package poly;
public class TV implements RemoCon{
int currCH = 95;
@Override
public void chUp() {
if (currCH < RemoCon.MAXCH) {
currCH++;
} else {
currCH = 1;
}
System.out.println("TV의 채널이 올라간다. : " + currCH);
}
@Override
public void chDown() {
if (currCH > RemoCon.MINCH) {
currCH--;
} else {
currCH = RemoCon.MAXCH;
}
System.out.println("TV의 채널이 내려간다. : " + currCH);
}
@Override
public void internet() {
System.out.println("TV는 인터넷 사용 가능");
}
}