File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes about pakages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "about pakages" Watch "about pakages" New topic

about pakages

sampath kumar yanagandla

Joined: Apr 29, 2007
Posts: 13
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

Joined: Jan 10, 2007
Posts: 6
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.

-- Abdel Olakara
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Diego Pedrosa

Joined: Nov 09, 2007
Posts: 8
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.

using the default package, and the source code is in /java/src
when you compile it with 'javac' the class file will go to /java src (having 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 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 ]

SCJP 5.0 (Yeah!! finally...)<br /> <br />There are 10 kinds of people...<br />The ones that understand binary,<br />and the ones that don't. ;P
Jason Shepherd

Joined: Nov 28, 2007
Posts: 1
I created a file as follows: (From the Packages Tutorial in the java homepage

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) {

Placed the file in a directory 'myDirectory'

From the command line in the myDirectory folder I run:

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:
subject: about pakages
It's not a secret anymore!