How to wrapping your own packages in java, JAVA Programming

Assignment Help:

How to Wrapping Your Own Packages in java?

Java does not limit you to using just the system supplied packages. You can write your own as well. You write packages just such as you write any other Java program. Make sure you follow these rules:

1. There must be no more than one public class per file.
2. All files within the package must be named classname.java where classname is the name of the single public class in the file.
3. At the extremely top of each file in the package, before any import statements, put the statement
package myPackage;

To use the package in other programs, compile the .java files as commonly and then move the resulting .class files within the appropriate subdirectory of one of the directories referenced in your CLASSPATH environment variable. For example if /home/elharo/classes is in your CLASSPATH and your package is known as package1, then you would form a directory known as package1 in /home/elharo/classes and then put all the .class files in the package in /home/elharo/classes/package1.

For example,
package com.macfaq.net;

import java.net.*;

public class URLSplitter {

public static void main(String[] args) {

for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[i]);
System.out.println("Protocol: " + u.getProtocol());
System.out.println("Host: " + u.getHost());
System.out.println("Port: " + u.getPort());
System.out.println("File: " + u.getFile());
System.out.println("Ref: " + u.getRef());
}
catch (MalformedURLException e) {
System.err.println(args[i] + " is not a valid URL");
}
}

}

}

$ javac -d /home/elharo/classes URLSplitter.java
The -d flag to the compiler tells it to form the essential directories such as elharo/net in the specified directory. In this instance, URLSplitter.class is placed in /home/elharo/classes/com/macfaq/net. You can use the usual shell syntax such as. For the current directory or ~ for your home directory.


Related Discussions:- How to wrapping your own packages in java

Explain the purpose of the access token, Question: a) Authentication r...

Question: a) Authentication relies on standards and protocols that are used to confirm the identity of a user or object. Windows Server 2003 supports several types of network

How we use a car object in a different class, How we Use a Car object in a ...

How we Use a Car object in a different class ? class Car { String licensePlate; // e.g. "New York 543 A23" double speed; // in kilometers per hour double maxSpeed;

What is javaserver faces ui component , A user interface control th...

A user interface control that outputs data to a client or permits a user to input data to a JavaServer Faces application.

Write a program that manages a list of train tickets, A fictitious train co...

A fictitious train company, 'Transrail', has commissioned you to write a program that manages a list of train tickets. The program should display a text menu that prompts the us

Discuss features of java, Question 1 Discuss features of JAVA Question...

Question 1 Discuss features of JAVA Question 2 What are primitive data types? Discuss Question 3 Explain data conversion function ValueOf ()? Question 4 What are th

How marketing strategies are changed along with the progress, How marketing...

How marketing strategies are changed along with the progress in computing? How latest marketing strategies are implemented? Marketing Strategy Changes along with the latest req

What is linear search, What is linear search? It is the simplest form o...

What is linear search? It is the simplest form of search. It searches for the element sequentially starting from first element. This search has a drawback if element is located

Probability, Mike sells on the average 15 newspapers per week (Monday – Fri...

Mike sells on the average 15 newspapers per week (Monday – Friday). Find the probability that 2.1 In a given week he will sell all the newspapers [7] 2.2 In a given day he will se

Explain the use and purpose of java adapter classes, Question: (a) Exp...

Question: (a) Explain the event handling mechanism using a 'JComboBox' as example. Your answer must clearly indicate the event source, event object and event listener. Also

Describe the superclass in inheritance, Describe the Superclass in Inherita...

Describe the Superclass in Inheritance ? In this example you start through defining a more common MotorVehicle class. public class MotorVehicle { private String licensePlat

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd