Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java confusion  RSS feed

 
Ma xwell Spiller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me on this. I'm using the book Head first Java 2nd edition 5.0. Im trying to compile this on NetBeans IDE 5.5

public class MyFirstApp {


public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("The World");
}

}

It keeps saying
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Alex\myfirstapp1\build\classes
C:\Documents and Settings\Alex\myfirstapp1\src\myfirstapp1\Main.java:1: class MyFirstApp is public, should be declared in a file named MyFirstApp.java
public class MyFirstApp {
1 error
BUILD FAILED (total time: 0 seconds)
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I think that the error message means that the java source file needs to have the same name as the public class of the file with a .java suffix. Namely, the source file should be named: "MyFirstApp.java".

-- Kaydell
 
Ma xwell Spiller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that too, and I did that. Unfortunately it had no effect.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make sure you have deleted any .class files that might be lying around. if the first attempt created the .class file with the wrong case, your subsequent compiles might just continue using that bogus file name.
 
Ma xwell Spiller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only one file for this project, and the filepath is clear.
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just bought the book and tried the same thing.

I ran the first program successfully by doing this:

New File>Java Classes>Empty Java File

A quick type of the code and it ran for me in Netbeans. Hope this helps.

Nate
 
Bert Bates
author
Sheriff
Posts: 8945
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you NetBeans users will be the death of us all

I really, really recommend that you lay off the IDEs for a while and use the command line. You'll get your Numchuk skills down much better that way
 
Jae Stryker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Bert - IDE's whilst making our lives as programmers a lot easier - When learning a language such as Java, using just a text editor to write the code means that you don't get confusted by what is being performed by the IDE as you're a are working in a pure native environment.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!