Java package and jar package, java package jar package

Source: Internet
Author: User

Java package and jar package, java package jar package

1. Package

Package pack;/* defines the package, which is placed in the first line of the program. The package name must be in lowercase */


Class PackageDemo
{
Public static void main (String [] args)
{
Packa. DemoA a = new packa. DemoA ();/* two errors will occur during compilation,
1. Incorrect Class Name (the name of the specified package must be written before the class name)
2. The package is not in (the package is defined in another directory and you need to set the variable (set = the package location ))
3. the permission is not enough. The permission should be large enough to be set to public, and the accessed members should also be public.
4. Compile sequence: first compile the class to use
*/
A. show ();
}
}
/*-D usage */
/* It is not annoying to add a file every time. Therefore, there is a parameter for us to add
Separate the-d. Two spaces, which is equivalent to adding the package of the current directory.
No package exists before. The current directory is used as the default package.
-D can also specify other directories to separate the current file from the running program. In this way, we only need to give the program to others.
(To run programs on other disks, you must set the class location. Otherwise, if there is no result, you can set the environment variable and set it to the sub-directory)
*/


/* How do I access classes in different packages? Four precautions are written on the Program */

/* Package features */
/* The package can write many classes, one public and the other private, so it is also encapsulated */


/* Package Summary
Access between packages. The classes in the accessed package and the Members in the class must be accessed by the public.
Sub-classes in different packages can also directly access the members accessed by protected in the parent class.

There are only two types of public and protected permissions available between packages.
Review: only functions with permissions greater than or equal to the parent class can be overwritten.
Two public classes or two public interfaces cannot appear in a package. You must create a new package and cannot integrate it.
Multiple packages and usage points
*/

/* To simplify the writing of class names (it is troublesome to create class objects to write many package names before class names)
1. Use the keyword import (import meaning) (Format: package name. Class Name)
2. After the import, you can directly create an object.
3. Imported classes in the package
4. Add * to import all classes (add * to import all classes in the sub-package)
5. We recommend that you do not use wildcards, because they occupy the memory space. You can use that character to load the character. You do not need to add it yourself in the future.
6. Different packages have the same class name. To avoid ambiguity, add a specific package name before the class name.
7. Create a package name. You can use a url to complete the definition. The url is unique.
8. How is the package name defined? Domain name + package name (abbreviated for specific functions)
*/

 

Package packa;

Public class DemoA extends packb. DemoB/* inherits the class in another package */
{
Public static void main (String args [])
{
Void show ()
{
System. out. println ("demoa show run ");
Method ();
}
}
}

 

 

Package packb;

Public class DemoB
{
Public static void main (String args [])
{
Public void method ()
{
System. out. println ("demob method run ");
}
}
}

 

 

 

2. jar package

/* Java compressed package (what is a Jar package: Use the jdk tool jar.exe)
1. Convenient project deployment
2. Easy to use. You only need to set the jar path in classPath.
3. database drivers and SSH frameworks are all implemented using jar packages.
*/

/* Review
1. Compile,-d for package Compilation
2. Run package name + class name
*/

/* How to create, similar to java and other tools
1. First understand
-C. Create a new archive file
-T list the archive Directories
-X extract the specified (or all) file from the file
-U: update existing archive files
-V generates detailed output in standard output
-F specifies the archive file name
-M: contains the configuration information in the specified configuration file.
-E is an independent application bound to an executable jar file.
Application entry point
-0 is stored only; no ZIP compression is used
-M: do not create a list file.
-I generate index information for the specified jar File
-C: change to the specified directory and include the files.
2. Create
(The directory where the package to be compressed is located) jar-cf (package name ***. Jar) (package name)
3. View
Jar-tf (name of the compressed package ***. Jar)
4. Use the jar package (usually downloaded from the internet)
1. Check the index file for the downloaded jar package (in the doc)
2.-cfv-tvf> cmd.txt (this can be used for display in the text block)
 
*/





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.