日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java反射用法示例_Java包| 类型,用法,示例

發(fā)布時間:2025/3/11 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java反射用法示例_Java包| 类型,用法,示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

java反射用法示例

配套 (Packages)

Packages in Java is simply a mechanism to encapsulate (i.e. to put in a short and concise form) a group of classes,interfaces,enumerations, sub packages, etc. In real world, application is developed in such a manner so that we can easily maintain each module. To create package is simply use package keyword with name of the package at first statement in the program.

Java包只是一種封裝(即,以簡明扼要的形式)一組類,接口,枚舉,子包等的機制。在現(xiàn)實世界中,應用程序的開發(fā)方式使我們可以輕松地維護每個模塊。 要創(chuàng)建包,只需在程序的第一條語句中使用帶有包名稱的package關鍵字。

There are two type of Packages that are found in java,

java中有兩種類型的Packages,

  • User defined packages

    用戶定義包

  • In Built packages

    內(nèi)置包裝

  • 1)用戶定義的套餐 (1) USER DEFINED PACKAGES)

    The Packages that are created by the user to differentiate between the classes and the interfaces that are made in their projects are user defined packages.

    用戶創(chuàng)建的用于區(qū)分類和在其項目中創(chuàng)建的接口的包是用戶定義的包。

    2)內(nèi)置包裝 (2) IN-BUILT PACKAGES)

    The Packages that are the part of java API’s and includes variousclasses, interfaces, sub packages that are already defined in it are in-built packages. These packages are also known as the Predefined packages.

    包是Java API的一部分,包括各種類,接口,已在其中定義的子包是內(nèi)置包。 這些軟件包也稱為預定義軟件包。

    There are some packages that exists in java, they are:

    Java中存在一些軟件包,它們是:

    • java.lang: uses to bundles the fundamental classes.

      java.lang :用于捆綁基本類。

    • java.io: classes for input , output functions are bundled in this package.

      java.io :用于輸入,輸出功能的類捆綁在此包中。

    • java.util: classes which are implemented in data structure for date and time operations are bundled here.

      java.util :這里捆綁了在數(shù)據(jù)結構中用于日期和時間操作的類。

    • java.applet: bundles classes for making applets .

      java.applet :捆綁用于制作applet的類。

    • java.net: bundles the classes for supporting network operations.

      java.net :捆綁用于支持網(wǎng)絡操作的類。

    These all are in-built packages that are commonly used.

    這些都是常用的內(nèi)置軟件包。

    Java包的優(yōu)點 (MERITS of packages in java)

  • By the use of packages in java, it becomes easy to search and locate any class, annotation, enumeration etc.

    通過使用Java中的包,可以輕松地搜索和找到任何類,注釋,枚舉等。

  • Naming conflict can be prevented that are occurred in between the different classes by the use of java packages.

    通過使用Java包,可以防止在不同類之間發(fā)生命名沖突。

  • Java packages renders protection.

    Java軟件包提供了保護。

  • Most of programming tasks are done by the API’s classes and Packages, which minimize the number of lines that are written within the piece of code.

    大多數(shù)編程任務都是由API的類和包完成的,它們可以最大程度地減少代碼段中編寫的行數(shù)。

  • Reduction in execution time i.e. execution time is less.

    減少執(zhí)行時間,即執(zhí)行時間更少。

  • Uses less memory space.

    使用更少的內(nèi)存空間。

  • Improved performance.

    改進的性能。

  • Steps for creating a user defined package:

    創(chuàng)建用戶定義包的步驟:

  • Package program’s first statement should be the package statement.

    打包程序的第一個語句應為package語句。

  • Class modifier must we public so that the class and methods can be used outside the program.

    我們必須公開Class修飾符,以便可以在程序外部使用類和方法。

  • Only one public class or only one public interface are used in package program while any number of normal classes are used in it.

    程序包程序中僅使用一個公共類或僅一個公共接口,而在其中使用了任意數(shù)量的普通類。

  • It should contain any main class not the main () in it.

    它應該包含任何主類,而不是main()。

  • Constructor modifier must be Public.

    構造函數(shù)修飾符必須為Public。

  • Method modifier of class or interface must be public.

    類或接口的方法修飾符必須是公共的。

  • The package program should be save either with public class name or a public interface name.

    程序包應使用公共類名或公共接口名保存。

  • Syntax:

    句法:

    //Sum.java //save package with 'public' classname//first statement is package package OurPackage//class modifier must public public class Sum {//constructor modifier must public.Public Sum() {System.out.println("Sum class constructor");}//method modifier must public.Public void show() {System.out.println("Sum class method");} }

    Read more: Packages in Java

    : Java包

    翻譯自: https://www.includehelp.com/java/packages-in-java.aspx

    java反射用法示例

    總結

    以上是生活随笔為你收集整理的java反射用法示例_Java包| 类型,用法,示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。