[TIL/Java] 객체 동등 비교 equals()
2024. 8. 21. 12:23
TIL/Java
equals()Object의 equals() 메소드는 객체의 번지를 비교하고 boolean 값을 리턴한다.`obj instanceof Class`: obj가 Class에 속하거나 Class를 상속받는 클래스에 속하면 true가 반환 됨 MemberExample.javapackage ch12.sec03.exam01;public class MemberExample { public static void main(String[] args) { Member mbr1 = new Member("홍길동"); Member mbr2 = new Member("홍길동"); Member mbr3 = new Member("고길동"); User usr1 = new User("홍길동"); System.out.printf("..
[TIL/Java] 다형성, 필드 다형성, 추상 클래스 (abstract)
2024. 8. 19. 15:27
TIL/Java
다형성프로그램을 구성하는 객체를 바꾸면 프로그램의 실행 성능이 다르게 나올 수 있다.객체 사용 방법이 동일하다는 것은 동일한 메소드를 가지고 있다는 뜻이다. 타이어를 한국 타이어와 금호 타이어를 상속하고 있는 상태타이어(부모) 메서드를 한국 타이어와 금호 타이어가 오버라이딩 하고 있다면타이어 메소드 호출 시 오버라이딩 된 메소드가 호출된다.오버라이딩 된 내용은 두 타이어가 다르기 때문에 실행 결과가 다르게 나온다.이것이 다형성이다.다형성을 구현하기 위해서는 자동 타입 변환과 메소드 재정의가 필요하다.필드 다형성필드의 타입과 그 타입에 의해 제공되는 메서드는 동일하게 사용되지만, 필드에 실제로 대입되는 객체가 달라져서 실행 결과가 다양하게 나올 수 있는 것 interface PaymentMethod { ..
[TIL/Java] 학생 수 입력받고 점수 등록하기 (if-else을 switch문으로 리팩토링)
2024. 8. 13. 16:26
TIL/Java
package practice;import java.util.Scanner;public class StudentAnalyze { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); boolean runFlag = true; int studentNum = 0; int[] scores = null; while (runFlag) { System.out.println("------------------------------------------"); System.out.println("1.학생 수 | 2.점수입력 | 3.점수리스트 | 4. 분석 | 5. 종료"); System.out.println..
[TIL/Java] 배열 항목에서 최대값 출력하기 (for문 이용)
2024. 8. 12. 15:20
TIL/Java
package practice;public class MaxArray { public static void main(String[] args) { int[] array = { 1, 5, 3, 8, 2 }; int max = -99999; for (int index = 0; index max) { max = array[index]; } } System.out.println(max); }}
[TIL/Java] 컴파일러란?
2024. 8. 7. 17:04
TIL/Java
컴파일러코드를 기계어로 바꿔주는 역할기계어를 CPU가 바로 알아먹는 것이 있고, 못 알아먹는 것이 있음CPU가 바로 알아먹으면 네이티브, 못 알아먹으면 비네이티브크로스 컴파일러와 비네이티브는 다른 것임자바 바이트코드도 그렇고, C#도 그렇고 중간 언어가 있음중간언어는 CPU가 직접 알아듣지는 못하지만 VM (Virtual Machine)을 통해서 CPU가 알아듣는 말로 번역해서 실행 됨4번의 역할을 하는 것이 바이트코드출처1. https://ko.wikipedia.org/wiki/%EC%BB%B4%ED%8C%8C%EC%9D%BC%EB%9F%AC