레이블이 자바강의인 게시물을 표시합니다. 모든 게시물 표시
레이블이 자바강의인 게시물을 표시합니다. 모든 게시물 표시

2013년 10월 31일 목요일

[자바강좌]JAVA Method Overring(자바 메소드 재정의) 상위 클래스의 인스턴스 메소드를 새로 구현함으로써 ...

 [자바강좌]JAVA Method Overring(자바 메소드 재정의)
 
상위 클래스의 인스턴스 메소드를 새로 구현함으로써 외부에 다른 반응양식을 보일 수 있다
메쏘드 재정의를 하기위해서 메쏘드 이름, 매개변수개수, 타입, 리턴형이 같아야 한다.
객체의 타입과 관계없이 참조값(reference)이 가리키는 실제 객체 자료형의 메쏘드가 선택되어 런타입중 실행
실제 자료형에 메쏘드가 없으면 가장 가까운 상위 클래스의 메쏘드가 실행된다.
상위 클래스보다 접근 제어를 강화할 수 없다
상위 클래스에 public으로 되어있는 함수를 하위 클래스에서 private으로 할 수 없다.
 

[예제]
 
package onj;
class A1 {
 public void m(int i) {
  System.out.println("A1의  m(int)");
 }
 public void m(double f) {
  System.out.println("A1의  m(double)");
 }
}
class B1 extends A1 {
 //A1의 m(int i) 재정의
 public void m(int i) {
  System.out.println("B1의 m(int)");
 }
 //method overloading(매개변수의 개수를 변화줌)
 public void m() {
  System.out.println("B1의 m()");
 }
}
class Override {
 public static void main(String[] args) {
  A1 a = new A1();
  a.m(1); // A1의 m(int)가 호출됨
  B1 b = new B1();
  b.m(1);     // B1의 m(int)가 호출됨
  b.m(1.0);   // B1에는 m(double d)이  없다, 상위클래스 A1의 b.m(double d) 호출
  
  A1 c = new B1();
  c.m(1);   // 마지막으로 재정의된 메쏘드 B의 m(int)가 호출됨
  //c.m(); // 컴파일오류: 자료형 A1에는 메쏘드 m()이 정의되어 있지 않음.
 
 }
}
 
[결과]
 
A1의  m(int)
B1의 m(int)
A1의  m(double)
B1의 m(int)

2013년 10월 29일 화요일

Java Colection,AbstractCollection 인터페이스 1. Collection 객체의 모임이며

Java Colection,AbstractCollection 인터페이스

1. Collection
 
객체의 모임이며, 직접 구현 안하며 Set이나 List중 하나를 구현한다.
크기 정보 추출
int size()
boolean isEmpty()
검색, 비교, 복사
boolean contains(Object o)
boolean containsAll(Collection c)
Iterator iterator()
Object[] toArray() : Collection 내의 객체의 배열을 반환
Object[] toArray(Object[] a)
객체 추가, 제거
boolean add(Object o)
boolean addAll(Collection c)
boolean remove(Object o)
boolean removeAll(Collection c) : c를 모두 제거
boolean retainAll(Collection c) : c를 제외한 객체 제거
clear()
특징
구성원 객체의 수가 변경되었으면 true를 반환
허용하지 않는 메쏘드는 UnsupportedOperationException 발생
add, addAll 메쏘드는 ClassCastException 발생 가능
null을 허용하지 않을 경우 NullPointerException 발생 가능
조건에 맞지 않을 경우 IllegalArgumentException 발생 가능
 
2. AbstractCollection
 
Collection 인터페이스 구현한 추상클래스
중복 허용
실제 저장 구조와 관계된 함수는 미구현
변경 불가능한 하위 Collection 구현 시 iterator(), size() 만 구현
변경 가능한 하위 Collection 구현 시
add() 구현하지 않으면  UnsupporedOperationException 발생
String toString()은 각 구성원 객체의 toString() 값을 출력한다.
 
 
[예제]

package onj;
 
