(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); 'code/JAVA' 카테고리의 글 목록 :: 깜냥깜냥

syso+Ctrl+space: system.out.println()

for+Ctrl+space: 다양한 for문
try+Ctrl+space: try-catch문
main+Ctrl+space: main이 만들어짐.


Ctrl + Shift + M : 특정 클래스 Import

Ctrl + Shift + O : 자동으로 Import

 

Ctrl + L : 특정 줄 번호로 이동

Ctrl + 마우스커서(혹은 F3) : 클래스나 메소드 혹은 멤버를 상세 검색

ALT + Left , ALT + Right : 이전, 이후 작업 화면

Ctrl + Shift + G : 특정 메소드나 필드를 Reference하고 있는 곳을 검색

Ctrl + , or  : 다음 annotation(에러, 워닝, 북마크 가능)으로 점프

Ctrl + T : hierarchy 팝업 창 띄우기(인터페이스 구현 클래스간 이동 시 편리)

F4 : hierachy view 퍼스펙티브 생성

Ctrl + O : 메소드나 필드 이동하기

Ctrl + Shift + Down : 클래스 내에서 다음 멤버로 이동

F2 : 컴파일 에러의 빨간 줄에 커서를 가져다가 이 키를 누르면 에러의 원인에 대한 힌트를 제공

Ctrl + 0 : 클래스 구조를 트리로 보기

Ctrl + Shift + T : 클래스 찾기

Ctrl + Shift + Space : 메소드의 파라미터 목록 보기

(메소드의 괄호 안에 커서를 놓고 이 키를 누르면 파라미터 타입 힌트를 볼 수 있음)

 

Ctrl + K : 찾고자 하는 문자열을 블럭으로 설정한 후 키를 누른다

Ctrl + Shift + K : 역으로 찾고자 하는 문자열을 찾아간다

Ctrl + J : Incremental find 이클립스 하단 상태 표시줄에 Incremental find 라고 표시되어 한 글자자씩 누를 때 마다 코드내의 일치하는 문자열로 이동, 다시 Ctrl + J 를 누르면 그 문자열과 일치 하는 부분을 위/아래 방향키로 탐색이 가능

Ctrl + PageUp , Ctrl + PageDown : Edit 창 좌우 이동 (Edit 창이 여러 개 띄워져 있을 경우 Edit 창간의 이동)

 

Ctrl + Shift + F : 코드 자동 정리

Ctrl + 1 : Quick Fix 에러가 발생했을 경우 Quick Fix를 통해 쉽게 해결이 가능함

Ctrl + Shift + / : 블록 주석(/* */)

Ctrl + Shift + \ : 블록 주석 제거

Ctrl + / : 여러 줄이 한꺼번에 주석 처리됨 (주석 해제하려면 반대로 하면 됨)

Alt + Up(Down) : 위(아래)줄과 바꾸기

Alt + Shift + UP : 커서를 기준으로 토큰단위 블럭지정

Alt + Shift + DOWN : 커서를 기준으로 토큰단위 블럭해제

Alt + Shift + 방향키 : 블록 선택하기

Alt + Shift + R : Refactoring (이름변경) - Refactoing 으로 전체 소스에서 이름변경에 의한 참조 정보를 변경해 준다

Alt + Shift + J : 자동으로 주석 달기 (메소드나 멤버변수에 포커스 두고 실행)

Alt + Shift + Z : Surround With 메뉴 (try / catch 문이나 for , do , while 등을 해당 블록에 감싸주는 메뉴가 나타남)

Ctrl + Space : 입력 보조장치(Content Assistance) 강제 호출 → 입력하는 도중엔 언제라도 강제 호출 가능함

Ctrl + D : 한 줄 삭제

Ctrl + W : 파일 닫기

Ctrl + I : 들여쓰기 자동 수정

Ctrl + Shift + X : 대문자로 변환

Ctrl + Shift + Y : 소문자로 변환

Ctrl + Shift + L : 모든 단축키의 내용을 표시

Ctrl + Shift + B : 현재 커서 라인에 Break point 설정

 

