• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package class.src

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic