10 Replies - 2642 Views - Last Post: 17 October 2005 - 11:36 PM Rate Topic: -----

#1 Israel   User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 833
  • Joined: 22-November 04

Class Error

Posted 17 October 2005 - 01:29 AM

Ok, I'm new to Java but I'm stuck on hello world. I've read a tutorial and I'm using Borland's JBuilder. I'm just trying to run this simple code:

package MyFirstProject;

public class HelloWorld
{
       public static void main(String args[]) throws Exception
       {
              System.out.println ("Hello world!");
              System.in.read();
       }
}



But I keep getting and error message that says:

"MyFirstProject.java": class HelloWorld is public, should be declared in a file named HelloWorld.java at line 3, column 1

Didn't I declare that HelloWorld is public when I said " public class HelloWorld"??? I've tried adding the .java extention in the code like in the error but didn't seem to help at all. Does anyone know what I'm doing wrong here?

Is This A Good Question/Topic? 0
  • +

Replies To: Class Error

#2 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Class Error

Posted 17 October 2005 - 02:05 AM

The problem is taht your file is called MyFirstProject.java and in Java each class must be declared in a file that has the same name as the class, so in your case HelloWorld.java.

I don't know JBuilder, so I can't tell you how could you rename your file via the IDE, but if you change
public class HelloWorld
...



to
public class MyFirstProject
...



it should run.
Was This Post Helpful? 0
  • +
  • -

#3 Israel   User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 833
  • Joined: 22-November 04

Re: Class Error

Posted 17 October 2005 - 03:09 AM

Ok, that got rid of the errors. So simple... I should have seen that. But now the compilier is wanting to know what kind of runtime configuration to use (which is NOT in the tutorial). I'm thinking about looking at some other Compiliers. What do you suggest?

This post has been edited by Israel: 17 October 2005 - 03:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Class Error

Posted 17 October 2005 - 04:21 AM

I am not sure what your IDE - its not the compiler - referring to as a runtime configuration, but try to go with the default, or if it means the command line options, then do not set anything.

If you are looking for another IDE, I am using Netbeans, and I've never had a problem with it, though I am sure, that I'm gonna receive now a lot of bashing that it is slow, ugly, and whatever, and use Eclipse (or some other IDE) instead. So I can recommend it, but I am using it with 1G ram (in dualchannel) and a decent processor, so I am not sure how useful it is on less powerful systems - I am writing this because I've heard people complaining who tried to run it on older machines.
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Class Error

Posted 17 October 2005 - 05:33 AM

Eclipse is alright...I've nopt had a great deal of usage experience with NetBeans, so I can't really comment on it...

Of course, you can just install the java interpreter and use notepad and the command line. :)
Was This Post Helpful? 0
  • +
  • -

#6 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Class Error

Posted 17 October 2005 - 05:41 AM

Yes, to learn the basics it might be even better to start with notepad and the command line, because you'll have a better understanding of what's going on :) And it might be even faster to create small examples, because you only have to copy & paste them - well, unless you are learning from a book- , and modifying them doesn't really require an IDE!
Was This Post Helpful? 0
  • +
  • -

#7 Israel   User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 833
  • Joined: 22-November 04

Re: Class Error

Posted 17 October 2005 - 04:44 PM

Ok, notepad and command line sounds good. Could anyone recommend a good tutorial to go with that? Preferable one online that's free... Thanks.
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Class Error

Posted 17 October 2005 - 04:50 PM

Do you mean a java tutorial? Or how to compile from the command line?
Was This Post Helpful? 0
  • +
  • -

#9 Rk47   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 11-October 05

Re: Class Error

Posted 17 October 2005 - 05:19 PM

I am sorta new with java as well. I use Dr.Java, its free and easy to use . http://drjava.sourceforge.net/
Was This Post Helpful? 0
  • +
  • -

#10 Israel   User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 833
  • Joined: 22-November 04

Re: Class Error

Posted 17 October 2005 - 08:31 PM

Quote

Do you mean a java tutorial? Or how to compile from the command line?


Both would be nice :D
Was This Post Helpful? 0
  • +
  • -

#11 1lacca   User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Class Error

Posted 17 October 2005 - 11:36 PM

Here you are both. I think you'll need the First Steps (Microsoft Windows) one.

This post has been edited by 1lacca: 17 October 2005 - 11:38 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1