Categories
程式開發

Java 代碼的組織機制



{“type”:”doc”,”content”:[{“type”:”heading”,”attrs”:{“align”:null,”level”:2},”content”:[{“type”:”text”,”text”:”包”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”在我们进行编程的时候会经常遇到一个相同的问题,就是”},{“type”:”text”,”marks”:[{“type”:”strong”}],”text”:”命名衝突”},{“type”:”text”,”text”:”。不同的人可能會定義同樣的類和接口名,Java 中解決這個問題的主要方法就是”} ,{“type”:”text”,”marks”:[{“type”:”strong”}],”text”:”「包」”},{“type”:”text”,”text”:”。 “}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”「包」类似计算机中的文件夹,正如我们在计算机管理文件,文件放在文件夹中一样,类和接口放在包中,文件夹一般是目录层次解决,Java 包也类似。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”「包」有包名,这个名称以点号 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”.”}]},{“type”:”text”,”text”:” 分隔表示層次結構。比如,我們之前常用的 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”String”}]},{“type”:”text”,”text”:” 類就位於包 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”java.lang”}]},{“type”:”text”,”text”:” 下,其中 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”java”}]},{“type”:”text”,”text”:” 是上層包名,”},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”lang”}]},{“type”:”text”,”text”:” 是下層包名。帶完整包名的類名稱為其”},{“type”:”text”,”marks”:[{“type”:”strong”}],”text”:”「完全限定名」”},{“type”:”text”,”text”:”,比如String 類的完全限定名為”},{“type”:”codeinline”,” content”:[{“type”:”text”,”text”:”java.lang.String”}]},{“type”:”text”,”text”:”。Java API 中所有的類和接口都位於包 java 或 javax 下,java 是標準包,javax 是擴展包。”}]},{“type”:”heading”,”attrs”:{“align”:null,”level”:3},”content”:[{“type”:”text”,”text”:”声明类所在的包”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”定义类的时候,应该先使用关键字 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”package”}]},{“type”:”text”,”text”:” 聲明其包名”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”codeblock” ,”attrs”:{“lang”:”java”},”content”:[{“type”:”text”,”text”:”package com.lgq.study.bean;npublic class User {n}”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”以上声明类 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”User”}]},{“type”:”text”,”text”:” 的包名為 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”com.lgq.study.bean”}]},{“type”:”text”,”text”:” 包聲明語句應該位於源代碼的最前面,前面不能有註釋外的其他語句。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”包名和目录结构必须匹配,如果源文件的根目录为 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”D:\src\”}]},{“type”:”text”,”text”:”,則上面的 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”User”}]},{“type”:”text”,”text”:” 類對應的文件 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”User.java”}]},{“type”:”text”,”text”:”,其全路徑就應該是 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”D:\src\com\lgq\study\bean\User.java”}]},{“type”:”text”,”text”:”。如果不匹配, Java 會提示編譯錯誤。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”Java 中命名包名的一个惯例是使用域名作为前缀,因为域名是唯一的,一般按照域名的反序来定义包名,比如,域名是 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”apache.org”}]},{“type”:”text”,”text”:”,包名就以 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”org.apache”}]},{“type”:”text”,”text”:” 開頭。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”heading” ,”attrs”:{“align”:null,”level”:3},”content”:[{“type”:”text”,”text”:”类的导入”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”blockquote” ,”content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”同一個包下的類之間互相引用是不需要包名的,可以直接使用。但如果類不在同一個包內,則必須要知道其所在的包。只有一個例外,”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”同一个包下的类之间互相引用是不需要包名的,可以直接使用。但如果类不在同一个包内,则必须要知道其所在的包。只有一个例外,”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”同一個包下的類之間互相引用是不需要包名的,可以直接使用。但如果類不在同一個包內,則必須要知道其所在的包。只有一個例外,”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”同一个包下的类之间互相引用是不需要包名的,可以直接使用。但如果类不在同一个包内,则必须要知道其所在的包。只有一个例外,”}{“type”:”codeinline””content”:[{“type”:”text”,”text”:”java.lang”}]},{“type”:”text”,”text”:” 包下的類可以直接使用,不需要引入,也不需要使用完全限定名,比如String 類、System 類,其他包的類則不行。 a”}]}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”heading” ,”attrs”:{“align”:null,”level”:4},”content”:[{“type”:”text”,”text”:”类的完全限定名导入类”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”codeblock” ,”attrs”:{“lang”:”java”},”content”:[{“type”:”text”,”text”:”public class Test {n public static void main(String[] args) {n int[] arr = new int[]{1, 4, 2, 3};n java.util.Arrays.sort(arr);n System.out.println(java.util.Arrays.toString(arr));n }n}” }]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”上面使用 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”Arrays”}]},{“type”:”text”,”text”:” 類中的 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”sort”}]},{“type”:”text”,”text”:” 方法,通過完全限定名可以這樣使用。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”heading” ,”attrs”:{“align”:null,”level”:4},”content”:[{“type”:”text”,”text”:”将用到的类引入当前类”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”引入的关键字是 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”import”}]},{“type”:”text”,”text”:”,”},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”import”}]},{“type”:”text”,”text”:” 需要放在 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”package”}]},{“type”:”text”,”text”:” 定義之後,類定義之前:”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”codeblock” ,”attrs”:{“lang”:”java”},”content”:[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nnpublicclassTest{npublicstaticvoidmain(String[] args) {n int[] arr = new int[]{1, 4, 2, 3};n Arrays.sort(arr);n System.out.println(Arrays.toString(arr));n }n}”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline””content”:[{“type”:”codeinline””content”:[{“type”:”codeinline””content”:[{“type”:”codeinline””content”:[{“type”:”text”,”text”:”import”}]},{“type”:”text”,”text”:” 操作還有如下寫法:”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”bulletedlist” ,”content”:[{“type”:”listitem”,”content”:[{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”import java.util.*”}]},{“type”:”text”,”text”:” 引入 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”java.util”}]},{“type”:”text”,”text”:” 包下所有的直接類,而不會引入 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”java.util”}]},{“type”:”text”,”text”:” 下嵌套包內的類。”}]}]}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”heading” ,”attrs”:{“align”:null,”level”:3},”content”:[{“type”:”text”,”text”:”静态导入”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text”,”text”:”静态导入有一个 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”static”}]},{“type”:”text”,”text”:” 關鍵字,可以直接導入類的公開靜態方法和成員。”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”codeblock” ,”attrs”:{“lang”:”java”},”content”:[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nimportstaticjavalangSystemout;//導入靜態變量outnnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nimportstaticjavalangSystemout;//导入静态变量outnnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nimportstaticjavalangSystemout;//導入靜態變量outnnpublicclassTest{npublicstaticvoidmain(String[{“type”:”text””text”:”packagecomlgqstudy;nnimportjavautilArrays;nimportstaticjavalangSystemout;//导入静态变量outnnpublicclassTest{npublicstaticvoidmain(String[] args) {n int[] arr = new int[]{1, 4, 2, 3};n Arrays.sort(arr);n out.println(Arrays.toString(arr)); //直接使用 out 變量n }n}”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”heading” ,”attrs”:{“align”:null,”level”:2},”content”:[{“type”:”text”,”text”:”包的作用域”}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”bulletedlist” ,”content”:[{“type”:”listitem”,”content”:[{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”public”}]},{“type”:”text”,”text”:”:標記為 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”public”}]},{“type”:”text”,”text”:” 的部分可以被任意的類使用;”}]}]},{“type”:”listitem”,”content”:[{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”private”}]},{“type”:”text”,”text”:”:標記為 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”private”}]},{“type”:”text”,”text”:” 的部分只能被定義它們的類使用;”}]}]},{“type”:”listitem”,”content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”如果沒有指定”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”如果没有指定”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”如果沒有指定”}{“type”:”codeinline””content”:[{“type”:”paragraph””attrs”:{“indent”:0″number”:0″align”:null”origin”:null}”content”:[{“type”:”text””text”:”如果没有指定”}{“type”:”codeinline””content”:[{“type”:”text”,”text”:”public”}]},{“type”:”text”,”text”:” 或 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”private”}]},{“type”:”text”,”text”:”,這個部分(類、方法或變量)可以被同一個包中的所有類訪問,而其他包內的類則不可以訪問。”} ]}]},{“type”:”listitem”,”content”:[{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”protected”}]},{“type”:”text”,”text”:”:標記為 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”protected”}]},{“type”:”text”,”text”:” 的部分不僅表明子類可以訪問,還表明同一個包內的其他類可以訪問,即使這些類不是子類也可以。”}]}]}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”blockquote” ,”content”:[{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”protected”}]},{“type”:”text”,”text”:” 和 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”default”}]},{“type”:”text”,”text”:” 的區別就在於子類是否和父類在同級包中,”},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”protected”}]},{“type”:”text”,”text”:” 修飾的變量子類在其他包中也可以訪問,但是 “},{“type”:”codeinline”,”content”:[{“type”:”text”,”text”:”default”}]},{“type”:”text”,”text”:” 情況下的變量子類只能在同級包中才可以訪問。”}]}]},{“type”:”paragraph”,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null}},{“type”:”paragraph” ,”attrs”:{“indent”:0,”number”:0,”align”:null,”origin”:null},”content”:[{“type”:”text””text”:”可見性範圍從小到大是:”}{“type”:”codeinline””content”:[{“type”:”text””text”:”可见性范围从小到大是:”}{“type”:”codeinline””content”:[{“type”:”text””text”:”可見性範圍從小到大是:”}{“type”:”codeinline””content”:[{“type”:”text””text”:”可见性范围从小到大是:”}{“type”:”codeinline””content”:[{“type”:”text”,”text”:”private”}]},{“type”:”text”,”text”:” < 默認(包)< "},{"type":"codeinline","content":[{"type":"text","text":"protected"}]},{"type":"text","text":" < "},{"type":"codeinline","content":[{"type":"text","text":"public"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading" ,"attrs":{"align":null,"level":2},"content":[{"type":"text","text":"JAR 文件"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Java 中,编译后的一个或多个包的 "},{"type":"codeinline","content":[{"type":"text","text":"Java class"}]},{"type":"text","text":" 文件可以打包為一個文件,Java 中打包命令為 "},{"type":"codeinline","content":[{"type":"text","text":"jar"}]},{"type":"text","text":",打包後的文件擴展名為 "},{"type":"codeinline","content":[{"type":"text","text":".jar"}]},{"type":"text","text":",一般稱之為 "},{"type":"codeinline","content":[{"type":"text","text":"jar"}]},{"type":"text","text":" 包,JAR 文件是壓縮的,它使用了大家熟悉的 ZIP 壓縮格式。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"打包方式如下,首先到编译后的 "},{"type":"codeinline","content":[{"type":"text","text":"java class"}]},{"type":"text","text":" 文件根目錄,然後運行如下命令:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock" ,"attrs":{"lang":"shell"},"content":[{"type":"text","text":"jar -cvf hello.jar com"}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"com 是最上层包名"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align": null,"level":2},"content":[{"type":"text","text":"程序的编译与链接"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"「编译」是将源代码文件变成扩展名是 "},{"type":"codeinline","content":[{"type":"text","text":".class"}]},{"type":"text","text":" 的一種字節碼,這個工作一般是由 "},{"type":"codeinline","content":[{"type":"text","text":"javac"}]},{"type":"text","text":" 命令完成的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"「链接」是在运行时动态执行的,"},{"type":"codeinline","content":[{"type":"text","text":".class"}]},{"type":"text","text":" 文件不能直接運行,運行的是 "},{"type":"codeinline","content":[{"type":"text","text":"Java"}]},{"type":"text","text":" 虛擬機,執行的就是 "},{"type":"codeinline","content":[{"type":"text","text":"java"}]},{"type":"text","text":" 命令,這個命令解析 "},{"type":"codeinline","content":[{"type":"text","text":".class"}]},{"type":"text","text":" 文件,轉換為機器能識別的二進制代碼,然後運行。所謂「鏈接」就是根據引用到的類加載相應的字節碼並執行。 "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 编译和运行时,都需要以参数指定一个 "},{"type":"codeinline","content":[{"type":"text","text":"classpath"}]},{"type":"text","text":",即類路徑。類路徑可以有多個,對於直接的 "},{"type":"codeinline","content":[{"type":"text","text":"class"}]},{"type":"text","text":" 文件,路徑是 "},{"type":"codeinline","content":[{"type":"text","text":"class"}]},{"type":"text","text":" 文件的根目錄;對於 "},{"type":"codeinline","content":[{"type":"text","text":"jar"}]},{"type":"text","text":" 包,路徑是 "},{"type":"codeinline","content":[{"type":"text","text":"jar"}]},{"type":"text","text":" 包的完整名稱(包括路徑和 jar 包名)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text""text":"在Java源代碼編譯時,Java編譯器會確定引用的每個類的完全限定名,確定的方式是根據"}{"type":"codeinline""content":[{"type":"text""text":"在Java源代码编译时,Java编译器会确定引用的每个类的完全限定名,确定的方式是根据"}{"type":"codeinline""content":[{"type":"text""text":"在Java源代碼編譯時,Java編譯器會確定引用的每個類的完全限定名,確定的方式是根據"}{"type":"codeinline""content":[{"type":"text""text":"在Java源代码编译时,Java编译器会确定引用的每个类的完全限定名,确定的方式是根据"}{"type":"codeinline""content":[{"type":"text","text":"import"}]},{"type":"text","text":" 語句和 "},{"type":"codeinline","content":[{"type":"text","text":"classpath"}]},{"type":"text","text":"。如果導入的是完全限定名,則可以直接比較並確定。如果是模糊導入(import 帶"},{"type":"codeinline" ,"content":[{"type":"text","text":".*"}]},{"type":"text","text":"),則根據 "},{"type":"codeinline","content":[{"type":"text","text":"classpath"}]},{"type":"text","text":" 找對應父包,再在父包下尋找是否有對應的類。如果多個模糊導入的包下都有同樣的類名,則Java會提示編譯錯誤,此時應該明確指定導入哪個類。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph" ,"attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text""text":"Java運行時,會根據類的完全限定名尋找並加載類,尋找的方式就是在類路徑中尋找,如果是"}{"type":"codeinline""content":[{"type":"text""text":"Java运行时,会根据类的完全限定名寻找并加载类,寻找的方式就是在类路径中寻找,如果是"}{"type":"codeinline""content":[{"type":"text""text":"Java運行時,會根據類的完全限定名尋找並加載類,尋找的方式就是在類路徑中尋找,如果是"}{"type":"codeinline""content":[{"type":"text""text":"Java运行时,会根据类的完全限定名寻找并加载类,寻找的方式就是在类路径中寻找,如果是"}{"type":"codeinline""content":[{"type":"text","text":"class"}]},{"type":"text","text":" 文件的根目錄,則直接查看是否有對應的子目錄及文件,如果是"},{"type":"codeinline","content" :[{"type":"text","text":"jar"}]},{"type":"text","text":" 文件,則首先在內存中解壓文件,然後再查看是否有對應的類。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"参考资料"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist" ,"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 编程的逻辑"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java编程思想"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 核心技术 卷 1"}]}]}]}]}