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

Using rmi build robust distributed systems-jdbc odbc, This work assesses th...

This work assesses the following Outcomes: • Build robust, secure distributed systems using advanced programming techniques Use RMI to build a distributed application accessing

Define network organization and their features, Define network organization...

Define network organization? What are important features of network organization? Network Organization : Network organization is an inter firm organization in which is charac

Illustrate about object oriented programming, Object Oriented Programming ...

Object Oriented Programming   Java is basically object oriented. Each line of code you write in java should be inside a class (not counting import directives). OOP fundamental

Explain JMS, JMS ((java messaging service))is an acronym used for Java Mess...

JMS ((java messaging service))is an acronym used for Java Messaging Service. It is Java's answer to formed software using asynchronous messaging. It is one of the official specific

How can we include images in a web page using html and java, How can we inc...

How can we include images in a web page using HTML and Java script? Image in HTML Image in Javascript Images in JavaScript could be manipulated in several ways using the buil

Website for swapping and selling books, Website for swapping/selling books ...

Website for swapping/selling books Project Description: Seeking a website where students can sell and buy books. I want them to swap books as well. Payment options are requir

Developed an asteroids game, In the previous assignments, we have developed...

In the previous assignments, we have developed an Asteroids game. In this assignment, we are going to use the same codebase to develop a different gameplay. The inspiration for thi

Explain final fields, Explain final fields ? You may also declare field...

Explain final fields ? You may also declare fields to be final. This is not the similar thing as declaring a method or class to be final. While a field is declared final, it is

Develop wechat program to integrate with sugarcrm, Wechat and SugarCRM P...

Wechat and SugarCRM Project Description: Seeking the partner able to develop wechat program to integrate with SugarCRM. Wechat Official Account able to perform some functi

Programming, Byteland county is very famous for luminous jewels. Luminous j...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

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