Home » General » Java program development, compilation and execution
develop run first java program

Java program development, compilation and execution

Hello, guys… We learned something about Java programming language in the last two articles – Sun Microsystem Java uses, basic information and history and JAVA SDK : Download, installation and configuring process with windows

In this post, you will learn how to develop and run Java program on your machine. I think that all Java beginners should start learning Java programming language from this basic program. With the help of this basic program, you will learn basic knowledge of the Java programming language.

First, we will have got to know answers of all these question which is given below. So basically what will you learn in this article???

1. How to create a Java source file?

2. How to compile Java source file?

3. How to run the Java program?

First, you should know for enhancing your knowledge. Something about a Java source file, compilation process and running process of Java program.

What is a Java source file?

– Java source file contains code. This code follows the syntax of Java, which is written by developer or you. Only developers are understood Java source file code.

What is compile process?

– In this process, source file of Java takes by Java compiler that is ‘javac’. The Javac compiler translates this Java source file into the bytecode. It means that javac changes the programming language into machine language. These instructions only understand by the Java virtual machine (JVM). After compilation process, JVM makes class file in java. If your filename is A, means its source file is A.java and a class file is A.class.

What is running process?

– Run the program with the help of JVM in your command prompt. And see the output of this program. This process is called, the running process of Java. bytecode files loaded into the Java Virtual Machine, and executing its JVM instructions starting from the entry point of the specified class.

To create an application in Java, we should have some tools

1. A text editor (Notepad or Notepad++). But, notepad++ is a good text editor for Java. Download Notepad++ from here

2. JAVA SDK 8 (Java SE Development Kit 8), Download JAVA SDK 8, Go to this link.

Now, we have all tools and some knowledge for developing the Java application and run the Java program. We will develop a Java application in three steps

Create a Java program source file, compile and run 

1. Create a Java source file 

We have notepad++ or notepad editor for creating a source file of Java. We write Java source code in notepad++. Follow these steps

1. Open the notepad++ >> File >> New (create a new file) or CTRL+N.

2. Write a Java code carefully on this new file. Because, Java is case-sensitive language. Java syntax is more important. We create a source file and save (CTRL+S) the in any location of your computer. Remember the location of the file. In this example, we save the file in “C:\Users\username\Desktop\fun.java”. Your file extension is .java this location. fun.java Source code is given below

Class fun                                                                            // fun is class name which is same as filename


public static void main ( String args[] )                        // execution of the program starts from main method


System.out.println(“We are learning java”);       // this line prints the string



Every Java program has at least one class. And it’s necessary that your class name is similar to the your file name. For example – You create a Java file fun.java. So, your class name should be  A.

We are not describing you each and every line of this example at this moment. First, we compile this program and see the output of the program. After compilation of this program, we will describe you. Now, we will see the compilation of Java.

2. Compilation of Java program 

To compile the Java program, follow these steps-

1. Open the command prompt (windows+R).

2. Go to the location of the Java file in the command prompt with the help of some command. Our file location is “C:\Users\username\Desktop\fun.java”. We have cd (Change Directory) commands for select the exact directory in command prompt.

Example – We start the command prompt

–> Suppose that When we open the command prompt. We get this path on the command prompt “C:\Users\username”.

–> If we want to change the path and go on this path “C:\Users\username\Desktop\fun.java” for compilation of Java program. Write this command after C:\Users\username path. Below two lines of command prompt lines –

C:\Users\username> cd desktop and press the enter button


Now, you are in this path “C:\Users\username\Desktop\”.

3. Now, we are ready for compiling the Java file fun.java. Write the javac fun.java after this path. Javac is the Java compiler.

C:\Users\username\Desktop\javac fun.java and press the enter.

Now, your Java file compilation process completed. And you get fun.class file.

4. Finally, run the fun.java program file in command prompt.

C:\Users\username\Desktop> java fun and press enter
Now, you can see the output of the program.

Loading bytecode files intovthe JVM, and executing its JVM instructions starting from the entry point of the specified class.

We are learning Java

Understand each line of program 

You are a little bit familiar with the Java programming syntax from above code. We describe each and every line of the program step by step. It’s important to learn before compiling the Java program, meaning of the line.

Class Declaration 

Class is the combination of variables and methods. If a class defines public, it means public type of class accessible by any object of the program in anywhere in the Java program. There are four types of accessibility in the class – public, private, protected and default.

Syntax –  class fun {

The main method 

Approx. In every programming language, the main method is the most important method. In JAVA programming language, program execution starts from the main method. When, we compile the Java program in JVM (JAVA VIRTUAL MACHINE). First, JVM finds the main method in the program. Java programs cannot run without main method.

Syntax – public static void main(String args[]) {




{ – It is the start from main method block.

} – It is the ends of the main method block.

Code in the block –

We have written a line of code in the block. The code is

System.out.println(“Practical is important in life”);

This line prints the “Practical is important in life”, Println method prints the string. And above line calls the println method of the System.out class means System.out class includes the println method.

I think that you learn to develop, compile and run your first Java program. If you have any doubt. Then ask us in a comment. It is the best article for beginner. We will learn more about Java programming in the next article. If any mistake in this article, please tell us.

About Snehil Shrivastava

Howdy, This's Snehil. And I really love the Computer Science Universe. Now, I'm snooping around that universe. And I'm here to stick the Technology, How To's, Tips & Tricks, Android and much more etc.

Check Also

Flash Light Apps

5 Flash Light Apps: How to Get Flash Alerts during Phone Call, SMS

Nowadays, we have all multi features smartphone that is useful for many purposes. From all …