🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #19046

����import

#19046
From: ����
Date: Mon, 12 Jan 2004 06:02
102 lines
6701 bytes
����import

��һ������
import��c�����е�include�Ƿ�����; 
������ڳ���ͷ����������� 
import aLibrary.*; 
������ȥ���������aLibrary.*;�������·���� 
�������������һ������: 
public class Prey{ 
        //private implentation 
        public Prey(int whereX,int whereY,int leastX,int leastY,int rangeX, 

                    int rangeY) 
        public void move() 
        public int getX() 
        public int getY() 
        public void setRoam(int distance) 
        public void print() 
  } 
 
������һ������Test.java��ʹ��Prey��: 
import Prey; 
public  class Test{ 
        private Prey rabbit; 
        public Test(){ 
        //create and manipulate rabbit object 
        } 
        public static void main(string[] args) 
        { 
         Test prog=new Test(); 
        } 
} 
��Ӧ�ð�Prey�ŵ�����. 

��������򵥵Ľ���취
��Prey.java����Prey.class�ŵ�Test�ĵ�ǰĿ¼�£�����֤ϵͳ��classpath��������ֵ
����
classpath��.;
����Ϳ���ֱ����Test.java��ֱ��ʹ��Prey�࣬���Ҳ���ʹ��import�ؼ��֡�

�����������θ��import���ͻ���������classpath����ֵһ�����ҵ�������Ҫ����


import�ؼ��ֵĹ���������include����������̺�include��һ��

���ڳ�ѧ�ߣ���ʦ��Ҫ�����ǡ���
��1�����Ұ�import����include��
��2�����Ұ�����java�ļ��ŵ�ͬһ��Ŀ¼�£�
��3���ڳ��������õ���ϵͳ�ࣨ�Լ�д���ࣩ����ʹ��import��ֱ��ʹ�ü��ɣ�������Ϊ
�����������Զ��ҵ���
��ʦ˵����ѧ��package��һ�ж�ӭ�ж���ˡ�

include���ø��Ʒ�����ָ���ļ���ͷ�ļ�����Դ�ļ��Կɣ�������ԭԭ�������Ƶ���ǰ��
���С���ʵ���ǽ������ı��ļ��ϲ�Ϊһ���ļ�����

�����һ���Ϊ��Ԥ���?��
import��ִ���ļ��ϲ����ܣ���ֻ�����ҵ���ǰ����ʹ�õ����*.class�ļ�����*.java��
����

���Ծ�һ������������import�Ĵ��¹�����̡�
�����ҵĻ���ϵͳ����������classpathֵΪ��
classpath��.;c:\jdk\lib\tools.jar
������һ��javaԴ�ļ���ʹ����������䣺
import java.io.BufferedInputStream;
����������javac.exe��������̣�������Ӧ�����¡���
��1������classpathֵ��
��2�������ڡ�.��Ŀ¼��Ѱ��java\io\BufferdInputStream.class����java\io\BufferdI
nputStream.java�ļ�����.��Ŀ¼��?ǰ���Jav

aԴ�ļ����ڵ�Ŀ¼�����ҵ��������ҹ�̣��������
��3���ڡ�c:\jdk\lib\tools.jar���ļ��м�����Ѱjava\io\BufferdInputStream.class��
��java\io\BufferdInputStream.java��
��4�����ҵ��������ҹ�̣�������׳��쳣��������classpath�н�������������Ŀ¼
����������Ϊ��Ѱ����BufferedInputStream�࣬����

Ϊ��ǰϵͳ������BufferedInput�ࡣ������û����ô���ܣ������Զ�ȥ���Ŀ¼���ҡ�


������ڳ�������ʹ���Լ�д���ࣨ����ΪExample�ࣩ����������������㲻��ʹ��pac
kage��䣬��ô�����ַ�������
��1�������޸�classpath�ķ���
�ҵ�Example.class������Example.class���ļ������临�Ƶ���ǰ�����Ŀ¼�£������
���ڲ��ҡ�.��Ŀ¼��ʱ��Ϳ����ҵ�������ˡ�
��Ҫ˵�����ǣ����ڳ����ﲻ��Ҫдimport���
��2����Ҫ�޸�classpath�ķ���
�ҽ�����Ŀ¼D:\programming\java\mylib����Example.class������Example.java���ļ�
����ڸ�Ŀ¼�¡�Ȼ���classpath�޸�Ϊ����ֵ����
classpath��.;c:\jdk\lib\tools.jar;d:\programming\java\mylib
�����ҾͿ�������һ��UseExample.java�ļ���ֱ��ʹ��Example���ˣ�������Ȼ����ʹ��
import�ؼ��֡�������������d:\programming\java\m

ylibĿ¼�ҵ�Example.java����Example.class�ļ���
�Ҷ�classpath�������޸Ľ����������Example���·��������ڸ��߱���������������
������Ҫ�Ķ�����

������밴�չ���Ϊ�Լ�д�����ɸ�����飬����ڲ�ͬĿ¼���ô����Ҫʹ��packag
e�ˡ��α��������ӣ�����Ͳ��漰�ˡ�


--
�뿪�����֪������ã�����˰����֪���Ժ󲻻����Ķ�һ�Ρ�
�� ��Դ:���ɽ��ˮ bbs.neu.edu.cn��[FROM: 210.83.210.174]
Technical Details
Message-ID: <4AEGif$Cax@bbs.neu.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEU

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: f6cb0,4dfc984436455413
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2004-01-11 22:03:10 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEU
From: stillicel.bbs@bbs.neu.edu.cn (����)
Newsgroups: cn.bbs.comp.lang.java
Subject: ����import
Date: 12 Jan 2004 06:02:17 GMT
Organization: ��ɽ��ˮ
Message-ID: <4AEGif$Cax@bbs.neu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: java/M.1073887337.A
Lines: 102