简体   繁体   中英

Java command prompt compile error

I started learning Java lately, and trying to make my first program based on book which is the "Hello World" program. After writing the script on notepad, i try to compile it on the command prompt and then this notice appeared.

first I type: javac javaCode.java

then there a notice said:

    javaCode.java:2: error: <identifier> expected
    public class static void main(string[] args) {
                ^
    javaCode.java:6: error: reached end of file while parsing
    }
     ^
    2 errors

I don't have any ideas what going on here so please give detailed information and how to fix this thing.

public class static void main(string[] args)

Remove class

  public static void main(string[] args) 

class is different from method. main method syntax doesn't contain class .

Your main method needs to go inside a class: Java won't let you do things any other way.

Try:

public class HelloWorld{
    public static void main (String[] args){
        //your code goes here
    }
}

this the basic structure for a simple program like this.

the class identifier, has to be on the declaration of the class.

public class Caculator {
    public static void main(String[] args) {
        // Your code here
    }
}

It probably should be:

    public class JavaCode {

      public static void main(String[]args){

      }

    }

That should do it. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM