Java6 Java 작성 시 신경쓰면 좋은 Early return, Guard clause * return false가 먼저 오도록 작업 하기 Why?Early return이란?불필요한 코드 실행 방지: return false 이후의 코드는 실행되지 않으므로, 조건이 충족되지 않았을 때 불필요한 작업을 막을 수 있다.성능 최적화: 조건이 충족되지 않은 경우 즉시 함수를 종료함으로써 리소스를 절약할 수 있다. 예제 - 강의 등록, 취소 import entity.Lecture;import entity.Student;public class StudentTest { public static void main(String[] args) { // 학생 입력 Student s1=new Student("김나나","32번"); Student s2=new Student.. 2024. 12. 12. Java if와 논리 연산자를 이용한 날짜 출력 예제 package entity;public class MyDate { private int day; private int month; private int year; //디폴트 생성자 public MyDate() { } //MyDate(int day, int month, int year) 생성자 public MyDate(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } // todo 우리가 만들 메소드 public boolean isValid() { if (month 12) { .. 2024. 12. 12. Java 함수 만들기 // 3과 5를 더하자.int num1 = 3;int num2 = 5;System.out.println(num1 + num2);// 7과 10을 더하자.num1 = 7;num2 = 10;System.out.println(num1+num2);// 10과 6을 더하자.num1 = 10;num2 = 6;System.out.println(num1+num2); // 프로그래밍 하다보니 중복되는 코드 == 재사용되는 코드가 발생하더라 // 효율적으로 처리하기위해 만든게 함수다! // 지금까지는 함수를 사용만 해봤다 = 함수를 호출(call) 했다 = 남이 만든것을 이용 // 함수 호출은 1줄만 필요 // 어떤 복잡한 기능이라도 함수로 만들어져있으면 .. 2024. 12. 9. Java 기본 배열 Array 학생 점수 관리 프로그램을 만들기 학생 3명의 수학 점수를 처리 첫번째 학생은 70점, 2번째 학생은 90점, 3번째 학생은 77점 int mathScore1 = 70; int mathScore2 = 90; int mathScore3 = 77; // 전체 총점 구하세요. System.out.println( mathScore1 + mathScore2 + mathScore3 ); // 평균 구하세요. System.out.println(( mathScore1 + mathScore2 + mathScore3 ) / 3); // 정수로만 계산하기때문에 소수점이 나오지 .. 2024. 12. 9. Java의 기본 문법 - 클래스, 변수 1. 클래스객체를 생성하기 위한 설계도붕어빵 틀 = 클래스 / 붕어빵 = 객체하나의 클래스로부터 여러개의 객체를 만들 수 있다. 클래스로부터 객체를 생성하는 과정 생성된 객체 클래스 이름의 규칙네이밍 컨벤션(Naming Convention) - 가독성, 일관성을 위함여러 단어로 구성된 경우 각 단어의 첫 글자를 대문자로 작성)클래스명은 대문자로 시작클래스명은 명사로 public 클래스는 단하나 public 클래스 이름과 자바 파일 이름은 같아야 한다. 패키지 이름은 모두 소문자로.2. 프로그램은 1개의 main() 함수가 있어야 한다.public 클래스'psvm'(public static void main)을 입력하면 IntelliJ IDEA에서 Java의 main() 메소드가 자동으로 생성됨Java .. 2024. 12. 9. Java란?, Java17 설치 및 환경변수 설정 Java란?Java는 1995년 썬 마이크로시스템즈(Sun Microsystems)에서 발표한 객체 지향 프로그래밍 언어로, 다양한 응용 프로그램을 개발하는 데 널리 사용됩니다. 자바 17 다운로드https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html Java Archive Downloads - Java SE 17WARNING: Older versions of the JDK are provided to help developers debug issues in older systems. They are not updated with the latest security patches and are not recommended.. 2024. 12. 8. 이전 1 다음