//AbstractCollection을 상속한 사용자 정의 컬렉션
import java.util.*;
public class MyCollection extends AbstractCollection {
 private int size = 0;
 private Object[] arr = new Object[10];
 public int size() {
  return size;
 }
 public boolean add(Object o) {
  arr[size++] = o;
  return true;
 }
 public Iterator iterator() {
  return new Iterator() {
   private int current = -1;
   public boolean hasNext() {
    return current + 1 < size;
   }
   public Object next() {
    current++;
    if (size <= current)
     throw new NoSuchElementException();
    return arr[current];
   }
   public void remove() {
    if (current == -1 || size <= current) throw new NoSuchElementException();
    for (int i = current + 1; i < size; i++)
     arr[i - 1] = arr[i];
    current--;
    size--;
   }
  };
 }
 public static void main(String[] args) {
  MyCollection col = new MyCollection();
  col.add("OnJ1");
  col.add("OnJ2");
  System.out.println("size(): " + col.size());
  System.out.println("contains(): " + col.contains("second"));
  System.out.println("toString(): " + col);
  System.out.print("iterator: ");
  // 반복자
  Iterator iter = col.iterator();
  while (iter.hasNext()) {
   System.out.print(iter.next() + ", ");
  }
  System.out.println();
  System.out.print("toArray(): ");
  Object[] array = col.toArray();
  for (int i = 0; i < array.length; i++)
   System.out.print(array[i] + ", ");
  System.out.println();
  col.remove("first");
  System.out.println("remove(): " + col);
  MyCollection col2 = new MyCollection();
  col2.add("OnJ3");
  col2.add("OnJ4");
  System.out.println("containsAll(): " + col.containsAll(col2));
  col.addAll(col2);
  System.out.println("addAll(): " + col);
  col.removeAll(col2);
  System.out.println("removeAll(): " + col);
  col.clear();
  System.out.println("col.size() : " + col.size());
  System.out.println("clear(): " + col);
 }
}
 

[결과]
 
size(): 2
contains(): false
toString(): [OnJ1, OnJ2]
iterator: OnJ1, OnJ2,
toArray(): OnJ1, OnJ2,
remove(): [OnJ1, OnJ2]
containsAll(): false
addAll(): [OnJ1, OnJ2, OnJ3, OnJ4]
removeAll(): [OnJ1, OnJ2]
col.size() : 0
clear(): []

2013년 10월 19일 토요일

JAVA JNDI를 이용한 DNS 서비스 구현 JNDI란 자바로 만들어진 프로그램이 Naming 및 Directory 서비스에 접근할 수 있도록 제공되는 API 입니다.

JAVA JNDI를 이용한 DNS 서비스 구현

 JNDI란 자바로 만들어진 프로그램이 Naming 및 Directory 서비스에 접근할 수 있도록 제공되는 API 입니다.
 
즉 자바 응용 프로그램이 어느 위치에 있든지 필요한 자바 객체들을 검색할 수 있는 것입니다. EJB 환경에서는 JNDI를 이용해 EJB Home 객체를 얻어낸 후 이를 이용해 Java Beans 객체를 생성하거나 접근하게 됩니다.
 
JNDI는 DNS(Domain Name System), COS(Common Object Services) 등의 네이밍 서비스 표준과 LDAP(Lightweight Directory Access Protocol), NDS(NetWare Directory Service), NIS(Netware Information System) 등 API를 제공 합니다.
 
참고로 JDK1.4 부터는 JNDI 서비스 프로바이더에 DNS Service Provoder를 제공하여 DNS 서비스를 통해 네이밍 서비스를 받을 수 있도록 지원 했는데 아래는 그 예제 입니다.
 
아래예제는 www.onjprogramming.co.kr에 대한 DNS 서비스를 받아 오는 예제 입니다.
 

import java.util.Hashtable;
import javax.naming.directory.*;
import javax.naming.NamingEnumeration;
public class JNDIExample {
 public static void main(String[] args) {
  Hashtable h = new Hashtable();
  h.put("java.naming.factory.initial","com.sun.jndi.dns.DnsContextFactory");
  h.put("java.naming.provider.url","dns://ns.dacom.co.kr");
  
  try {
   //DirContext 초기화
   DirContext context = new InitialDirContext(h);
   
   //DNS질의 결과를 받아 오자...
   Attributes attribute = context.getAttributes("www.onjprogramming.co.kr");
   
   //질의 결과 출력
   NamingEnumeration ne = attribute.getAll();
   System.out.println("www.onjprogramming.co.kr --> ");
   while(ne.hasMoreElements()) {
    System.out.println(ne.next());
   }
  }
  catch(Exception e) {
   e.printStackTrace();
  }
  
 }
}
 
[결과]
java.sun.com --> 
A: 209.249.116.141

2013년 8월 2일 금요일

Java Template Method 패턴 예제 , java design pattern

Java Template Method 패턴 예제   


