0

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.

3 Answers 3

5

Package names cannot contain spaces and special characters

Package Naming Conventions

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks, O I see, What might those special characters be?
In your case you can't use spaces in package names: docs.oracle.com/javase/tutorial/java/package/namingpkgs.html
O.K now I have corrected what you said and now get a different error: The little pointy arrow thing now points at the full stop between jdk1^.7.0_03. and the orginal error for the space has gone
the reason is that when you declare a package as a.b.c , it expects a folder c inside a folder b which is inside a. Also you cant have numbers in pacakge names
Congratulations to all that helped me: We appear to have some success... the MyTestApplication.java has now compiled into a .class file. - I corrected the owner file permissions for the bin folder but when I try to run the .class file using java command I have new errors
|
1

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

3 Comments

Thanks. I did what you said and deleted the package and replaced with default as below: but now get 'package does not exist' error and the little arrow thing points to the fullstop after the system class in: system.out.println("Hello World");
could this mean some of the source files are missing?
Congratulations to all that helped me: We appear to have some success... the MyTestApplication.java has now compiled into a .class file. - I corrected the owner file permissions for the bin folder but when I try to run the .class file using java command I have new errors
1

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

9 Comments

Thanks. I did what you said but now get 'package does not exist' error and the little arrow thing points to the fullstop after the system class in: system.out.println("Hello World");
More precisely the error says ' Package system does not exist'
Thanks @Kumar Vivek Mitra but that is Weird!! you only changed the argument statement- do not see how that was the problem. But I changed to how you said and the error seems to have gone . But Now I have another new error: '' error while writing MyTestApplication (Access is denied)
I checked the permissions and the system has full control!
O I see the 'system' became: 'System'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.