aspose file tools*
The moose likes Beginning Java and the fly likes absolute newbie compile error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "absolute newbie compile error" Watch "absolute newbie compile error" New topic
Author

absolute newbie compile error

Chris Lucier
Greenhorn

Joined: Nov 18, 2009
Posts: 3
OK so I was a programmer in a past life, mostly C and VB. Getting into Java for personal reasons. Picked up a copy of Head First Java 2nd Edition as it looks cool. Started into Chapter 1. Downloaded the JDK 6 R17. Installed it all. Changed the path variable to add my Java Bin. then I typed an example in notepad:



I saved as Loopy.java. Went to the command line and typed "javac Loopy.java" and I get a compile error:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd C:\Documents and Settings\Administrat
or\My Documents\Java Code\HFJR2CH1

C:\Documents and Settings\Administrator\My Documents\Java Code\HFJR2CH1>javac lo
opy.java
loopy.java:1: class Loopy is public, should be declared in a file named Loopy.ja
va
public class Loopy {
^
1 error

C:\Documents and Settings\Administrator\My Documents\Java Code\HFJR2CH1>


not sure what to do now...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Chris Lucier wrote:
C:\Documents and Settings\Administrator\My Documents\Java Code\HFJR2CH1>javac lo
opy.java
loopy.java:1: class Loopy is public, should be declared in a file named Loopy.ja
va
public class Loopy {
^
1 error


javac Loopy.java (not loopy.java) . if you get further problem let me know. and welcome to javaranch
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
loopy.java:1: class Loopy is public, should be declared in a file named Loopy.ja
va


Every .java file could contain maximum 1 public class (but many private classes).
The name of the public class has to be same as the name of .java file.

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ireneusz Kordal wrote:
Every .java file could contain maximum 1 public class (but many private classes).


many private classes ? you cant declare a class as private except inner classes(nested classes). but yes you can delclare one class as a public[if you are declaring a public class in a file ,then that file should be named as that class]
Chris Lucier
Greenhorn

Joined: Nov 18, 2009
Posts: 3
Thanks that worked.... argh see I am rusty have to remember that caps matter (the BIG difference of working in a text editor versus an IDE is actually knowing the syntax and capitalization (i mistakenly capped something else in the code, once fixed bingo it worked)).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Welcome to JavaRanch

I have gone back to your post and added CODE tags; have a look and see how much better the post looks. Please remember the code button.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: absolute newbie compile error