Skip to main content

A simple problem about HelloWorld

5 replies [Last post]
Joined: 2008-08-17

package Mypackage;
class Main
public static void main(String avgr[])

How to compile and run this program?
Note: the class Main is in the package Mypackage
Do I need to create a folder named 'Mypackage' ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-09-03

Create a folder with name of the package
Place all the java files written under this package here.
Now while compiling compile from a higher directory above the directory with package name.
for ex:if you create under myPack
create a folder myPack
put here
now come out of the directory and compile using
javac myPack/
if you compile in the the MyPack dir itself,compiler says File not found

Joined: 2004-06-03

Hmmm... I've been going through the package documentation here:

and, I agree, it doesn't really give you a good example of how to compile a program that has been created package -- this is unfortunate since all Swing examples now use packages. Here is the current index for the Package lesson:

Creating and Using Packages:
Creating a Package
Naming a Package
Using Package Members
Managing Source and Class Files
Summary of Creating and Using Packages
Questions and Exercises: Creating and Using Packages

I wonder what you collectively think about adding a page after "Creating a Package" and before "Naming a Package" that shows a simple example just like what we have here?



Joined: 2008-08-24

Yes Sharon I completely agree.

I think the whole lesson set could be improved by interweaving with more worked examples.

In my thread about the life of variables I suggested that the "theory" section on classes and objects should be tied in with the "practical" section Introduction to Swing.

I also believe the "theory" section on packaging programs in jar files, could be tied in with practical examples in Swing/NetBeans.

Joined: 2008-08-17

I mean compile and and run it in command line.

I tried:
java Main
java Mypackage.Main
but they doesn't work. Can somebody help me?

Joined: 2007-03-19

u need javac.exe for compile (javac [ options ] [ sourcefiles ] [ @argfiles ])

more you can read at