Template Method Pattern
 

오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷 실무전문 강의) 
www.onjprogramming.co.kr

상위클래스 쪽에 템플릿이 되는 메소드가 정의되어 있고 , 그 메소드의 정의내에는 추상메소드가 사용되너 상위클래스만 보면 추상메소드가 어떤식으로 호출되는지 알수있지만 최종적으로 어떤 처리를 하는지 모른다.
 하위클래스에서 어떠한 처리를 하는지에 관계없이 큰 틀은 상위클래스가 결정한데로 처리된다. 실제로 어떤일을 하는지는 하위클래스의 구현된 내용을 봐야 한다.
 상위클래스의 템플릿 메소드에 알고리즘이 기술되어 있으므로 하위클래스에서는 알고리즘을 일일이 기술할 필요가 없다. (개개의 하위클래스에 일일이 알고리즘을 기술한다면 수정사항이 발생되면 일일이 개별 하위클래스를 수정해야 한다.)


// AbstractDisplay.java
public abstract class AbstractDisplay { 
    public abstract void open();       
    public abstract void print();       
    public abstract void close();       
    public final void display() {     
        open();                           
        for (int i = 0; i < 5; i++) {     
            print();                   
        }
        close();                           
    }
}

// GreetingDisplay.java
public class GreetingDisplay extends AbstractDisplay { 
    private String s;                               
    public GreetingDisplay(String s) {    this.s =s;              }
    public void open() {                         
        System.out.println("hello " + s);                 
    }
    public void print() {                           
        System.out.println("your name is " + s);                     
    }
    public void close() {                         
        System.out.println("bye~ " + s);               
    }
}
// StringDisplay.java
public class StringDisplay extends AbstractDisplay {   
    private String string;                             
    private int width;                                 
    public StringDisplay(String string) {             
        this.string = string;                         
        this.width = string.getBytes().length;         
    }
    public void open() {    printLine();    }
    public void print() {  System.out.println("|" + string + "|");    }
    public void close() {  printLine();      }
    private void printLine() {                   
        System.out.print("+");                   
        for (int i = 0; i < width; i++) {  System.out.print("-");      }
        System.out.println("+");               
    }
}
// Main.java
public class Main {
    public static void main(String[] args) {
        AbstractDisplay d1 = new GreetingDisplay("이종철");                 
        AbstractDisplay d2 = new StringDisplay("Hello, world.");   
        AbstractDisplay d3 = new StringDisplay("안녕하세요~");   
        d1.display();                                               
        d2.display();                                               
        d3.display();                                               
    }
}  

2013년 8월 1일 목요일

JAVA Finalize() 메소드 , java destroy

클래스 정의에 포함가능, 객체가 소멸되어 메모리에서 차지하던 공간을 해제하기 직전에 자동으로 호출된다.
 쿨래스 객체가 소멸될때 특별한 작업을 필요로 하는 자원을 사용한느 경우에 용이
  (대부분 이러한 환경은 자바환경에 들어 있지 않으며 자동으로 해제가 되지 않는다. 글꼴이나 그리기등의 그래픽자원, 하드디스크등의 외부파일… 디스크의 파일등을 열면서도 종결이 보장되지 않는다면 객체가 소멸될때 파일을 닫았는지 확인 해야한다.)
 객체가 소멸된 사실을 기록하는것(예를들어 객체의 개수를 세는 count 변수등이 있다면 이 메소드에 변수의 값을 –하면 될것이다…) 

자바의 반복문

/* 인수로 숫자를 입력받아 그 수까지의 팩토리얼을 계산하는 프로그램 */
public class FactorialFor {
public static void main(String[] args) {
long fact=1;
if (args.length<1) {
System.out.println("Usage : java Factirial Number");
System.exit(1);
}
for(int i=Integer.parseInt(args[0]);i>=1;i--) {
for(int j=1;j<=i;j++) {
fact *= j;
}
System.out.println(i+"! = " + fact);
fact = 1;
}
}
}


/* 인수로 숫자를 입력받아 그 수까지의 팩토리얼을 계산하는 프로그램 */
public class FactorialWhile {
public static void main(String[] args) {
long fact=1;
if (args.length<1) {
System.out.println("Usage : java Factirial Number");
System.exit(1);
}
int i = Integer.parseInt(args[0]); int j=1;
while(i>=1) {
while(j<=i) {
fact *= j; j++;
}
System.out.println(i+"! = " + fact);
fact = 1; i--; j=1;
}
}
}


public class FactorialDoWhile {
public static void main(String[] args) {
long fact=1;
if (args.length<1) {
System.out.println("Usage : java Factirial Number");
System.exit(1);
}
int i = Integer.parseInt(args[0]); int j=1;
do {
do {
fact *= j; j++;
} while(j<=i);
System.out.println(i+"! = " + fact);
fact = 1; i--; j=1;
} while(i>=1);
}
}


/* 소수 찾기 ( 주어진 갯수만큼 ...) */
public class Primes {
public static void main(String[] args) {
//소수 20개를 찾아라. 루프를 어디까지 돌릴지는 모른다. 
int value=20; 
            outerLoop:
        //2부터 계속돌자 ,, 
for(int i=2;;i++) {
    for(int j=2;j<=i-1;j++) {
          if (i%j==0){
              continue outerLoop;
          }
    }
    //소수일 경우만 이리온다.
    System.out.println(i);
    if (--value==0) {
break outerLoop; 
    }
}
}
}

자바 상속(JAVA EXTENDS), 자바실무강좌,오라클실무강좌,OnJ,ORACLEJAVA

상속 개념 이해 바랍니다.


오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷  실무전문 강의) 



상속은 한 클래스를 확장하여 새로운 클래스를 만드는 것을 말한다. 이렇게 새로 만들어지는 클래스를 하위클래스(SubClass)라고 부른다. 그리고 원래의 클래스는 상위클래스(SuperClass)라고 부른다. 하위클래스는 상위클래스에서 정의한 메쏘드와 변수들을 그대로 가지고 있을 수 있다. (물론 이것도 접근변경자를 통해 조절이 가능하다) 여기에 추가로 하위 클래스 자체적으로 정의된 메쏘드와 변수들을 가질 수 있다. 어떤 클래스에 대해서, 상속받는 하위 클래스는 여러 개가 될수 있다. 

이미 만들어놓은 클래스를 기반으로 원하는 기능이 추가된 새로운 클래스를 쉽게 만들어낼 수 있다

자바의 모든 클래스는 상속의 대상이 되는 상위클래스(SuperClass)가 반드시 하나 존재한다
프로그램의 재사용성과 확장성을 높인다.

class Employee {
    String name;    String id;
  //생성자
    public Employee(String name1, String id1) {
        name = name1;    id = id1;
    }
    public void gotoOffice() {
        System.out.println(name+"님 출근하였습니다...");
    }
    public void gotoHome() {
        System.out.println(name+"님 퇴근하였습니다...");
    }
}



Employee Class를 상속한 Manager Class가 있다….
//직원클래스를 상속한 일반관리자 Class
class Manager extends Employee {
    String chargeDept;
    public Manager(String newName,String newID,String newDept) {
        //super는 상위클래스의 생성자를 의미
        super(newName, newID);
        this.chargeDept = newDept;
    }

    public void startJob() {
        System.out.println(this.chargeDept + " " + super.name + "님이 관리업무를 시작합니다...");
    }
}


Employee Class를 상속한 SalesEmployee Class가 있다….
//직원클래스를 상속한 영업팀직원 클래스
class SalesEmployee extends Employee {
    //영업담당지역, 메소드내에서만 변수에 접근이 가능하다.
    private String chargeArea;
    public SalesEmployee(String newName,String newID,String newArea) {
        //super는 상위클래스의 생성자를 의미
        super(newName, newID); 
        this.chargeArea = newArea;
    }
    public void startJob() {
        System.out.println(super.name + "님이 “ + this.chargeArea + “ 지역으로 영업업무를 나갑니다...");   
    }
}



상속을 위해서는 extends keyword를 사용한다.  (class a extends b  b로 부터 상속을 받음)
extends키워드를 이용해 클래스를 상속받으면 상속받은 클래스는 상위클래스의 필드와 메소드를 상속받는다.
      (예) 앞의 Manager Class instance화 했다면
        Manager m = new Manager(“홍길동”, “12345”,”관리부”);
        String id = m.id;
        m.gotoOffice();
      등과 같이 사용이 가능하다… 물론 m.startJob() 처럼 자신의 Method를 사용이 가능하다.
