Article View: cn.bbs.comp.lang.java
Article #19044Re: ��λ�����һ��import�ĺ���?????
From: ����
Date: Mon, 12 Jan 2004 05:41
Date: Mon, 12 Jan 2004 05:41
92 lines
6635 bytes
6635 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�ĵ�ǰĿ¼�£�����֤ϵͳ��cla
sspath��������ֵ����
classpath��.;
�����ֱ����Test.java��ֱ��ʹ��Prey�����ʹ��import�ؼ��֡�
����
��������Ҫ�˽����package�ĺ�����÷�������úÿ�����̲��й���pakage��Ҫ���ʹ
�÷�����Ȼ�����������ӣ����һ�±�������θ��import���ͻ���������classpath��
��ֵһ�����ҵ�����Ҫ��class�ġ�
import�ؼ��ֵĹ���������include����������̺�include��һ��
���ڳ�ѧ�ߣ���ʦ��Ҫ�����ǡ���
��1�����Ұ�import����include��
��2�����Ұ�����java�ļ��ŵ�ͬһ��Ŀ¼�£�
��3���ڳ��������õ���ϵͳ�ࣨ�Լ�д���ࣩ����ʹ��import��ֱ��ʹ�ü��ɣ�������Ϊ
�����������Զ��ҵ���
��ʦ˵����ѧ��package��һ�ж�ӭ�ж���ˡ�
include���ø��Ʒ�����ָ���ļ���ͷ�ļ�����Դ�ļ��Կɣ�������ԭԭ�������Ƶ���ǰ��
���С���ʵ���ǽ������ı��ļ��ϲ�Ϊһ���ļ���������һ���Ϊ��Ԥ���?��
import��ִ���ļ��ϲ����ܣ���ֻ�����ҵ���ǰ����ʹ�õ����*.class�ļ�����*.java��
��������ͻ���Ϊ�ҵ����õ������ֹ����������ִ�й�̡�
�����ҵĻ���ϵͳ����������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�ļ�����.��Ŀ¼��?ǰ���JavaԴ�ļ����ڵ�Ŀ¼�����ҵ������
���ҹ�̣��������
��3����û���ҵ�����ڡ�c:\jdk\lib\tools.jar���ļ��м�����Ѱjava\io\BufferdInpu
tStream.class����java\io\BufferdInputStream.java��
��4�����ҵ��������ҹ�̣�������׳��쳣������Ϊ����classpath�н�������������
Ŀ¼�������������Զ�������Ŀ¼���ҡ�
������ڳ�������ʹ���Լ�д���࣬��������������㲻��ʹ��package��䣬��ô������
��������
��1��������classpath
���Ǹ����Դ�ļ�����class�ļ����Ƶ���ǰ�����Ŀ¼�£���������ڲ��ҡ�.��Ŀ¼��
ʱ��Ϳ����ҵ�������ˡ����ڳ����ﲻ��Ҫдimport���
��2����classpath
��д��һ��Example.java�������һ����Ͻ�����һ��Ŀ¼D:\programming\java\mylib����
Example.java����ڸ�Ŀ¼�¡�Ȼ���classpath�ij�����ֵ����
classpath��.;c:\jdk\lib\tools.jar;d:\programming\java\mylib
�Ҷ�classpath�������ľ��������Example���·����
�����ҾͿ�������һ��UseExample.java�ļ���ֱ��ʹ��Example���ˣ����Ҳ���ʹ��impo
rt�ؼ��֡���Ϊ������������d:\programming\java\mylibĿ¼�ҵ�Example.java����Exa
mple.class���
������밴�չ���Ϊ�Լ�д�����ɸ�����飬����ڲ�ͬĿ¼���ô����Ҫʹ��packag
e�ˡ��α��������ӣ�����Ͳ��漰�ˡ�
--
�뿪�����֪������ã�����˰����֪���Ժ����Ķ�һ�Ρ�
[0;1;36m�� ��Դ:���ɽ��ˮ bbs.neu.edu.cn��[FROM: 210.83.210.174][m
Technical Details
Message-ID:
<4AEGJ8$C0u@bbs.neu.edu.cn>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEUShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: f6cb0,7e246a7947675f50 X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2004-01-11 21:42:07 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!feed2.newsreader.com!newsreader.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: Re: ��λ�����һ��import�ĺ���????? Date: 12 Jan 2004 05:41:44 GMT Organization: ��ɽ��ˮ Message-ID: <4AEGJ8$C0u@bbs.neu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: java/M.1073886104.A Lines: 92