Ctrl + F6 : 창간 전환, UltraEdit 나 Editplus 의 Ctrl + Tab 과 같은 기능

Ctrl + Shift + F4 : 열린 파일 모두 닫기

Ctrl + M : 전체화면 토글

Ctrl + Alt + Up(Down) : 한 줄(블럭) 복사

템플릿 수정 → 환경설정/자바/편집기/템플릿


F10 : 메뉴창을 활성화

Ctrl + F8 : 다음 Perspective로 이동

Ctrl + N : 새로운 파일 및 프로젝트 생성

Ctrl + Shift + Down : Java Editor에서 다음 member로 이동

Ctrl + F7 : 다음 View로 이동

Ctrl + Shift + F7 : 이전 View로 이동

Alt + ← : 이전 작업 화면

Alt + → : 다음 작업 화면

F12 : 컴파일 중 에러 등으로 포커스가 다른 곳으로 갔을 때 Editor 로 커서 이동

Ctrl + 1 : 컴파일 에러가 발생한 곳에서 Ctrl + 1을 누를 경우 컴파일 에러에 대한 해결책을 제시

 

Ctrl + Shift + B : 현 커서의 위치에 브레이크 포인터 설정/해제

F11 : 디버깅 시작

F8 : 디버깅 계속

F6 : 한 줄씩 실행(Step Over)

F5 : 한 줄씩 실행하되 함수일 경우 그 함수 내부로 들어감(Step Into)

Ctrl + R : 현재 라인까지 실행(Run to Line)

Ctrl + F11 : 이전에 실행되었던 Run 파일 실행


Server Class


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
32
33
import java.io.*;
import java.net.*;
public class  UnicastServer{
    private ServerSocket serverS;
    public UnicastServer(int port){
        try{
            serverS = new ServerSocket(port);
        }catch(IOException ioe){
            ioe.printStackTrace();
            System.exit(0);
        }
        UnicastServerThread ust=null;
        while(true){
            System.out.println("클라이언트 대기중");
            Socket s=null;
            try{
                s = serverS.accept();
            }catch(IOException ioe){
                ioe.printStackTrace();
            }
            System.out.println("client ip : "+
                s.getInetAddress().getHostAddress());
            
            ust = new UnicastServerThread(s);            
            Thread t = new Thread(ust);
            t.start();            
        }
    }
    public static void main(String[] args){
        new UnicastServer(3000);
    }
}
 

 
ServerThread Class
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.net.*;
import java.io.*;
public class UnicastServerThread implements Runnable{
    private Socket socket;
    private BufferedReader bufferR; 
    private BufferedWriter bufferW;
    private InputStream is;
    private OutputStream os;
    private String message;    
    private BufferedReader file=null;
    public UnicastServerThread(Socket socket){
        this.socket = socket;        
    }
    public void run(){
        boolean isStop = false;        
        try{
            is = socket.getInputStream();
            bufferR = new BufferedReader(
                    new InputStreamReader(is));
            os = socket.getOutputStream();            
            bufferW = new BufferedWriter(
                    new OutputStreamWriter(os));    
        }catch(IOException ioe){
            isStop=true;
        }
        try{    
            while(!isStop){
                            
                    String message = bufferR.readLine();
                    if(message.equals("exit")) isStop = true;
                    System.out.println("received message : "+ message);
                    message += System.getProperty("line.separator");
                    bufferW.write(message);
                    bufferW.flush();    
                    
                    System.out.printf("message : ");
                    file = new BufferedReader(new InputStreamReader(System.in));
                    message = file.readLine();
                    message += System.getProperty("line.separator");
                    bufferW.write(message);
                    bufferW.flush();            
                    message = bufferR.readLine();
                    
            }//while end        
        }catch(IOException ioe){
            System.out.println("클라이언트가 강제로 " +"종료되었습니다.");
            isStop=true;
        }finally{
            try{
                if(bufferR != null) bufferR.close();
                if(bufferW != null) bufferW.close();
                if(socket != null) socket.close();
                if(file !=null) file.close();
            }catch(IOException ioe){
                ioe.printStackTrace();
            }
        }//finally end
    }//run end    
}
 