하위클래스는 객체를 생성할 때 상위클래스의 객체를 먼저 생성해야 한다. 하위클래스는 크게 상위클래스 객체부와 자기 자신의 객체부로 나눌 수 있다. 즉 new 키워드를 사용하여 하위클래스를 생성하면 상위클래스의 부분과 하위클래스 고유의 부분이 나뉘어 생성된다는 것이다. 이때 상위클래스 부분을 super라고 한다. 그리고 상위클래스 객체부를 생성하기 위해 사용하는 것이 바로 상위클래스 생성자 super()이다. 
      (예) 만약 Manager Class에서 super(newName, newID)를 생략하면 다음과 같은 에러가 난다.  생략시에는 default로 super() 이 삽입되는데ㅡ Employee에는 파라미터가 없는 생성자가 선언되지 않았기때문에 ….
      Example.java:22: cannot resolve symbol        symbol  : constructor Employee  ()
        location: class Employee        public Manager(String newName,String newID,String newDept) {


하위클래스에서 상위클래스의 멤버를 호출하고자 할때는 .(점) 연산자를 사용하여 나타낼 수 있다. 
      (예) Manager Class에서 super.name
      public void startJob() {
            System.out.println(this.chargeDept +” “+ super.name + "님이 직원관리 업무 를 시작합니다...");   
    }

       


이제 SaleEmployee(영업부직원)을 상속한(확장한) SalesChief(영업팀장) Class를 만들어보자.
영업팀장 Class는 영업부직원과 같이 id,이름,영업담당 지역을 가지면서 자신만의 속성을 가진다.
      //영업팀직원 클래스를 상속한 영업팀장 클래스
      class SalesChief extends SalesEmployee {
      int salesTarget;  //영업팀 목표 매출액
      public SalesChief(String newName,String newID,String newArea, int newSalesTarget) {
          //super는 상위클래스의 생성자를 의미
          super(newName, newID, newArea); 
          this.salesTarget = newSalesTarget;
      }
      //영업팀장의 업무는 더이상 확장이 안된다는 의미, 상속할수가 없다는 의미
      final public void startJob() {
          System.out.println(super.name + "님이 영업팀 직원을 관리한다...");
          System.out.println(super.name + "님이 관리하는 영업팀의 매출목표는 "+ this.salesTarget + "만원 입니다...");
      }
      }


SalesChief Class의 경우 SalesEmployee의 startJob() 메소드를 재정의(Override) 했다.
메소드의 재정의라고 하는 것은 상속의 관계에 있는 클래스들 사이에서 상위클래스에 있는 메소드를 하위클래스에서 다시 정의하여 사용하는 것을 말한다. 이 경우 하위클래스의 메소드는 상위클래스의 메소드와 이름도, 매개변수 타입도, 그리고 반환형도 같다. 하지만 내부적으로 하는 일은 다르다. 
만약 SalesChief Class의 startJob 메소드에서 다음과 같이 정의한다면,,,
      public void startJob() {
          System.out.println(super.chargeArea); 
          System.out.println(super.name + "님이 영업팀 직원을 관리한다...");
    System.out.println(super.name + "님이 관리하는 영업팀의 매출목표는 "+ this.salesTarget + "만원 입니다...");
      }
      아래와 같은 오류발생…
      Example.java:59: chargeArea has private access in SalesEmployee
      System.out.println(super.chargeArea); 
객체지향 언어에서는 정보의 은닉(캡슐화,Encapsulation) 을 위해서 위와 같은 접근지정을 할 수 있다. 즉 SaleEmployee의 자료중 정보 은닉의 필요가 있는 필드나 메소드는 접근지정자를 사용해 접근을 제한할 수 있는 것이다.
       


현재 작성한 클래스나 클래스의 멤버를 다른 클래스에게 상속시키고자 하지 않을경우엔 final 키워드를 사용한다.예를 들어 한 회사에 영업팀장은 그 만의 고유한 업무를 가지고 영업팀장의 업무를 관리하는 또 다른 개체가 없을 때는 영업팀장을 상속하여 더 확장된 기능을 가진 클래스를 만들 필요가 없을 것이다. 이럴 경우 final 키워드를 사용한다. 
메소드의 경우도 이와 같이 상속을 완전히 금지하는 경우가 있는데 이러한 메소드도 final이라는 키워드와 같이 사용하게 되고 종단 메소드(final method)라고 부른다. 


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


/* Class의 상속에 관한 예제 Example1.*/
//직원 Class
class Employee {
    String name;
    String id;

  //생성자
    public Employee(String name1, String id1) {
        name = name1;
        id = id1;
    }

    public void gotoOffice() {
        System.out.println(name+"님 출근하였습니다...");
    }

    public void gotoHome() {
        System.out.println(name+"님 퇴근하였습니다...");
    }
}


//직원클래스를 상속한 일반관리자 Class
class Manager extends Employee {
    String chargeDept;
    public Manager(String newName,String newID,String newDept) {
        //super는 상위클래스의 생성자를 의미
        super(newName, newID);    this.chargeDept = newDept;
    }
    public void startJob() {
        System.out.println(this.chargeDept + " " + super.name + "님이 일을 시작합니다...");
    }
}
//직원클래스를 상속한 영업팀직원 클래스
class SalesEmployee extends Employee {
    //영업담당지역, 메소드내에서만 변수에 접근이 가능하다.
    private String chargeArea;
    public SalesEmployee(String newName,String newID,String newArea) {
        //super는 상위클래스의 생성자를 의미
        super(newName, newID);      this.chargeArea = newArea;
    }
    public void startJob() {
        System.out.println(super.name + "님이 " + this.chargeArea + " 지역으로 영업업무를 나갑니다...");
    }
}


//영업팀직원 클래스를 상속한 영업팀장 클래스
class SalesChief extends SalesEmployee {
      int salesTarget;  //영업팀 목표 매출액
      public SalesChief(String newName,String newID,String newArea, int newSalesTarget) {
              super(newName, newID, newArea);  this.salesTarget = newSalesTarget;
      }
      public void startJob() {
          System.out.println(super.name + "님이 영업팀 직원을 관리한다...");
          System.out.println(super.name + "님이 관리하는 영업팀의 매출목표는 "+ this.salesTarget + "만원 입니다...");
      }
}
//Main Class
class Example {
    public static void main(String args[]) {
        Manager m = new Manager("이종철","12345","솔루션개발");
        m.gotoOffice();        m.startJob();        m.gotoHome();
        SalesEmployee se = new SalesEmployee("차두리","23456","서울");
        se.gotoOffice();        se.startJob();        se.gotoHome();
        SalesChief sc = new SalesChief("홍길동","34567","전국",9000);
        sc.gotoOffice();        sc.startJob();        sc.gotoHome();
    }
}


2013년 7월 30일 화요일

[오라클강의,자바강의,오라클자바교육,오라클교육,자바교육,자바오라클]Oracle Explicitly Named Indexes(9i이상)

oracle pk index
오라클 9i이상 에서 인덱스는 Primary Key Unique Key와는 별도로 CREATE TABLE
USING INDEX구 안에 CREATE INDEX 문법을 이용해서 정의하는 것이 가능해 졌습니다.


오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷  실무전문 강의)



