Firstly your file for a java class must end in .java which you have
discovered already, then each file can have only one public class, so
you separated them off into files by themselves which is the right
thing to do as well. The class name and the file name must match up so
that the file MyFirstApp.java contains the class: public class
MyFirstApp { ... }.
So after that the only thing left to do is to declare them all as
belonging to the same package. At the top of each file before any
other code (you can have // or /* */ comments before but no actual
code) put the keyword package and follow it with whatever package name
you want to use. E.g.:
/* MyFirstApp
* Author: lucky314159
* Date: 20100102 */
package myfirstapp;
Do this with each file in your application and you won't need to
import the classes.
The above approach is good programming practice, but you can also
compile everything without the package keyword and package name and
then each file would automatically go in what is called the 'default
package' which would effectively work the same, so again you don't
need to import anything.
On 02/01/2010, at 1:48 PM, JKid314159 wrote:
> Hi:
>
> I am compiling the following:
>
> javac MyFirstApp.txt
>
> I receive the following message?
>
> error: Class names, 'MyFirstApp.txt',are only accepted if
> annotation processing is explicitly requested.
>
> I tried to save the file as MyFirstApp.java and then compiled
> javac MyFirstApp.java
>
> This produced a number of compiler errors.
>
> Then I had two public class plus another class with main. The
> compiler messaged the two other public classes should be in a separate
> file but I was unsure how to import them to the class file with the
> main class.
>
> Any suggestions on this.
>
> Thank you.
>
> --
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en