JAVA API - JAVA REFERENCE

개발 및 관리/Java 2013. 1. 19. 00:39 posted by HighLighter
반응형

JAVA API를 찾아 보는 방법에는 2가지가 있다.

 

1. 책을 뒤져본다.

1) JAVA IN A NUTSHELL

http://kangcom.com/sub/view.asp?sku=200505060002&mcd=571

 

2) Java 7: The Complete Reference, 8th Edition

http://kangcom.com/sub/view.asp?sku=2008F0025832&mcd=571

 

 

2. HTML API 문서를 활용한다. (Java 7 Standard Edition Documentation)

http://www.oracle.com/technetwork/java/javase/documentation/index.html

 

반응형
반응형

 

 

 

public ArrayList<String> placeDotCom(int comSize) {
ArrayList <String> alphaCells = new ArrayList<String>();

private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();

ArrayList<String> newLocation = helper.placeDotCom(3);

 

위와 같이 빨간색 부분 때문에 Error가 발생했다.

 

 

DotComBust.java
다운로드

 

 

cf. http://smbw.tistory.com/

    http://blog.naver.com/han1000jae?Redirect=Log&logNo=80115100888

    http://blog.naver.com/shreds?Redirect=Log&logNo=89749439

반응형
반응형

 

import java.io.*;

 

public class SimpleDotComTestDrive {
 
 public static void main(String[] args) {
  
    int numOfGuesses = 0;
    GameHelper helper = new GameHelper();
   
    SimpleDotCom theDotCom = new SimpleDotCom();
    int randomNum = (int)(Math.random()*5);
   
    int[] locations = {randomNum,randomNum+1,randomNum+2};
    theDotCom.setLocationCells(locations);
    boolean isAlive = true;
   
    while(isAlive == true) {
     
      String guess = helper.getUserInput("enter a number");     
      String result = theDotCom.checkYourself(guess);
      numOfGuesses++;
     
      if(result.equals("kill")) {
        isAlive = false;
        System.out.println(numOfGuesses + " guesses");
    } // if문 끝
 } // while문 끝
 } // main문 끝
} // class문 끝

 

 

class SimpleDotCom {
 
 int[] locationCells;
 int numOfHits = 0;

 public void setLocationCells(int[] locs) {
  locationCells = locs;
 }

 public String checkYourself(String stringGuess) {
  int guess = Integer.parseInt(stringGuess);
  String result = "miss";
  for(int i=0; i < locationCells.length; i++) {
    if(guess == locationCells[i]) {
   result = "hit";
   numOfHits++;
   break;
    }
 }

 if(numOfHits == locationCells.length) {
  result="kill";
 }

 System.out.println(result);
  return result;
 }
}


class GameHelper {
  public String getUserInput(String prompt) {
    String inputLine = null;
    System.out.print(prompt + " ");
    try {
      BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
      inputLine = is.readLine();
      if(inputLine.length() == 0) return  null;
      } catch (IOException e) {
        System.out.println("IOException: " + e);
      }
        return inputLine;
    }
}

 

//String을 int로 바꿀 대는 Integer.parseInt()를 쓴다.
//String Str = "1000";
//int nmbr = Integer.parseInt(Str);

//p.141
//Math.random은 double형의 0이상 1미만의 숫자를 리턴한다.

반응형

자바 추천 서적

개발 및 관리/Java 2013. 1. 16. 23:33 posted by HighLighter
반응형

 

자바 추천 도서를 아래와 같이 정리해 보았다.

오늘 생각해보니, DB도 혼자 많이 했듯이 자바도 혼자 해볼만 할 것 같다.

어차피 자바는 학생 시절에 조금은 다루어 보지 않았는가???

몇 권의 책만으로도 충분하다. Oracle Database도 그렇게 하지 않았는가???

인생은 원래 그런거다. 나는 Guru를 추구하는 자인가, 아닌가...

어차피 Java를 해보아야 한다. DBA 겸 개발자이면 메리트가 클 것이다. 

 

제일 유명한 자바책: JAVA의 정석, 소설같은 자바, 난 정말 자바를 공부한 적이 없다구요, Head First Java
cf. 열혈강의 자바 프로그래밍

 

-------------------------------------------------------------------------------------------------------

자바 7 실무 바이블
 http://kangcom.com/sub/view.asp?sku=201210160007&mcd=571

소설같은 자바 4판
 http://kangcom.com/sub/view.asp?sku=201010010005&mcd=571

이펙티브 자바 제2판
 http://kangcom.com/sub/view.asp?sku=200904220002&mcd=571

쉽게 따라하는 자바 웹 개발
 http://kangcom.com/sub/view.asp?sku=201211300002&mcd=571

열혈강의 자바 디자인 패턴
 http://kangcom.com/sub/view.asp?sku=201109300008&mcd=571

Head First jQuery: 자바스크립트를 몰라도 배울 수 있는 제이쿼리
 http://kangcom.com/sub/view.asp?sku=201205090005&mcd=571


-------------------------------------------------------------------------------------------------------


Java Generics and Collections

http://shop.oreilly.com/product/9780596527754.do


agile Java

http://langrsoft.com/index.php/agile-java


Java concurrency in practice

http://books.google.co.kr/books/about/Java_concurrency_in_practice.html?id=6LpQAAAAMAAJ&redir_esc=y


effective java

http://java.sun.com/docs/books/effective/toc.html


head first design patterns

http://book.naver.com/bookdb/book_detail.nhn?bid=1882446

http://vincehuston.org/dp/

 

 

 

반응형
반응형

http://www.ietf.org
The Internet Engineering Task Force
인터넷의 원활한 사용을 위한 인터넷 표준규격을 개발하고 있는 미국 IAB(Internet Architecture Board)의 조사위원회

반응형
반응형
 


//action event 처리하기

import java.awt.*;
import java.awt.event.*;

public class Action implements ActionListener{
 Frame f;
 Button b;
 public static void main(String args[]){
  Action a = new Action();
 }
 public Action(){
  f = new Frame();
  b = new Button("QUIT");
 
  f.add(b);
  b.addActionListener(this);
  f.setSize(200,200);
  f.setVisible(true);
 }
 public void actionPerformed(ActionEvent e){
  b.setBackground(Color.red);
  b.setLabel(""QUIT");
 }
}

//addActionListener()를 통해 해당 버튼의 이벤트를 Frame에 등록한다.
//해당 버튼이 클릭이 일어나면 public vodi actionPerformed(ActionEvent e)에 의해 상태가 변하고, 해당하는 코드가 실행된다.


//앞의 코드는 버튼이 었고 이번에는 윈도우에 대한 이벤트를 다루어 보자

import java.awt.*;
import java.awt.event.*;

public class Action implements WindowListener{
 Frame f;
 public static void main(String args[]){
  Action a = new Action();
 }
 public Action(){
  f = new Frame();
  f.addWindowListener(this);
  f.setSize(200,200);
  f.setVisible(true);
 }
 public void windowClosing(WindowEvent e){
  System.exit(0);
 }
 public void windowActivated(WindowEvent e){}
 public void windowClosed(WindowEvent e){}
 public void windowOpened(WindowEvent e){}
 public void windowDeactivated(WindowEvent e){}
 public void windowDeiconified(WindowEvent e){}
 public void windowIconified(WindowEvent e){}
}

addWindowListener()로 이벤트 코드를 등록한 뒤 메소드 구현한다.
 그러나, 리스너 인터페이스들을 implements 했을 때는 필요없는 메소들도 모두 구현해야 하는 불편함이 있기 때문에, 이를 추상 메소드로 만든 클래스인 어댑터클래스를 사용할 수 있다.


<Listener interface>

ComponentListener : ComponentAdapter (나머지도 모두 이름 뒤에 Adaptor가 붙는다)

ContainerListener

FocusListener

MouseListener

MouseMotionListener

WindowListener

KeyListener

 


다음은 어댑터 클래스 사용의 예제이다.

import java.awt.*;
import java.awt.event.*;

public class Action extends WindowAdapter{
 Frame f;
 public static void main(String args[]){
  Action a = new Action();
 }
 public Action){
  f = new Frame();
  f.addWindowListener(this);
  f.setSize(200,200);
  f.setVisible(true);
 }
 public void windowClosing(WindowEvent e){
  System.exit(0);
 }
}

 

반응형
반응형

자바로 GUI를 윈도우 기반으로 했을 때, 버튼을 만들고 마우스로 클릭했을 때,
해당 Frame을 닫을 수 있게 하는 코드이다.

import java.awt.*;
public class JPlayer extends Frame implements ActionListener {

  private Button quit;
  quit = new Button("Quit");
  quit.addActionListener(this);

  JPlayer(){}
 
 public void actionPerformed(ActionEvent e) {
  String arg = e.getActionCommand();

  if ("QUIT".equals(arg)) {
   System.out.println("QUIT");
   dispose();
  }
 }
 public static void main(String arg[])
{
 JPlayer j = new JPlayer();
}
}
 

반응형
반응형

코드포멧: 코드의 띄어쓰기, 행, 열 정렬 자동 : Ctrl+Shift+F
파일찾기 : Ctrl + Shift + R
소스내용찾기 : Ctrl + H
디버깅 : Ctrl + F11
브레이크 포인트 : Ctrl + Shift + B

블록을 쓰운 후 'Ctrl+/': 해당 블록에 대한 주석 처리
코드 작성 중 변수, 메소드 찾기:  Ctrl+해당 변수, 메소드 클릭하면 선언한 곳으로 이동Ctrl + . : 이동

Ctrl + e : 한줄지움

Ctrl + w : 메뉴보여줌

Ctrl + space : 클래스등 코드 도움

Ctrl + , : 찾기나, TASK항목 이동

Ctrl + F6 : Editor 선택

Ctrl + F7 : View 선택

Ctrl + F8 : Perspectieve 선택

Ctrl + F11 : 디버깅

Ctrl + 1 : QuickFix 실행

Ctrl + Shift + b : 브레이크 포인트

Ctrl + Shift + e : 현재 캐럿에서 끝까지 삭제

Ctrl + Shift + f : 코드 포맷팅

Ctrl + Shift + m : 자동 임포트

Ctrl + Shift + o : 임포트 자동 정리

Ctrl + Shift + space : 입력 파

이클립스_단축키.doc
0.06MB

라미터 정보 보여줌

반응형
반응형

자바에서 문자와 숫자의 변환은 어떻게 이루어 지나요?

문자에서 숫자로 변환은 어떻게 하나요?

1. int A = Integer.parseInt("1000");

2. String s = "1000";

    int x = Integer.parInt(s);

 

3. double d = Double.parseDouble("100.4");


숫자에서 문자로 변환은 어떻게 하나요?
1. String str = Integer.toString(1000));

2. double d = 10.5;

    String  doubleStr = "" + d;

//String에 어떤 것을 붙이든 지 그 값은 String으로 변환됩니다.

 

3. double d = 10.5;

   String doubleStr  = Double.toString(d);

   

두 개를 적절히 잘 사용하면 매우 유용합니다. ^^

 

cf. Boolean

    Character

    Byte

    Short

    Integer

    Long

    Float

    Double

 

package java_lang;

public class StringEx7 {
 public static void main(String[] args) {
  int value = 100;
  String strValue = String.valueOf(value); //int를 String으로 변환한다.
  
  int value2 = 100;
  String strValue2 = value2 + ""; //int를 String으로 변환하는 또 다른 방법
  
  System.out.println(strValue);
  System.out.println(strValue2);
 }

}

반응형

자바, 문자열 문자열 나누기

개발 및 관리/Java 2008. 4. 1. 21:57 posted by HighLighter
반응형

제가 몰라서 참 고생한 적이 있는 정보입니다. 참 유용한 정보인 것 같습니다.

하나, StringTokenizer를 이용한 문자열 나누기

public void token(){

  String str = "ABC|DEF|GHI|JKL";
  StringTokenizer tokens = new StringTokenizer(str,"|");
 
  for(int i = 1;tokens.hasMoreTokens(); i++)
  {
   System.out.println("문자열 " + i + ":" + tokens.nextToken());
  }

 }

둘, split을 이용한 문자열 나누기

public void token(){

  String str1 = "ABC|DEF|GHI|JKL";
  String[] str2 = str1.split("|");
 
  for(int i = 0 ;i < str2.length : i++)
  {
   System.out.println("문자열 " + i + ":" + str2[i]);
  }
 }

반응형