Client Class
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
import java.net.*;
 
public class UnicastClient {
    private String ip;
    private int port;
    private String message;
    private BufferedReader file = null;
    private BufferedWriter bufferW = null;
    private BufferedReader bufferR = null;
 
    public UnicastClient(String ip, int port) throws IOException {
        this.ip = ip;
        this.port = port;
        boolean isStop = false;
        Socket tcpSocket = getSocket();
        OutputStream os = tcpSocket.getOutputStream();
        InputStream is = tcpSocket.getInputStream();
        bufferW = new BufferedWriter(new OutputStreamWriter(os));
        bufferR = new BufferedReader(new InputStreamReader(is));
        while (!isStop) {
            System.out.print("message : ");
            file = new BufferedReader(new InputStreamReader(System.in));
            message = file.readLine();
            message += System.getProperty("line.separator");
            bufferW.write(message);
            bufferW.flush();
            message = bufferR.readLine();
            
            String message = bufferR.readLine();
            if (message.equals("exit"))
                isStop = true;
            message += System.getProperty("line.separator");
            bufferW.write(message);
            bufferW.flush();
 
            
            if (message.equals("exit")) {
                isStop = true;
                System.out.println("종료되었습니다.");
            } else {
                System.out.println("Received message : " + message);
            }
        }
        tcpSocket.close();
        bufferW.close();
        bufferR.close();
        file.close();
    }
 
    public Socket getSocket() {
        Socket tcpSocket = null;
        try {
            tcpSocket = new Socket(ip, port);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.exit(0);
        }
        return tcpSocket;
    }
 
    public static void main(String[] args) throws IOException {
        new UnicastClient("localhost", 3000);
    }
}
 


Memory class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
public abstract class Memory {
    protected int[] data;
    protected int top;
 
    public Memory() {
        data = new int[10];
        top = 0;
    }
 
    public void push(int num) {
        if (top == data.length) {
            System.out.println("FULL!!");
            return;
        } else {
            data[top++] = num;
        }
    }
 
    public abstract int pop();
 
}
 


Stack class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Stack extends Memory {
    
    @Override
    public int pop() {
         if (top == 0) {
                System.out.println("EMPTY!!!");
                return 0;
            }
            else {
                return data[--top];
            }
    }
}
 


Queue class


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
public class Queue extends Memory {
    protected int front;
 
    public Queue() {
        front = 0;
    }
 
    @Override
    public int pop() {
        if (top == front) {
            System.out.println("EMPTY!!!");
            return 0;
        } 
            return data[(front++)];
        }
 
}
 


// 수정 중에 있습니다. Queue가 front가 배열을 넘으면 입력 불가. 좋은 방법 있으심 이야기 해주셔도 됩니다:)

 

Main class


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num;
        int a;
        
        Memory mem;
    
        Queue que=new Queue();
        Stack sta=new Stack();
        
        
        
        do {
            System.out.println("1.stack" + "\t" + "2.queue" + "\t" + "3.Quit");
            num=sc.nextInt();
            if (num == 1) {
                mem = sta;
            }
            else if(num==2){
                mem=que;
            }
            else if (num == 3) {
                continue;
            }
            else {
               System.out.println("Not num");
               System.out.println("Bye");
                num = 3;
                continue;
            }
     
            System.out.println("1.push""\t""2.pop");
            num=sc.nextInt();
     
            if (num == 1) {
     
                System.out.println("Data input : ");
                a=sc.nextInt();
                mem.push(a);
     
     
            }else if (num == 2) {
                System.out.println(" output Data : " + mem.pop());
     
            }
            else if (num==3){
                System.out.println("Not num " + "\n"+"bye");
                num=3;
                continue;
                
            }
        } while (num != 3);
    }
}
 

 



