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

Define array, Define Array ? Indexed collections of variable of similar...

Define Array ? Indexed collections of variable of similar data types or we can say a Set of organized variables of similar type.

How to evaluate two words similarity, I need to get how to start the java p...

I need to get how to start the java program to evaluate the simillarity.

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

What is mixing data types, What is Mixing Data Types? As well as mergin...

What is Mixing Data Types? As well as merging various operations, you can mix and match various numeric data types on the similar line. The program below uses both ints and dou

Write a program of else statement in java, Write a program of else statemen...

Write a program of else statement in java? The else statement in Java // This is the Hello program in Java class Hello { public static void main (String args[]) { if (

What do you mean by auto wiring, The Spring container is able to autowire r...

The Spring container is able to autowire relationships among collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for

Cyclos ussd and mobile banking ivr module, Cyclos USSD and mobile banking I...

Cyclos USSD and mobile banking IVR module Project Description: We previously have a Cyclos mobile banking solution deployed on our server with SMS banking module. The solu

Calculates whether a plane successfully lands or not, Write a program calle...

Write a program called LandThePlane that calculates whether a plane successfully lands or not.   The program begins by prompting (asking) the user for the following details, in th

Loops, #questiongfjnkdfn..

#questiongfjnkdfn..

Explain java flow control, Explain java flow control ? if els...

Explain java flow control ? if else else if while for do while switch case break continue goto is a reserved word.

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