my dog learned polymorphism*
The moose likes Beginning Java and the fly likes making/calling a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "making/calling a package" Watch "making/calling a package" New topic
Author

making/calling a package

salvador rcn
Ranch Hand

Joined: Feb 18, 2004
Posts: 51
package com.javaranch; // does it making a package or calling a package ? but calling needs // import.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class PostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>\n <body>\n");
out.println(" <h2>\n Hello World\n </h2>\n");
out.println(" </body>\n</html>\n");
out.flush();
out.close();
}
}
Leo Deegan
Greenhorn

Joined: Jun 15, 2004
Posts: 12
Hi Salvador -

The package declaration indicates the package location of your class. It does not execute a call to the package (in fact, I don't believe packages are executable). In your example, you do not need to import the package com.javaranch.

--Leo
salvador rcn
Ranch Hand

Joined: Feb 18, 2004
Posts: 51
package com.javaranch; // it is declaring only ?

import java.io.*; // it is calling only ?

wwhat is the difference ?
Leo Deegan
Greenhorn

Joined: Jun 15, 2004
Posts: 12
The package line says that your PostServlet class is in the com.javaranch package, which means it is in the subdirectory com/javaranch relative to your source root directory.

If you have the import java.io.* line, you are indicating that your class can use the java.io package classes without fully qualifying their names. If you notice, your class can use a PrintWriter without having to call it java.io.PrintWriter each time you use the PrintWriter name.

When you declare a package, you are not calling the package. When you import the set of classes in a package (e.g., import java.io.*), you are also not making a call.
Jeff Pavlocak
Greenhorn

Joined: Apr 26, 2004
Posts: 16
The package statement allows you to group several classes and interfaces together into a "package". You can then reference the classes you created in that package in other java programs by importing the package.

Example:

package com.myNewPackage;

import com.javaranch.*;

public class myNewClass
{
PostServlet ps = new PostServlet();

// more code...
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: making/calling a package