Home   |   About   |   Terms   |   Contact    
A platform for writers

How to Compile and run a Java Program?


☯ All Java Articles     ☯ All Articles

Popular Google Pages:

◕ Send your story to RiyaButu.com and get ₹ 500/- Details..

◕ Bengali Story writing competition. Details..

This article is regarding How to Compile and run a Java Program?
Last updated on: .

◕ How to Compile and run a Java Program?

- Java source code is always stored in a file with the extension .java.
Generally we use text editor like notepad or notepad++ to write our source code.
For an example, we can store our source code in a file named as myJavaprogram.java.

After we create a source code file for our program, first we need to compile our source code using the java compiler.
Then we can run that Java Program.
Java compiler comes by-default with the JDK ( Java Development Kit ).

◕ To compile and run the myJavaprogram.java file please follow the following process:

- Make a folder in the c:\ drive and give it a name. Say we named the folder as test.

- Put the myJavaprogram.java file in this folder.
And put the following Java code on it and save it.

public class apples{
public static void main (String args[]){
system.out.println("I love APPLE!");

- Go to run box ( Window button + R )

- Type cmd and press enter.

- Console window will open

- Type cd\ and press enter.
This will bring us on the C:\ drive.

- Type dir and press enter.
This will give us the all the directory list of the C:\ drive.

- Type cd test and press enter.
This means, we want to Chang Directory to test.
In simple, we want to go on the test folder.

- Type dir and press enter.
Again this will open all the file names which are there on the test folder.

- Type javac myJavaprogram.java and press enter.
This will compile the Java file myJavaprogram.java
A new compiled file will appear with the name of the class (here it is apples) with an extension of .class.
So here the new compiled file will be apples.class.

- Type java apples and press enter.
We will get the result I love APPLE!

Congrats! You have run your 1st Java Program successfully.

Please note:
Now-a-days we can test Java programs through different testing tools.
But for learning the above process is the best.

Related Java articles:
What is Java? Where we can apply Java?
Why Java is a Machine Independent Program? What is Machine Independent Program?
Root Directory of Java
How to Compile and run a Java Program?
What is .class file in Java?
What is variable in a program?
What is identifier in Java?
Integer data types in Java?
What is Primitive Types in Java?
How to declare constant variables in Java?
Why should we declare the initial value of a variable in Java?
Use of Underscores to write an integer in Java

Top of the page

Amazon & Flipkart Special Products


Top of the page