• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Moose Greetings

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I realise that this will have come up before but I am not sure what to search for.

I have installed Java 1.6.0_24 and set my Paths (I think) I have followed the instructions for Moose Greetings (https://coderanch.com/how-to/java/how-to-create-java-program) When I compile I get an error stating:

MooseGreetings.java:1: class MooseGreeting is public, should be declared in a file named MooseGreeting.java
public class MooseGreeting {


Please could someone let me know what I am doing wrong, the text was copied from the webpage.

Many thanks
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Strange wrote:
MooseGreetings.java:1: class MooseGreeting is public, should be declared in a file named MooseGreeting.java
public class MooseGreeting {



Did you follow what the compiler error states?

And Welcome to JavaRanch
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really new to this and don't really understand what it says.

Sorry to be a pain
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me help you out: What is the name of the file you are trying to compile?
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thought I should post my code.

public class MooseGreeting {
public static void main(String[] args) {
System.out.println("moooooooo");
}
}
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MooseGreetings.java
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As the class is public- The file name containing the public class should have similar name as that of the public class name. In this case it should be MooseGreeting.java
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Strange wrote:MooseGreetings.java


Your class is MooseGreeting, but your file name is MooseGreetings (an extra "s")
 
Rob Strange
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Silly mistake, thank you.

 
Marshal
Posts: 76811
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Strange wrote: . . . Sorry to be a pain

You're not. Everybody makes that sort of mistake.

But you would have got the answer quicker if you'd given us more details, in this case the file name.
 
Grow a forest with seedballs and this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic