Article View: cn.bbs.comp.lang.java
Article #19045����import
From: ����
Date: Mon, 12 Jan 2004 05:56
Date: Mon, 12 Jan 2004 05:56
103 lines
6951 bytes
6951 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
��������Ҫ�˽����package�ĺ�����÷�������úÿ�����̲��й���pakage��Ҫ���ʹ
�÷�����Ȼ�����������ӣ����һ�±�������θ��
import���ͻ���������classpath����ֵһ�����ҵ�����Ҫ��class�ġ�
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�ˡ��α��������ӣ�����Ͳ��漰�ˡ�
--
�뿪�����֪������ã�����˰����֪���Ժ����Ķ�һ�Ρ�
[0;1;36m�� ��Դ:���ɽ��ˮ bbs.neu.edu.cn��[FROM: 210.83.210.174][m
Technical Details
Message-ID:
<4AEGbU$Cqz@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!167.206.3.103.MISMATCH!news3.optonline.net!maily.cic.tsinghua.edu.cn!news.neu.edu.cn!NEUShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: f6cb0,4dfc984436455413,start X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2004-01-11 21:57:16 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!167.206.3.103.MISMATCH!news3.optonline.net!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 05:56:30 GMT Organization: ��ɽ��ˮ Message-ID: <4AEGbU$Cqz@bbs.neu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: java/M.1073886990.A Lines: 103