This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package class.src

 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . 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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper, thank you for the answer. Sometimes it is not easy to find the right information. Now I got it.

Best Regards
Urs
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic