Basic of Create and Execute the java Program
First you need to choose a text editor like Notepad, Notepad++, Wordpad and etc, I recommended to use the Notepad++.Write a Simple Java Program and Save
After open your editor write a java program and save it same as class name (class simple) with .java extension, your file name should like classname.java.
File_name.java
where
File_name – it is a file name which used in main method.
Java – extension, it indicate the file type.
The above one is a source file. If the program contains multiple classes, which class has main method, that class name is saves as the file name.
Set Path in Java
Before execute the java program you should set the JDK installed path. All you need to find the JDK bin folder and copy the path and paste by the following screenshot. In default JDK Bin folder in C:\Program Files\Java\jdk1.6.0\bin.
Paste the above copied path to Environment Variable. Right click on my computer => properties => Advanced => Environment
Variables.
After click on the Environment Variables Find the path in system variable.
Click Edit and move to end of the line put semicolon (;) - and
paste previously copied path (C:\Program Files\Java\jdk1.6.0\bin) then click ok.
Move to program directory
After create the program and set the path open command prompt (Run=>cmd=>Enter), you can see the window like below screenshot.
Move to program saved directory through DOS command, like below.
Compile the Java Program
The source code should be compiled and generate the class file like below syntax.
Javac file_name.java
Where
javac – name of the java complier.
Filename – name of the source file, which is already saved in your system.
When compile the java program, java compiler can generate the class file. This class file contain the byte code. Java compiler is automatically named for the class file.
The class file is look like the above marked image.
Execute the java program
When we execute the java program the program will execute from the class file (sample.class), source code no need.
java File_name
Where
Java – name of the java interpreter.
Filename - name of the source file, which is already saved in your system.
Java interpreter can generate the machine code from the byte code.
0 comments:
Post a Comment