简体   繁体   中英

Error when trying to compile .java helloworld program using javac

I am new to Java programming and I am self learning.

After some initial trouble running javac I double checked the windows address and class paths and set them up for the correct directory paths. Problem solved because now when I type 'javac-version' I get the version showing that the java comilier is installed. So now I am trying to now run a Helloworld program from the command prompt in order to check basic functionality! ( I am not using Eclipse because I am not ready to ad an extra layer of complexity yet - plus I get different errors in this IDE) The program I used is as follows:

package Program Files.Java.jdk1.7.0_03.bin.namespace;

public class MyTestApplication{
    public static void main(String[]args){
        system.out.println("Hello World!");
    }
}

So at the command prompt I navigate to the bin directory (where my source code file is) which is: c:\\program files\\java\\jdk1.7.0_03\\bin\\javac MyTestApplication.java

And I receive the following errors back:

MyTestApplication.java:3: error ';' expected package program^files.java.jdk1.7.0_03.bin.namespace;

Please note: the symbol between the 'program' and 'files' is a '^' symbol but is situated bottom of the words rather than the top - I have had to used this symbol in its present 'top' location as My keyboard appears not have this symbol at the desired position capability.

So if any one can point out what I may of overlooked! this would be appreciated.

Package names cannot contain spaces and special characters

Package Naming Conventions

In your case, you probably want to leave your class in the default, nameless, package. Delete the package statement altogether.

Package cannot have spaces, like between Program and Files

package Program Files.Java.jdk1.7.0_03.bin.namespace;

package should be like this

package com.demo.first;

Every file can have one and only 1 package,
and is the 1st statement in the file, 
and all the classes, interfaces, etc in that file belong to only that package

EDITED :

system .out.println("Hello World!"); // system is wrong package.

System .out.println("Hi"); // System is right

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