File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about pakages

 
sampath kumar yanagandla
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
what is the default package for a java program.

if we mention

it belongs to javaranch package.

what package it belongs to if we dont mention package name.
 
Abdel Olakara
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sampath,
Default package in java is unnamed package ie,source files did not contain a package statement. It includes all the files in current directory.

Regards,
-- Abdel Olakara
http://technopaper.blogspot.com
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's handy to write tiny example programs and maybe even simple homework in the default package, but it causes headaches to use the default package in larger systems. I only use it for quick disposable tests.
 
Diego Pedrosa
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you don't specify a package, the .class files will end up in either the same dir as the source (.java) files or in the dir you specified in javac -d option.

example:
using the default package, and the source code is in /java/src
when you compile it with 'javac MyApp.java' the class file will go to /java src (having MyApp.java and MyApp.class in the /java/src dir)

if you compile this with 'javac -d /java/class' the .class file will go to /java/class (now MyApp.java is in /java/src and MyApp.class is in /java/class)

now if you use a package, say 'package javaranch;':
your .class files will end up in a dir named javaranch (that will be either under /java/src or java/class based upon the '-d' compiler option used)
[ November 09, 2007: Message edited by: CoderX ]
 
Jason Shepherd
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a file as follows: (From the Packages Tutorial in the java homepage http://java.sun.com/docs/books/tutorial/java/package/QandE/packages-questions.html)

package mygame.shared;

public class Utilities {
// set DEBUG = false and compile to stop debug messages
final static boolean DEBUG = true;

public static void printMsg(String msg) {
if (DEBUG) {
System.out.println(msg);
}
}
}

Placed the file in a directory 'myDirectory'

From the command line in the myDirectory folder I run:
javac Utilities.java

From the tutorial, and what you mentioned above I think the resulting Utilites.class file should be placed in a subdirectory of myDirectory name mygame/shared but it is just created in the current directory.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic