Java 1.5 부터 나온 개념으로 자료형을 결정짓지 않고 틀을 만들어 두는 것을 말합니다.
Object(참조형 타입) 자리에 T들어갑니다.
그래서 자료형의 정보를 Object 대신 T로 작성해 비워 두고 인스턴스 생성시 참조 타입을 결정합니다
public static void main(String[] args) {
Box abox = new Box();
Box obox = new Box<>();
Box sbox = new Box<>();
Box ibox = new Box<>();
Box dbox = new Box<>();
dbox.set(1.0);
double dNum = dbox.get();//형변환도 필요없음
System.out.println(dNum);
}
package day_2024_08_05;
class Box<T> {
private T ob;
public void set(T o) {
ob = o;
}
public T get() {
return ob;
}
}
public class BoxMain {
public static void main(String[] args) {
Box<Apple> abox = new Box<Apple>();
Box<Orange> obox = new Box<>();
Box<String> sbox = new Box<>();
Box<Integer> ibox = new Box<>();
Box<Double> dbox = new Box<>();
dbox.set(1.0);
double dNum = dbox.get();
System.out.println(dNum);
}
}
DBox<String, Integer> box = new DBox<String, Integer>(); box.set("Apple", 25); System.out.println(box); // Apple & 25
package day_2024_08_06;
class DBox<T, I> {
private T str;
private I count;
public void set(T str, I count) {
this.str = str;
this.count = count;
}
@Override
public String toString() {
return str + " , " + count;
}
}
public class DBoxMain {
public static void main(String[] args) {
DBox<String, Integer> box = new DBox<String, Integer>();
box.set("Apple", 25);
System.out.println(box);
}
}
--사원테이블(emp)에서 급여 (SAL)가 3000 이상인 사원을 출력하는 쿼리문
select * from emp where sal>=3000;
-- 사용하여 부서 번호(DEPTNO)가 20인 사원에 관한 정보만 출력하는 쿼리문
select * from emp where deptno=20;
--이름(ENAME)이 KING인 사람의 사번(empno), 이름(ename), 급여(SAL)를 출력하는 쿼리문
select empno,ename,sal from emp where ename='KING';
--1982년 1월 1일 이후에 입사한 사원을 출력하는 쿼리문
- select empno,ename,sal from emp where hiredate>='1982/01/01';
- select empno,ename,sal from emp where hiredate>='1982.01.01';
--부서번호가 10번이고 job 이 메니져인 사원은?
select *from emp where deptno=10 and job='MANAGER';
--부서번호가 10번 or(또는) job 이 메니져인 사원은?
select *from emp where deptno=10 or job='MANAGER';
--부서번호가 10 번이 아닌 사원?
select *from emp where deptno!=10 ;
DESC는 DESCRIBE의 약어로, 테이블이나 뷰(view)의 구조를 설명하는 데 사용됩니다.
DESCRIBE 명령은 테이블의 열 이름, 데이터 타입, 제약 조건 등의 정보를 제공합니다.
interface Stack {
int length(); // 현재 스택에 저장된 개수 리턴
int compacity(); // 스택의 전체 저장 가능한 개수 리턴
String pop(); // 스택의 톱(top)에 저장
boolean push(String val); // 스택의 톱(top)에 저장된 문자 리턴
}
StringStack 는 객체가 생성될때 기본적으로 3개의 배열을 갖는다.
boolean push(String val) 구현시 Stack이 다 차있을경우, 배열의 크기를 원래의
크기보다 2배로 늘리고, 원래 있던 배열의 요소를 새로운 배열로 복사하도록 할것.
package day_2024_08_05;
import java.util.Scanner;
interface Stack3 {
int length(); // 현재 스택에 저장된 개수 리턴
int compacity(); // 스택의 전체 저장 가능한 개수 리턴
String pop(); // 스택의 톱(top)에 저장
boolean push(String val); // 스택의 톱(top)에 저장된 문자 리턴
}
class StringStack3 implements Stack3 {
private String arrStr[];
private int index; // top
public StringStack3() {
arrStr = new String[3];
index = 0;
}
public StringStack3(int size) {
arrStr = new String[size];
index = 0;
}
@Override
public int length() {
return index;
}
@Override
public int compacity() {
return arrStr.length;
}
@Override
public String pop() {
if (index == 0)
return "비어있음";
else {
String str = arrStr[index - 1];
index--;
return str;
}
}
@Override
public boolean push(String val) {
String arrTemp[];
if (index == arrStr.length) {
arrTemp = new String[arrStr.length * 2]; // 배열을 2배로 늘리고
for (int i = 0; i < arrStr.length; i++) { // 기존에 있던 값을 새로운 배열로 이동
arrTemp[i] = arrStr[i];
}
arrStr = arrTemp; // 기존의 배열을 새로운 배열로 교체
}
arrStr[index++] = val;
return true;
}
}
public class StackMain3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringStack3 stack3 = new StringStack3();
System.out.print("총 스택 저장 공간의 크기 입력 >> ");
stack3 = new StringStack3(sc.nextInt());
while (true) {
System.out.print("문자열 입력");
String str = sc.next();
if (str.equals("그만")) {
break;
}
boolean isFull = stack3.push(str);
if (isFull == false) {
System.out.println("스택이 꽉 차서 푸시 불가!");
}
}
System.out.print("스택에 저장된 모든 문자열 팝 :");
int length = stack3.length();
for (int i = 0; i < length; i++) {
System.out.print(stack3.pop() + " ");
}
}
}

package day_2024_08_06;
import java.util.Scanner;
class Player {
protected String[] player = new String[2];
public Player() {
Scanner sc = new Scanner(System.in);
System.out.print("첫번째 플레이어 이름 >> ");
player[0] = sc.next();
System.out.print("두번째 플레이어 이름 >> ");
player[1] = sc.next();
}
}
class SlotMachine extends Player {
private int playerNum = 0;
private int[] random = new int[3];
public SlotMachine() {
super();
}
public void run() {
while (true) {
Scanner sc = new Scanner(System.in);
System.out.print(player[playerNum++ % 2] + ":\t");
String enter = sc.nextLine();
for (int i = 0; i < random.length; i++) {
random[i] = (int) (Math.random() * 3);
System.out.print("\t" + random[i]);
}
if (random[0] == random[1] && random[0] == random[2]) {
System.out.println("\t" + player[++playerNum % 2] + "님 승리!!!");
break;
}
System.out.println("\t아쉽군요!");
}
}
}
public class SlotMachineGame {
public static void main(String[] args) {
SlotMachine game = new SlotMachine();
game.run();
}
}