inblog logo
|
Coding's note
    JAVA

    이소연's avatar
    이소연
    Aug 05, 2024
    Contents
    연습문제String 예제문제컬렉션스레드스트림버퍼채팅 만들기 가능
    💡
    패키지(폴더)(자바 클래스 파일 모여있는 거)
    패키지(폴더)
    (클래스 파일(java,class) )
     
     
    패키지의 모임 = 라이브러리
    💡
    패키지의 모임 = 라이브러리
     
    라이브러리 모듬 = 모듈
    -class 모여있는 거
     
    클래스 path설정
    필요 라이브러리가 외부에 있을 때?!
    notion image
    notion image
    notion image
    notion image
    scanner내용 바꾸고파 ⇒ 상속받아서 재정의. ⇒ but final있어서 변경x
     
    자바로 구웠는데 main이 없으면 lib(실행될 필요가 없으니까?)-v
    실행되면 exe?!
     
    이게 생략되있음
    notion image
    notion image
    notion image
    notion image
    notion image
    notion image
    notion image
    account랑 account.tostring()이랑 같음-v
    notion image
    package ex03.test; interface 행위 { void start(); } class 삼양라면 implements 행위 { private void 물끓이기() { } private void 스프넣기() { } private void 면넣기() { } private void 계란넣기() { } @Override public void start() { 물끓이기(); 면넣기(); 스프넣기(); 계란넣기(); } } class 신라면 implements 행위 { private void 물끓이기() { } private void 스프넣기() { } private void 면넣기() { } private void 계란넣기() { } @Override public void start() { 물끓이기(); 스프넣기(); 면넣기(); 계란넣기(); } } public class ScopeEx02 { public static void main(String[] args) { 삼양라면 la = new 삼양라면(); la.start(); 신라면 la2 = new 신라면(); la2.start(); } }
    package ex03.test; class Account { private int number; // 1111 private String pw; // 8877 private String author; // 최주호 private int balance; // 1000 public Account(int number, String pw, String author, int balance) { this.number = number; this.pw = pw; this.author = author; this.balance = balance; } public int getNumber() { return number; } public String getPw() { return pw; } public String getAuthor() { return author; } public int getBalance() { return balance; } public void chanagePassword(String pw){ this.pw = pw; } public void changeAuthor(String author) { this.author = author; } public void deposit(int amount){ this.balance = this.balance + amount; } public void withdraw(int amount){ this.balance = this.balance - amount; } public void setBalance(int balance){ this.balance = balance; } } public class ScopeEx02 { public static void main(String[] args) { // 1. 계좌생성 (2023.12.25) Account account = new Account(1111, "8877", "최주호", 1000); // 2. 입금 (2023.01.10) - 5000 account.deposit(5000); // 3. 비밀번호 변경 (2023.01.20) - 9988 account.chanagePassword("9988"); // 4. 계명 - 이름 변경 (2023.02.20) - 홍길동 account.changeAuthor("홍길동"); // 5. 계좌번호변경 - 은행 - 불가능합니다. // 6. 출금 - 500원 account.withdraw(500); // 7. 5000 원 입금 int currentBalance = account.getBalance(); int balance = currentBalance + 5000; account.setBalance(balance); } }
    package ex06.example7; public class BurgerSet { // has Burger, Coke private Burger burger; private Coke coke; public BurgerSet(Burger burger, Coke coke) { this.burger = burger; this.coke = coke; System.out.println("버거 세트가 만들어졌어요"); } public int getTotalPrice() { return burger.getPrice() + coke.getPrice(); } public Burger getBurger() { return burger; } public Coke getCoke() { return coke; } }
    package ex06.example7; public class LotteApp { public static void main(String[] args) { Burger b1 = new Burger("기본버거", 1000); // [Burger] Burger b2 = new ShrimpBurger("새우버거", 2000, "새우"); // [Burger, ShrimpBurger] Coke c1 = new Coke("콜라", 1000); System.out.println(); BurgerSet set1 = new BurgerSet( new Burger("기본버거", 1000), new Coke("콜라", 1000) ); System.out.println("총 가격은 : " + set1.getTotalPrice()); // System.out.println(set1.getBurger().getPrice()); // System.out.println(set1.getCoke().getPrice()); } }
    package ex08; class Account extends Object { private String author; private int number; private int balance; public Account(String author, int number, int balance) { this.author = author; this.number = number; this.balance = balance; } @Override public String toString() { return "Account{" + "author='" + author + '\'' + ", number=" + number + ", balance=" + balance + '}'; } } public class ObEx01 { public static void main(String[] args) { Account account = new Account("홍길동", 1111, 1000); System.out.println(account); System.out.println(account.toString()); System.out.println(account.getClass()); System.out.println(account.hashCode()); } }
     
    ==은 메모리 주소를 비교하는 것
    ⇒ 가르치는 게 다르니까 다른 거.
    notion image
     
    ==은 상황에 따라 주소이나 값 비교
    ==은 기본 자료형(int, long,boolea, char) : 값
    ==은 참조 자료형(그 외) : 주소
     
     
    notion image
    equals로 상태 비교를 한다.
    equals는 object 상속 // object는 모든 객체의 부모.
    1. 주소 먼저 비교
    1. 1. 안되면 안의 값을 비교
    notion image
     
    값을 비교하려면 equals
     
    메모리
    -static
    -heap
    내부에 string 영역이 따로 있음.
     
     
    -stack
     
    정수 기초/참조형
    notion image
    why? 메소드 사용 가능
    notion image
     
    파싱 : 구문분석
    파싱이 제대로 된 것⇒ 그 언어의 오브젝트로 된 것.
     
     

    연습문제

    package ex08.example; public class StringEx001 { public static void main(String[] args) { String date = "AABBBCCCCDDDDD"; // Byte -> 14Byte(한번에 8번 던짐) String convert = "A2B3C4D5"; // Byte -> 8Byte (인코딩.압축한 거) //SO (받는 쪽 : 디코딩해야 함. 압축에 대한 명세서가 필요) } }
     
     
    2>3>1
     

    String 예제문제

     
    제네릭

    컬렉션

    스레드

    스트림

    버퍼

    채팅 만들기 가능

    string
    공공api
    object
    jdbc(db 응용)
     
    Share article
    Contents
    연습문제String 예제문제컬렉션스레드스트림버퍼채팅 만들기 가능

    Coding's note

    RSS·Powered by Inblog