Skip to main content
added 49 characters in body
Source Link
pb2q
  • 59.9k
  • 19
  • 150
  • 152

I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't ana (click-launchable) executable, and - without some acrobatics - neither is a compiled class.class file. You: you shouldn't expect to double-click either and start your program.

In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.

To just run your code outside your IDE, you can invoke the java VM on the command line:

c:\> java HelloWorld

As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.

But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files. If you're using a specific IDE like Eclipse or NetBeans, use that to refine your search.

I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't an executable, and neither is a compiled class file. You shouldn't expect to double-click either and start your program.

In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.

To just run your code outside your IDE, you can invoke the java VM on the command line:

c:\> java HelloWorld

As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.

But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files.

I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't a (click-launchable) executable, and - without some acrobatics - neither is a compiled .class file: you shouldn't expect to double-click either and start your program.

In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.

To just run your code outside your IDE, you can invoke the java VM on the command line:

c:\> java HelloWorld

As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.

But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files. If you're using a specific IDE like Eclipse or NetBeans, use that to refine your search.

Source Link
pb2q
  • 59.9k
  • 19
  • 150
  • 152

I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't an executable, and neither is a compiled class file. You shouldn't expect to double-click either and start your program.

In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.

To just run your code outside your IDE, you can invoke the java VM on the command line:

c:\> java HelloWorld

As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.

But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files.