아마도 대부분의 사용자들은 다음과 같은 방식을 알고 계실텐데

예제를 보시면서 어떤 것이 바뀌었는지 확인해 보도록 하죠.

SQL> create table test (
  2  c1 varchar2(4) not null,
3  c2 number(10)  not null,
4  constrint pk_test primary key(c1) using index
  4  );

테이블이 생성되었습니다.


위의 create table문은 pk_test라는 이름을 가지는 primary key 제약 조건을 만들며 아울러 pk_test라는 이름을 가진 인덱스를 만듭니다. 이 두가지는 user_ind_colums 뷰와 user_constraints 뷰에서 table_name = TEST라는 조건을 주시면 확인이 가능합니다.

그러나 9i이후에서는 인덱스에 대해 명시적으로 이름을 주는 것이 가능해 졌는데

우선 아래의 예제를 참고 하도록 하죠

SQL> create table test (
  2  c1 varchar2(4) not null,
  3  c2 number(7),
  4  constraint pk_test primary key(c1)
  5  using index
  6      (create index idx_test_c1 on test(c1))
  7  );

테이블이 생성되었습니다.

이 경우는 테이블을 만들면서 primary key를 만드는데 (원래는 default pk를 만들게 되면 그 컬럼으로 유니크 인덱스를 만듭니다.) 인덱스의 이름은 primary key 이름과 다르게 주기 위해 using index 구안에 create index문을 이용해서 인덱스를 생성했습니다.

--------------------------------------------------------------------
아래의 SQL문중 하나를 이용해 인덱스는 놔두고 PK만 삭제할 수 있습니다.
--------------------------------------------------------------------

SQL> alter table test drop primary key keep index;

테이블이 변경되었습니다.

또는

SQL> alter table test drop constraint pk_test;

테이블이 변경되었습니다.

[출처]오라클자바커뮤니티