Learn Java Tutorial for Beginners, Part 28: Packages

Опубликовано: 24 Июль 2020
на канале: Quordnet Academy
36
3

In this video by Quordnet Academy for the series Learn Java Tutorial for Beginners how to use Packages have been discussed.
If you would like to discover even more about java programming tutorial or the java complete course I advise you to check out the playlist :
   • Java Tutorial For Beginners  

Packages In Java
Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces. Packages are used for:

Preventing naming conflicts. For example there can be two classes with name Employee in two packages, college.staff.cse.Employee and college.staff.ee.Employee
Making searching/locating and usage of classes, interfaces, enumerations and annotations easier
Providing controlled access: protected and default have package level access control. A protected member is accessible by classes in the same package and its subclasses. A default member (without any access specifier) is accessible by classes in the same package only.
Packages can be considered as data encapsulation (or data-hiding).
All we need to do is put related classes into packages. After that, we can simply write an import class from existing packages and use it in our program. A package is a container of a group of related classes where some of the classes are accessible are exposed and others are kept for internal purpose.
We can reuse existing classes from the packages as many time as we need it in our program.
Subpackages: Packages that are inside another package are the subpackages. These are not imported by default, they have to imported explicitly. Also, members of a subpackage have no access privileges, i.e., they are considered as different package for protected and default access specifiers.
Example :
import java.util.*;
util is a subpackage created inside java package.
Accessing classes inside a package
Consider following two statements :
// import the Vector class from util package.
import java.util.vector;
// import all the classes from util package
import java.util.*;
First Statement is used to import Vector class from util package which is contained inside java.
Second statement imports all the classes from util package.
// All the classes and interfaces of this package
// will be accessible but not subpackages.
import package.*;

// Only mentioned class of this package will be accessible.
import package.classname;

// Class name is generally used when two packages have the same
// class name. For example in below code both packages have
// date class so using a fully qualified name to avoid conflict
import java.util.Date;
import my.packag.Date;

// Java program to demonstrate accessing of members when
// corresponding classes are imported and not imported.
import java.util.Vector;

public class ImportDemo
{
public ImportDemo()
{
// java.util.Vector is imported, hence we are
// able to access directly in our code.
Vector newVector = new Vector();

// java.util.ArrayList is not imported, hence
// we were referring to it using the complete
// package.
java.util.ArrayList newList = new java.util.ArrayList();
}
public static void main(String arg[])
{
new ImportDemo();
}
}
To never miss an update from or channel hit the subscribe button first and if already subscribe hit the bell icon.
1.Follow us on INSTAGRAM for Interesting posts
  / quordnet_academy  
2.Follow us on LINKEDIN for interesting content on different aspects
  / quordnet-academy  
3.Don't forget to like our FACEBOOK to get the most out of it
  / quordnetacademy  
4.Follow us on twitter to get a mix of all
  / quordnetacademy  
5.If you want to get us on TUMBLR please then click on the link given below
https://www.tumblr.com/blog/quordnet-...
6.Do join our OFFICIAL Telegram for notes of different things
https://t.me/quordnet
7.For get job update regularly both private and government do join this telegram channel
https://t.me/quordnetforjobs
#learn_java #javaforbeginners #javatutorialforbeginners #objectorientedprogramming
#tostringinjava #objectclass #objectclassinjava #java #javatutorial #quordnetacademy
#java_tutorial_series #javatutorialseries #howtousejavapackages #javapackagestutorial #listofjavapackagesandclasses #howtonamejavapackages #stepstocreatepackageinjavawithexample


На этой странице сайта вы можете посмотреть видео онлайн Learn Java Tutorial for Beginners, Part 28: Packages длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Quordnet Academy 24 Июль 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 36 раз и оно понравилось 3 зрителям. Приятного просмотра!