aspose file tools*
The moose likes Beginning Java and the fly likes New here, with a basic question to get started Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New here, with a basic question to get started" Watch "New here, with a basic question to get started" New topic
Author

New here, with a basic question to get started

Mitch Brink
Greenhorn

Joined: Jul 03, 2009
Posts: 3
Hello, all.
I've done some BASIC programming in the past, as well as some proprietary assembler with one company I worked for.
I haven't done any OOP programming, and I just got Head First Java.

I'm using JCreator as my IDE. I tried my first program, and it's giving me the error :

"--------------------Configuration: <Default>--------------------
C:\Users\Mitch\Documents\bottles.java:1: class BeerSong is public, should be declared in a file named BeerSong.java
public class BeerSong {
^
1 error

Process completed"

I'm assuming that it isn't the program itself, but some configuration problem with Java on my PC? But I don't know. Obviously.

Here's the code:

public class BeerSong {
public static void main (String[] args) {
int beerNum=99;
String word = "bottles";
while (beerNum >0) {
if (beerNum == 1) {
word = "bottle";
}

System.out.println (beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer.");
System.out.println("Take one down.");
System.out.println("Pass it around.");
beerNum = beerNum -1;

if (beerNum > 0) {

System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall.");


}
}
}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19788
    
  20

Mitch Brink wrote:C:\Users\Mitch\Documents\bottles.java:1: class BeerSong is public, should be declared in a file named BeerSong.java
public class BeerSong {
^
1 error

Process completed

In Java, every top level class (i.e. a class that is not nested inside another class) can have the public access modified, or no access modified. Private and protected are not allowed.

If you make your class public, then it must be placed in a file with the exact same name as the class (case sensitive!), plus the .java extension. In your case, bottles.java should be renamed to BeerSong.java. Not Beersong.java or beersong.java - really BeerSong.java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Mitch Brink wrote:Hello, all.
I've done some BASIC programming in the past, as well as some proprietary assembler with one company I worked for.
I haven't done any OOP programming, and I just got Head First Java.

I'm using JCreator as my IDE. I tried my first program, and it's giving me the error :

"--------------------Configuration: <Default>--------------------
C:\Users\Mitch\Documents\bottles.java:1: class BeerSong is public, should be declared in a file named BeerSong.java
...


I can't really provide a better answer than the one that was provided by the compiler.

it has nothing to do with your environment. The part of the sourcecode filename before .java should be the same as the primary class name.

p.s. like Rob said. He snuck in ahead of me.
Mitch Brink
Greenhorn

Joined: Jul 03, 2009
Posts: 3
Hey thanks, guys!
Ran just fine after that.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Mitch Brink wrote:Hello, all.
I've done some BASIC programming in the past, as well as some proprietary assembler with one company I worked for.
I haven't done any OOP programming, and I just got Head First Java.

I'm using JCreator as my IDE. I tried my first program, and it's giving me the error :
...


Wow, Basic and Assembler. That goes back a few years. I started much the same way. Did some basic and assembler back in the dark ages (early 1980s actually, on my Commodore 64), and some Fortran in university, then none at all for a very long time.
Mitch Brink
Greenhorn

Joined: Jul 03, 2009
Posts: 3
Yeah, I learned BASIC when I was about 12 (I'm 41 now) on a TRS Color Computer. I did so many fun things with it.
I've tried to learn OOP many times, but as an adult, I just never really had any drive or reason to learn like I did when I was a kid and wanted to make cool stuff happen on the screen.

But now my sons and I are playing with Lego Mindstorms, and there's a C-like language for that, plus I'd like to learn Java and maybe try to create some mobile apps.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Mitch Brink wrote:Yeah, I learned BASIC when I was about 12 (I'm 41 now) on a TRS Color Computer. I did so many fun things with it.
I've tried to learn OOP many times, but as an adult, I just never really had any drive or reason to learn like I did when I was a kid and wanted to make cool stuff happen on the screen.

But now my sons and I are playing with Lego Mindstorms, and there's a C-like language for that, plus I'd like to learn Java and maybe try to create some mobile apps.


same here. I got bored real fast with programming exercises that had no real value for me. But my lifetime hobby is chess, so that was the logical choice for a project that would keep me going for a long time. It's been a few years now off and on, and the project has come a long way from the early efforts. And there is still along way to go before it comes close to beating me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New here, with a basic question to get started