Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3

  • BOSCOCAMPUSVISION
  • 2020-09-14
  • 95
CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES  (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3
java packagecreating packagesaccessing a package
  • ok logo

Скачать CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3 бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3 или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3 бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео CP1344:PROGRAMMING IN JAVA-LECTURE -48-JAVA PACKAGES (CREATING PACKAGES, ACCESSING A PACKAGE)BCA-S3

Creating Packages

We have seen in detail how Java system packages are organized and used, Now, let us see how to create our own packages. We must first declare the name of the package using the package keyword followed by a package name, This must be the first statement in a Java source file (except for comments and white spaces), Then we define a class, just as we normally define a class. Here is an example:
package firstPackage;// package declaration
public class FirstClass //class definition
{
(body of class)
}
Here the package name is firstPackage. The class FirstClass is now considered a part of this package. This listing would be saved as a file called FirstClass.java, and located in a directory named firstPackage. When the source file is compiled, Java will create a .class file and store it in the same directory.

Remember that the .class files must be located in a directory that has the same name as the package, and this directory should be a subdirectory of the directory where classes that will import the package are located.
Creating our own package involves the following steps:

1. Declare the package at the beginning of a file using the form
package packagename;

2. Define the class that is to be put in the package and declare it public.

3. Create a subdirectory under the directory where the main source files are stored.
4. Store the listing as the classname.java file in the subdirectory created.

5. Compile the file. This creates .class file in the subdirectory.
Remember that case is significant and therefore the subdirectory name must match the package name exactly.
As pointed out earlier, Java also supports the concept of package hierarchy. This is done by specifying multiple names in a package statement, separated by dots. Example:

package firstPackage.secondPackage;
This approach allows us to group related classes into a package and then group related packages into a larger package. Remember to store this package in a subdirectory named firstPackage/ second Package.
A java package file can have more than one class definitions. In such cases, only one of the classes may be declared public and that class name with .java extension is the source file name. When a source file with more than one class definition is compiled, Java creates independent .class files for those classes.
Accessing a Package

It may be recalled that we have discussed earlier that a Java system package can be accessed either using a fully qualified class name or using a shortcut approach through the import statement, We use the import statement when there are many references to a particular package or the package name is too long and unwieldy.
The same approaches can be used to access the user-defined packages as well. The import statement can be used to search a list of packages for a particular class.
The general form of import
statement for searching a class is as follows:

import packagel [.package2] [.packag3].classname;


Here package1 is the name of the top level package, package2 is the name of the package that is inside the packages, and so on. We can have any number of packages in a package hierarchy. Finally, the explicit classname is specified,
Note that the statement must end with a semicolon (;). The import statement should appear before any class definitions in a source file. Multiple import statements are allowed. The following is an example of importing a particular class:

import firstPackage. secondPackage. MyClass;

After defining this statement, all the members of the class MyClass can be directly accessed using the class name or its objects (as the case may be) directly without using the package name.
We can also use another approach as follows:

import packagename.*;

Here, packagename may denote a single package or a hierarchy of packages as mentioned earlier. The star (*) indicates that the compiler should search this entire package hierarchy when it encounters a class name. This implies that we can access all classes contained in the above package directly.

The major drawback of the shortcut approach is that it is difficult to determine from which package a particular member came. This is particularly true when a large number of packages are imported. But
the advantage is that we need not have to use long package names repeatedly in the program.

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]