简体   繁体   English

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

[英]Error when trying to compile .java helloworld program using javac

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. 在运行javac遇到一些最初的麻烦之后,我仔细检查了Windows地址和类路径,并将它们设置为正确的目录路径。 Problem solved because now when I type 'javac-version' I get the version showing that the java comilier is installed. 解决了问题,因为现在当我键入“ javac-version”时,我得到的版本表明已安装Java comilier。 So now I am trying to now run a Helloworld program from the command prompt in order to check basic functionality! 因此,现在我试图从命令提示符下运行Helloworld程序,以检查基本功能! ( 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: (我没有使用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 ';' MyTestApplication.java:3:错误';' expected package program^files.java.jdk1.7.0_03.bin.namespace; 预期的程序包^ 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语句。

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 .out.println(“ H​​ello World!”); // system is wrong package. //系统包装错误。

System .out.println("Hi"); System .out.println(“ H​​i”); // System is right //系统正确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Eclipse IDE可以完美地编译和运行Java程序,但是当我使用“ javac”时,会导致错误 - Using Eclipse IDE can compile and run the Java program perfectly but when I use 'javac' it is resulting to Error Java:尝试编译Hadoop程序时找不到com.sun.tools.javac.Main - Java: com.sun.tools.javac.Main not found when trying to compile Hadoop program 尝试通过javac编译.java文件时遇到麻烦 - Trouble when trying to compile a .java file through javac 尝试编译程序时出错 - Error when trying to compile the program 当我从 Codename One HelloWorld 教程运行 Codename One HelloWorld Java 程序时,出现错误 - When I run the Codename One HelloWorld Java Program from the Codename One HelloWorld Tutorial, I get an error 尝试编译时出现Java错误 - Java Error when trying to compile 尝试编译简单的Java程序时出现NumberFormatException - NumberFormatException when trying to compile a simple java program Java:新手“javac:invalid flag”编译错误 - Java: newbie “javac: invalid flag” compile error 如何使用javac编译java包结构 - How to compile java package structures using javac 当我试图通过“javac”命令编译一个file.java时,它给了我“找不到文件”错误,虽然我已经完成了JDK的路径和变量 - When I am trying to compile a file.java by “javac” command, it gives me “file not found” error, though I have done the path and variable of JDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM