Packages
Packages is used to group related types which are classes, interfaces, enumerations and annotation types.
Ex.
//in UseCar.java
package com.cars.engine;
public interface UseCar{}
//in Vehicle.java
package com.cars.engine;
public abstract class Vehicle{}
3 Ways to access members:
Full qualified name. Ex. com.cars.engine.Vehicle;
Import package member. Ex. Vehicle v1= new Vehicle();
Import members entire package.
Ex.
import com.cars.engine.*;
Vehicle v1 = new Vehicle();
Car car1 = new Car();
Things you must remember with packages:
You must name packages with correct convention to make it unique and avoid name clashes.
Ex. package com.cars.engine;
Your class files should be located in the directories with names using the package name.
$javac -classpath /path/to/jar:/path/to/jar -d /path/to/folder/containing/java/files/ MyCar.java Vehicle.java $jar cfm MyCar.jar Manifest.txt /com/cars/engine/*.class $java -jar Main.jar |
to be continued...
No comments:
Post a Comment