尝试使用 javac 编译 .java helloworld 程序时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10984408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:18:44  来源:igfitidea点击:

Error when trying to compile .java helloworld program using javac

java

提问by Mr_leighman

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

我是 Java 编程的新手,我正在自学。

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:

在运行 javac 遇到一些初始问题后,我仔细检查了 Windows 地址和类路径,并将它们设置为正确的目录路径。问题解决了,因为现在当我输入“javac-version”时,我得到的版本显示已安装 java comilier。所以现在我试图从命令提示符运行一个 Helloworld 程序,以检查基本功能!(我没有使用 Eclipse,因为我还没有准备好添加额外的复杂层 - 而且我在这个 IDE 中遇到了不同的错误)我使用的程序如下:

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

因此,在命令提示符下,我导航到 bin 目录(我的源代码文件所在的位置),即: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;

MyTestApplication.java:3: 错误 ';' 预期的包程序^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.

因此,如果有人能指出我可能忽略的内容!这将不胜感激。

回答by Suraj Chandran

Package names cannot contain spaces and special characters

包名不能包含空格和特殊字符

Package Naming Conventions

包命名约定

回答by bmargulies

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

在您的情况下,您可能希望将类留在默认的、无名的包中。完全删除包语句。

回答by Kumar Vivek Mitra

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("世界你好!"); // 系统是错误的包。

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

System.out.println("你好"); // 系统正确