Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Class world is public?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Thanked 0 Times in 0 Posts

    Unhappy Class world is public?

    so I have just gotten started with java programming.. and I have been following a guy on youtube, (thejavahub) and have downloaded netbeans & JDK, well, ive followed his programming while he does it on screen, but my code keeps coming up with the error "Class world is public, should be declared in a file named World.java" EVERY time I put in "public class world {" it keeps yelling at me for the word "world" and I cannot figure out what I was doing wrong, I have rewritten the script over and over, to make sure im following the youtuber's EXACT words.. then I gave up, & the next day I logged onto netbeans, and found an example of coding, so I went into it... and their example was broken with the EXACT same thing.. "Class world is public, should be declared in a file named World.java" in it was in their EXAMPLE coding! so it doesn't make any sense, ill put the example coding in and ill you can tell me what you guys think, any feedback would be EXTREMELY appreciated! thank you.
    this is the code

    package thejavahub;
    import java.awt.*;
    import javax.swing.ImageIcon;
    //this is where it is broken! ;O
    //  |       |      |
    //  V       V     V
    public class world {
        private Rectangle[] blocks;
        private Image[] blockImg;
        private final int arrayNum = 500;
        //Block images
        private int x, y, xDirection, yDirection;
        //Map navigation
        static final int PAN_UP = 0, PAN_DOWN = 1, PAN_LEFT = 2, PAN_RIGHT = 3;
        public World(){
            BLOCK_DIRT_TOP = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_topDirt1.png").getImage();
            BLOCK_DIRT = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_dirt1.png").getImage();
            BLOCK_STONE = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_stone.png").getImage();
            BLOCK_SKY = new ImageIcon("C:/Users/Oliver/Documents/NetBeansProjects/TheJavaHub/src/thejavahub/images/tile_sky.png").getImage();
            blocks = new Rectangle[500];
            blockImg = new Image[500];
        private void loadArrays(){
            for(int i = 0; i < arrayNum; i++){
                if(x >= 500){
                    x = 0;
                    y += 20;
                if(i >= 0 && i < 100){
                    blockImg[i] = BLOCK_SKY;
                    blocks[i] = new Rectangle(x, y, 20, 20);
                if(i >= 100 && i < 125){
                    blockImg[i] = BLOCK_DIRT_TOP;
                    blocks[i] = new Rectangle(x, y, 20, 20);
                if(i >= 125 && i < 225){
                    blockImg[i] = BLOCK_DIRT;
                    blocks[i] = new Rectangle(x, y, 20, 20);
                if(i >= 225 && i < 500){
                    blockImg[i] = BLOCK_STONE;
                    blocks[i] = new Rectangle(x, y, 20, 20);
                x += 20;
        public void draw(Graphics g){
            for(int i = 0; i < arrayNum; i++){
                g.drawImage(blockImg[i], blocks[i].x, blocks[i].y, null);
        public void moveMap(){
            for(Rectangle r : blocks){
                r.x += xDirection;
                r.y += yDirection;
        public void stopMoveMap(){
        private void setXDirection(int dir){
            xDirection = dir;
        private void setYDirection(int dir){
            yDirection = dir;
        public void navigateMap(int nav){
                    System.out.println("default case entered... Doing nothing.");
                case PAN_UP:
                case PAN_DOWN:
                case PAN_LEFT:
                case PAN_RIGHT:
    Last edited by jps; August 16th, 2013 at 03:47 PM. Reason: code tags

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Class world is public?

    Java and Java programmers are case sensitive. The public class World should begin with a capital 'W' and should be in a file named World.java, also beginning with a capital 'W'.

Similar Threads

  1. Java, calling another public class from within the main class giving problems.
    By RandomGaisha in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 26th, 2012, 02:30 PM
  2. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  3. How can you get the compiler to run more than one public class?
    By tai8 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 19th, 2012, 04:27 PM
  4. What's difference between public class and abstract class?
    By Java95 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 24th, 2012, 07:37 AM
  5. Public class help/error
    By Plural in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 11th, 2010, 05:22 PM