error while writing <anonymous MyThread$1>: Access is denied" while compiling the below code

i am getting an error " error while writing <anonymous MyThread$1>: Access is denied" while compiling the below code"
import java.lang.*;
class MyThread
{
    public static void main(String[] args)
    {
        //Here we are using Anonymous Inner class
        //that implements a interface i.e. Here Runnable interface
        Runnable r = new Runnable()
        {
            public void run()
            {
                System.out.println("Child Thread");
            }
        };
       
        Thread t = new Thread(r);
        t.start();
        System.out.println("Main Thread");
    }
}
what is the reason for the error
Ganesh SadanalaAsked:
Who is Participating?
 
Jan LouwerensSoftware EngineerCommented:
Where are you compiling your java files? (ie, where are you storing your java files.)

Are they within the jre/jdk directories? You may not have permissions to write to those locations. Try moving your java files into your User directory (or sub-directory), and compile them there.
0
 
krakatoaCommented:
I don't believe what you have written is regarded as anonymous, but this is :

import java.lang.*;
class MyThread 
{
    public static void main(String[] args)
    {       
        new Thread(new Runnable(){
        
            public void run(){
                System.out.println("Child Thread");
            }
        }).start();
       
        System.out.println("Main Thread");
    }
}

Open in new window



BTW, your original code compiles.
0
 
CEHJCommented:
I don't know how you got that code in there in the first place (perhaps under another user's account) but it looks like you don't have write permissions on the directory into which the compiler wants to put it
0
 
krakatoaCommented:
<<import java.lang.*;>>  . . . not needed. Java.lang is always available by default.

As the experts have said, (some of) your write permissions are insufficient.
0
All Courses

From novice to tech pro — start learning today.