Java Packages and JAR packages

Source: Internet
Author: User

1. Package

Package pack; /* Define the package, put it in the first line of the program, the package name so the letter lowercase */


Class Packagedemo
{
public static void Main (string[] args)
{
Packa. Demoa a=new Packa.              Demoa (); /* There will be two errors at compile time,
1. Class name error (need to write the name of the specified package before the class name)
2.package package is not in (package definition in other directory, need to set the variable (set= package location))
3. Insufficient permissions, to be large enough, set to public, access to the members of public
4. Compile order, first compile the class to be used
*/
A.show ();
}
}
Use of/*-d * *
/* Every time you add a file, that's not annoying, so there's a parameter for us to add
Plus-D. Two spaces, which is equivalent to adding a package with the current directory
There was no package before, it is the current directory as the default package exists
-D can also specify to go to other directories to do this to separate the current file from the running program, so we just need to give the program to someone else to
(In other disk running program want to run, you must set the location of the class, otherwise there is no result, is to set environment environment variables, set to the sub-directory can be)
*/


/* How should classes in different packages be accessed? 4 notes written on the program */

/* Features of package */
/* Package can write many classes, a public, other private, so also has encapsulation */


/* Summary of package
Access to the package, access to the classes in the package, and members of the class require public access
Subclasses in different packages also have direct access to the members of the parent class that are accessed by protected

There are only two types of public and protected permissions that can be used between packages and packages
Review: Permissions greater than or equal to the parent class function can be overridden
You cannot have two public classes or two public interfaces within a package, you must create a new package that cannot be integrated
Multi-pack, also use point
*/

/* To simplify the writing of the class name (the object that creates the class has to write many package names before the class name, which is cumbersome)
1. Use keyword import (imported meaning) (format: Package name. Class name)
2. Once imported, create an object directly
3. The classes in the package are imported
4. Add * represents all classes imported (last plus * is all classes in the import sub-package)
5. It is recommended not to use wildcards, because this is more memory space, with that on the load that, and then basically do not add their own
6. Different packages have the same class name, so to avoid ambiguity, to add a specific package name before the class name
7. Create a package name do not repeat, you can use the URL to complete the definition, the URL is unique
8. How is the package name defined? Domain name + package name (abbreviation for specific function)
*/

Package packa;

public class Demoa extends packb. Demob/* Inherit a class from 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 Pack

/*java Compressed Package (what is a jar package: using the JDK tool Jar.exe)
1. Convenient to carry the item
2. Easy to use, just set the jar path in Classpath
3. Database driver, SSH framework, etc. are implemented in JAR package
*/

/* Review
1. Compile,-D to compile the package
2. Run Package name + class name
*/

/* How to create, similar to tools used in Java, etc.
1. Understand first
-C Create a new archive file
-t lists the archive directory
-X extracts the specified (or all) files from the file
-U Update existing archive file
-V generates verbose output in standard output
-f Specifies the archive file name
-M contains inventory information from the specified manifest file
-E is a standalone application bundled into an executable jar file
Specify the application entry point
-0 storage only; No use case any ZIP compression
-M does not create an entry for the manifest file
-I generate index information for the specified jar file
-C changes to the specified directory and contains the files therein
2. Create
(The directory where the package is to be compressed) JAR-CF (Compressed package name * * *). JAR) (The package name put in)
3. View
JAR-TF (Compressed Package name * * *). Jar
4. Use the jar package (usually downloaded from the Internet)
1. Download the jar package to see the index file (inside doc)
2.-CFV-TVF > path. txt (can be displayed using this in a text block view)

*/





Java Packages and JAR packages

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.