일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 참조타입
- html
- DB
- JavaScript
- 자바
- 개선
- controller
- java
- mybatis
- 형변환
- interface
- 환경설정
- jsp
- regex
- 자료구조
- jquery
- String
- for문
- jdbc
- scope
- Set
- JCF
- Selector
- 알고리즘
- SQL
- jar
- 자바스크립트
- extends
- iBATIS
- 정규화표현식
- Today
- Total
프로그래밍공부노트
Day 6 - JAVA(Argumnets, Paratmeter, 기본타입, 참조타입) 본문
19. UML(Unified Modeling Language)
- Class Diagram
패키지 클래스명 |
멤버필드 |
생성자 멤버메소드(타입) : 타입 |
file => new => other => ObjectAID UML Diagram => ObjectAID Class Diagram 선택
- plugin 주소를 이용해서 software
help => install new software
www.objectaid.com/update/current <- 클래스파일을 클래스 다이어그램으로 만들어줌
19. Cafe 프로그램 Class Diagram
20. Arguments & Parameter
- Argumetns : 메소드를 실행시키기 위해 필수적으로 필요한 값(value)
추가적인 내용 기본타입 값볷사(pass by value) immutable, 참조타입은 주소 전달(pass by reference) mutable
- Parameter는 전달받은 값을 연산블럭{}에서 사용하기 위해 이름을 정의 해 놓은 것
넘겨받은 값/주소를 담고 있는 변수 (타입 변수)
기본타입 값 복사
package com.min.edu;
import java.util.Scanner;
public class OrderMain {
public static void main(String[] args) {
// 기본타입 특징
long initL = 1000;
byte initB = 77;
System.out.println(initL);
System.out.println(initB);
CoffeeMake.primitiveType(initL, initB);
System.out.println(initL);
System.out.println(initB);
}
}
package com.min.edu;
public class CoffeeMake {
// parameter 필요한 이유 전달받은 값을 부를 수 있는 이름(캐치볼)
/**
* Arguments & parameter
* @param money long
* @param ChoiceCoffee byte
*/
public static void primitiveType(long money, byte ChoiceCoffee) {
System.out.println("입력된 금액 :" + money);
System.out.println("선택된 커피 :" + ChoiceCoffee);
CoffeeMake c = new CoffeeMake();
c.change2(money, ChoiceCoffee);
}
private void change2(long l, byte b) {
l = 99;
b = 99;
}
}
참조타입 값 전달
package com.min.edu;
import java.util.Scanner;
public class OrderMain {
public static void main(String[] args) {
//참조타입 특징
PassPort myInfo = new PassPort();
myInfo.name = "홍길동";
myInfo.age = 100;
myInfo.print();
CoffeeMake.referenceType(myInfo); // pass by reference
myInfo.print();
}
}
package com.min.edu;
public class CoffeeMake {
// parameter 필요한 이유 전달받은 값을 부를 수 있는 이름(캐치볼)
/**
* Arguments & parameter
* @param money long
* @param ChoiceCoffee byte
*/
public static void referenceType(PassPort me) {
System.out.println(me.name);
System.out.println(me.age);
CoffeeMake c = new CoffeeMake();
c.change(me);
}
private void change(PassPort ch) {
ch.name = "또치";
ch.age = 40;
}
}
package com.min.edu;
/**
* 이름과 나이를 가질 수 있는 클래스
* @author SANGJINYU
*
*/
public class PassPort {
public String name;
public int age;
public void print() {
System.out.printf("%s : %d\n",name,age);
}
}
ex) 커피자판기에 돈(Long타입), 선택된 커피(byte) => 묶음 입력
Scanner : java.util.Scanner 입력 인터페이스에서 입력을 쉽게 할 수 있도록 만들어진 객체
Scanner scan = new Scanner(System.in);
scan.nextInt()
package com.min.edu;
import java.util.Scanner;
public class OrderMain {
public static void main(String[] args) {
//Scanner 객체
Scanner scanner = new Scanner(System.in);
System.out.println("값을 입력해 주세요.");
int n = scanner.nextInt();
int m = scanner.nextInt();
System.out.println("입력받은 정수값:" + n + ":" + m);
System.out.println("돈을 입력해 주세요");
long l = scanner.nextLong();
System.out.println("커피를 선택해 주세요");
int i = scanner.nextInt();
21. JAVA Statement
1) end semicolon ; (종료의 의미)
2) declaration statement(선언문) : int a; (값을 주지 않은 상태)
3) 메소드의 호출(실행)
Method invocation statement
4) object create statement (객체생성) : new Object();
5) unary increment and decrement statement : ++x;, x++;, --x;, x--;
6) control flow statement
- selection statemen : if - else / switch - case
- iteration statement : for or while(컨디션 루프) / do-while
- execption - handling statement : throw, try-catch, try-catch-finally, (1.8 try-resource-with)
(run-time exception 실행시켰을때), checked-exception(파일 진짜 있어? 확인해봐))
에러는 개발자가 처리할 수 없음
- branching statement : continue; break; return;
선언시 초기값에 대하여
package com.min.edu;
import java.util.Scanner;
public class Declaration {
//멤버필드는 선언하고 초기값이 없을때 인스턴스화를 하면 초기값이 자동으로 생김
public byte b;
public short s;
public int i;
public long l;
public float f;
public double d;
public boolean bool;
public char c;
public int saveInt = 20210217;
public Scanner scanner;
public void testDeclar() {
//local variable에서의 변수 혹은 객체의 선언은
//반드시 값을 입력해야 한다
//이유는 초기화하는 기능이 없기 때문임
//사용되는 시점이 객체를 생성하고 메소드를 실행했을 경우에만 동작
int a;
Scanner s;
System.out.println(6/0);
}
}
package com.min.edu;
import java.util.Scanner;
public class Declaration_Main {
public static void main(String[] args) {
Declaration d = new Declaration();
// d.testDeclar();
System.out.println(d.b);
System.out.println(d.s);
System.out.println(d.i);
System.out.println(d.l);
System.out.println(d.f);
System.out.println(d.d);
System.out.println(d.bool);
System.out.println((int)d.c);
System.out.println(d.scanner); // 객체의 초기화는 null
System.out.println(d.saveInt);
}
}
'JAVA' 카테고리의 다른 글
Day 8 - JAVA실습(for문, 삼각형) (0) | 2021.02.20 |
---|---|
Day 7 - JAVA(if-else, while, do-while, break, continue) (0) | 2021.02.18 |
Day 5 - JAVA(method, static, return) (1) | 2021.02.16 |
Day 4 -JAVA(type) (0) | 2021.02.15 |
Day 3 - JAVA(access modify) (0) | 2021.02.10 |