Articles → Java → Create Compile And Execute Your First Java Program
Create Compile And Execute Your First Java Program
Software Requirement
Prerequisite Knowledge
Installation Of JDK
Create Your First Program
- Create a folder on any location to store java code files. Let us say a folder ‘files’ is created on c drive.
- Open a notepad (or any text editor) and paste the following program
class MainClass {
public static void main(String args[]) {
System.out.println("Hello World");
}
}
- Save the file with the name MainClass.java (you can give any file name, but the file extension should be .java) on the location ‘C:\files’.
Code Explanation
- A class MainClass is created.
- Inside the MainClass we have a method called main method (program execution starts with main function).
- Inside the main method we are printing a string ‘Hello World’.
Compile Your Program
- Open command prompt and go the location ‘C:\Program Files\Java\jdk1.7.0_07\bin’.
- Write following command in command prompt
javac c:\files\MainClass.java
- Press enter.
Execute Your Program
- Open command prompt (if the command prompt opened to compile the program is not closed).
- Go to the location ‘C:\files’.
- Write the following command in the command prompt
- Press enter.
Output
Click to Enlarge