NAME CLASS


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Name {
 
    private String name;
 
    public Name() {
 
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
}
  


SUBJECT CLASS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
public class Subject {
 
    private int subject;
 
    public int getSubject() {
        return subject;
    }
 
    public void setSubject(int subject) {
        this.subject = subject;
    }
 
}
 

Score CLASS

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
public class Score {
 
    private Name name;
    private Subject kor;
    private Subject eng;
    private Subject mat;
    private int total;
    private float avg;
 
    public Score() {
        name = new Name();
        kor = new Subject();
        eng = new Subject();
        mat = new Subject();
        total = 0;
        avg = 0;
    }
 
    public void setName(String name) {
        this.name.setName(name);
    }
 
    public String getName() {
        return name.getName();
    }
 
    public void setKor(int kor) {
        this.kor.setSubject(kor);
    }
 
    public int getKor() {
        return kor.getSubject();
    }
 
    public void setEng(int eng) {
        this.eng.setSubject(eng);
    }
 
    public int getEng() {
        return eng.getSubject();
    }
 
    public void setMat(int mat) {
        this.mat.setSubject(mat);
    }
 
    public int getMat() {
        return mat.getSubject();
    }
 
    public void setTotal() {
        this.total = kor.getSubject() + eng.getSubject() + mat.getSubject();
    }
 
    public int getTotal() {
        return total;
    }
 
    public void setAvg() {
        this.avg = total / 3;
    }
 
    public float getAvg() {
        return avg;
    }
 
}
 


MAIN CLASS


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
 
public class Student {
 
    private Score[] sco;
 
    public Student(int num) {
        sco = new Score[num];
        for (int i = 0; i < sco.length; i++)
            sco[i] = new Score();
    }
 
    public void setInput() {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < sco.length; i++) {
            sco[i] = new Score();
            System.out.print("Name Input: ");
            sco[i].setName(sc.next());
            System.out.print("Kor Input: ");
            sco[i].setKor(sc.nextInt());
            System.out.print("Eng Input: ");
            sco[i].setEng(sc.nextInt());
            System.out.print("Mat Input: ");
            sco[i].setMat(sc.nextInt());
            sco[i].setTotal();
            sco[i].setAvg();
        }
 
    }
 
    public void output() {
        for (int i = 0; i < sco.length; i++) {
            System.out.println(sco[i].getName() + "\t" + sco[i].getKor() + "\t" + sco[i].getEng() + "\t"
                    + sco[i].getMat() + "\t" + sco[i].getTotal() + "\t" + sco[i].getAvg());
        }
    }
 
    public static void main(String[] ar) {
        int num;
        Scanner sc = new Scanner(System.in);
 
        System.out.print("Member Input: ");
        num = sc.nextInt();
        Student stu = new Student(num);
 
        stu.setInput();
        System.out.println("Name"+"\t"+"Kor"+"\t"+"Eng"+"\t"+"Mat"+"\t"+"Total"+"\t"+"Avg");
        stu.output();
 
    }
 
}
 
 


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
32
33
34
35
36
import java.util.Scanner;
 
public class StudentScore {
    public static void main(String[] ar) {
        Scanner sc = new Scanner(System.in);
 
        String num;
        System.out.print("How many people? ");
        num = sc.next();
        String[] name = new String[Integer.valueOf(num)];
        String[][] score = new String[Integer.valueOf(num)][4];
        String[] avg = new String[Integer.valueOf(num)];
 
        
        for (int i = 0; i < score.length; i++) {
            System.out.print("Name Input: ");
            name[i] = sc.next();
            for (int j = 0; j < score[i].length-1; j++) {
                System.out.print("Score Input: ");
                score[i][j] = sc.next();
                
            }
            score[i][3]=Integer.toString(Integer.valueOf(score[i][0])+Integer.valueOf(score[i][1])+Integer.valueOf(score[i][2]));
            avg[i]= Float.toString(Float.parseFloat(score[i][3])/3);
        }
        System.out.println("Name""\t"+"Kor"+"\t"+"Eng"+"\t"+"Math"+"\t"+"Total"+"\t"+"Avg");
        for (int i = 0; i < score.length; i++) {
            System.out.print(name[i] + "\t");
            for (int j = 0; j < score[i].length; j++) {
                System.out.print(score[i][j] + "\t");
            }
            System.out.println(avg[i]);
        }
    }
}
 


+ Recent posts