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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
krakatoaCommented:
Closed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.