View Single Post
Unread 4 Oct 2006, 23:48   #2
Phil^
Insomniac
 
Phil^'s Avatar
 
Join Date: May 2003
Posts: 3,583
Phil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus wouldPhil^ spreads love and joy to the forum in the same way Jesus would
Re: Wierd Java Error

public class hello, not class hello - that *should* make it compile and execute fine if its being picky about that - although when i tested your code it worked straight off for me without modification so im not sure why you are getting that error. Best guess is that theres something youve overlooked as me copypasting that code into notepad, saving as hello.java in c:\ and doing javac hello.java , java hello worked straight off

im using
C:\>java -version
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)
btw. Shouldnt make a difference but still...

Note that the filename (hello.java) has to be the same to the class name ( hello ) , minus the .java bit when you make the class public. Its also case sensitive iirc so be careful that you didnt name the file Hello.java
Youve done it here but its something to bear in mind when you do other programs
public class MyWonderfulClass -> MyWonderfulClass.java
public class MyOtherThing -> MyOtherThing.java
and so on
you can only have one public class in a java file, but if you want more then one class there you can make them private by specifying them as private.

furthermore, main is a static method so you need to create an instance of that class before you use any (nonstatic)functions or variables in it - granted you can get around that by making hellomessage static too but thats going to cause you problems later on when you want to do things with inner variables.

there isnt any need for System.exit(0) since the program terminates itself after running through all the code anyway
its a good idea to get into the habit of making classes start with capital letters, and variables/method names start with lowercase - though its not necessary for it to work
__________________
Phil^

Last edited by Phil^; 5 Oct 2006 at 00:10.
Phil^ is offline   Reply With Quote