aspose file tools*
The moose likes Beginning Java and the fly likes package class.src Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package class.src" Watch "package class.src" New topic
Author

package class.src

Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
Hi

This is my source code:


package class.src;

public class MyFirstApp {

public static void main (String[] args) {

System.out.println("Hello World") ;

}
}

I tried to compile like that:

javac -d class/src MyfirstApp.java

It did not work. I do not understand packages properly.

Best Regards
Urs


SCJP 1.4
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1344
    
  12
Hi,

A few questions which may help you get started:

What error messages are you getting? (And what do you think they mean?)
What would happen if you renamed your package to example.src?



If you are in the directory of your source code (MyFirstApp.java), and compiled using



where would you find your MyFirstApp.class file?

And where would it be if you compiled using



(actually, I don't know if that last line would work in Windows - it is the syntax I use on my computer).

Have you created the classes/src directories before you compile?
[ March 16, 2007: Message edited by: Katrina Owen ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Easiest thing to do is leave out the package declaration. I wrote about that on another thread you were on this morning.

CR
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
. . . and you can't call a package class.src. The word "class" is a reserved keyword, which can't be used in that context.
[ March 16, 2007: Message edited by: Campbell Ritchie ]
Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
Hi

Thank you. Now I could compile the following code:


package example.src;

public class MyFirstApp {

public static void main (String[] args) {

System.out.println("Hello World") ;

}
}


I have done i like that:

javac -d . MyFirstApp.java

How can I execute the programm? What do I have to enter in the command line?

Regards
Urs
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Urs, please have a look at The Java Tutorial. You can find answers to basic questions there very quickly, at least quicker than waiting for people to answer your posts on the forums here.

For this particular problem, look at Lesson: Packages. Also read the JDK documentation, especially the documentation of the Java application launcher.

Go to the directory that contains your example directory and type this:

java example.src.MyFirstApp
[ March 19, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
Jesper, thank you for the answer. Sometimes it is not easy to find the right information. Now I got it.

Best Regards
Urs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package class.src
 
Similar Threads
accessibility doubt
constructor
package urgent!
Referencing a class in a default package
Packages