HOW TO EXECUTE A JAVA PROGRAM:

Step-1: Is Java available in your Computer?

Please check whether java is available in your computer.

go to 

MyComputer => C drive => Program Files => Java => JDK1.x => bin

By this, Java is available in your computer, Otherwise please install java

Then copy this URL

C:\Program Files\Java\JDK1.x\bin
(Note: JDK1.x means your installed version like JDK1.6 or JDK1.8)

Step-2: Set Java Path (Java Environment)

go to command prompt (cmd)

and type 

>javac

Then it results like

"javac is not recognized as an internal or external command"

it means java path setting is not done, so you need to

go to

Mycomputer (right click) => Properties => Advanced System settings => Environment variables 
=> System variables => new
variable name  : path
variable value  : C:\Program Files\Java\JDK1.8\bin;
Then click ok => ok => ok

By this path setting is over

close the current command prompt and open it again, Then type

>javac

Then it will shows different paths.

Step-3: Edit and Save Java program

Edit your java program in Notepad Then create a folder in C drive like ECE401 save your file using .java extension within double quotes as

"Filename.java"

in the ECE401 folder

Note:
It is better to use the same name for file name and java class name

Step-4: How to execute a java program

Open command prompt then go to your folder like

C:\ECE401>

Then compile your java program using the command

C:\ECE401>javac Filename.java

Then run your java program using the command 

C:\ECE401>java classname

It gives output.












No comments:

Post a Comment