JAVA

    [자바/JAVA] 프로그래밍 - API_String (2) String Method

    1. 문자열.charAt(int index) : char 문자열에서 전달받은 index 위치의 문자만을 추출해서 리턴 String str1 = "Hello World"; char ch = str1.charAt(3); System.out.println("ch : " + ch); 2. 문자열.concat(String str) : String 문자열과 전달된 또다른 문자열을 하나로 합쳐서 새로운 문자열로 리턴 String str1 = "Hello World"; String str2 = str1.concat("!!!!"); System.out.println(str2); System.out.println(str1);// 바뀌진 않음 String str3 = str1 + "!!!!"; System.out.print..

    [자바/JAVA] 프로그래밍 - API_String (1) String Pool

    1. 생성자를 통한 문자열 생성 package com.kh.chap02_string.controller; public class A_StringPoolTest { public void method1() { /* String s = "안뇽";// 참조자료형 int a = 10;// 기본자료형 */ // 1. 생성자를 통한 문자열 생성 String str1 = new String("hello");// 매개변수 생성자 String str2 = new String("hello");// 매개변수 생성자 // 주소값이 출력되지 않을까? System.out.println(str1.toString()); System.out.println(str2); // String 클래스에 toString() 메소드가 이미 오버라이..

    [자바/JAVA] 프로그래밍 - API_Math

    Math 특징 java.lang.Math (String, Object) => 굳이 import 안해도 사용 할 수 있음! - 모든 필드 상수필드, 모든 메소드 static 메소드!! (싹 다 static임!!) - 생성자 private 로 돼있음 => 생성 불가하도록!!! ** 한번만 메모리 영역에 올려놓고 재사용 하는 개념 => 싱글톤 패턴 ** openjdk11 document 상수 필드 System.out.println("파이 : " + Math.PI); 절대값을 알고자 할 때 : abs(앱솔루트) int num = -10; System.out.println("절대값 : " + Math.abs(num));// 오버로딩 올림 : ceil : 크거나 같은 정수값 double num2 = 4.349;//..

    [자바/JAVA] 프로그래밍 - 다형성 (Polymorphism) - 추상(abstract) - Interface

    추상클래스(abstract Class) : 일반필드 + 일반메소드 [+ 추상메소드] 인터페이스(interface) : only 상수필드 + 추상메소드 인터페이스 사용 전 Person Class package com.kh.chap02_abstractAndInterface.part02_basic.model.vo; public abstract class Person { private String name; private double weight; private int health; public Person() { } public Person(String name, double weight, int health) { this.name = name; this.weight = weight; this.health =..

    [자바/JAVA] 프로그래밍 - 다형성 (Polymorphism) - 추상(abstract)

    추상메소드 - 미완성된 메소드로 몸통부({})가 구현되어 있지 않은 메소드 추상클래스 - 미완성된 클래스 - 일반필드 + 일반메소드 [+ 추상메소드] => 추상메소드를 가진 클래스는 반드시 추상클래스로 명시 해야됨 * 추상메소드가 굳이 없어도 추상클래스로 만들 수 있음 언제사용되나요? > 개념적 : 단지 이 클래스가 미완성된 클래스다 라는걸 부여할 목적 => 덜 만들었을때 > 프로그래밍적 : 객체 생성이 불가 하게끔 라고자 할 때 * 추상메소드가 존재하는 추상클래스를 쓰는 이유 - 부모클래스에 추상메소드가 존재할 경우 자식클래스에서는 강제로 오버라이딩 해서 동일한 패턴의 메소드를 가지게 됨!! => 각 자식 클래스마다 실행시킬 내용은 다르지만 동일한 형태의 메소드로 구혔했으면 할 때 => 메소드 통일성 ..

    [자바/JAVA] 프로그래밍 - 다형성 (Polymorphism)

    // 기억해둘 것 !! '=' 기준으로 해서 왼쪽과 오른쪽의 자료형(타입)은 같아야 됨 System.out.println("1. 부모타입 레퍼런스로 부모객체를 다루는 경우"); Parent p1 = new Parent(); p1.printParent(); // p1 레퍼런스로 Parent 에만 접근 가능 System.out.println("2. 자식타입 레퍼런스로 자식객체를 다루는 경우"); Child1 c1 = new Child1(); c1.printChild1(); c1.printParent();// 자동형변환 된거였음!! (Child1 => Parent) // ((Parent)c1).printParent(); // c1 레퍼런스로 Child1, Parent 둘다 접근 가능 // Parent 접근시 ..

    [자바/JAVA] 프로그래밍 - 상속 (inheritance) 실습 문제_2

    [상속 실습문제2] 다음과 같은 조건을 만족하는 프로그램을 작성 하시오 도형의 x,y 좌표 값과 각 도형의 면적, 둘레를 계산하는 프로그램이다. 해당 구현 클래스 다이어그 램과 클래스의 구조를 참고하여 프로젝트를 완성하시오. Point Class package com.hw2.model.vo; public class Point { private int x; private int y; public Point() { } public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } publi..

    [자바/JAVA] 프로그래밍 - 상속 (inheritance) 실습 문제_1

    [상속 실습문제1] 다음과 같은 조건을 만족하는 프로그램을 작성 하시오 학생과 직원을 관리하는 프로그램으로 상속 구조를 통해 구현해보시오. 해당 클래스 다이어그램 과 클래스 구조를 참고하여 프로젝트를 완성하시오 Person Class package com.hw1.model.vo; public class Person { protected String name; private int age; private double height; private double weight; public Person() { } public Person(int age, double height, double weight) { this.age = age; this.height = height; this.weight = weight..