This question already has an answer here:
- Java Access Denied 3 answers
I use Windows 7 and recently installed JDK (jdk1.8.0_05). (I've also installed JRE) As I'm new to Java, I complied the Hello World Java code given on Official Java Website:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
I saved the file as C:\HelloWorldApp.java
And then in command prompt, I typed
javac HelloWorldApp.java
I got the following message:
C:/HelloWorldApp.java:5: error: error while starting HelloWorldApp: C:\HelloWorldApp.class (Access is denied)
class HelloWorldApp{
^
1 error
PS: I even tried making the class public. Also, I've specified PATH variable as C:\Program Files\Java\jdk1.8.0_05\bin
What may be the solution?
Add
public
keyword before theclass
keyword. That is, change:to
The class that contains main method must be declared as public.