Creating Your First Java Program

Posted by infocampus on April 19th, 2018

The essential steps to make the Hello World program are: compose the program in Java, assemble the source code, and run the program.

1. Write the Java Source Code

Microsoft item screenshot(s) republished with consent from Microsoft Corporation.

All Java programs are composed of plain content — in this way you needn't bother with any uncommon programming. For your first program, open up the easiest content tool you have on your PC, likely Notepad.

The entire program looks like this:

 // The classic Hello World! Program //1

class HelloWorld { //2

   public static void main(String[] args) { //3

      //Write Hello World to the terminal window

      System.out.println("Hello World!"); //4

   } //5

} //6

While you could reorder the above code into your content tool, it's smarter to start composing it in. It will enable you to learn Java all the more rapidly in light of the fact that you will discover how programs are composed, and the best part is that you will commit errors! This may sound odd, however, each misstep you make encourages you to improve as a software engineer over the long haul. Simply recollect that your program code must match the case code, and you'll be fine.

Note the lines with "//" above. These are remarks in Java, and the compiler disregards them.

2. The Basics of This Program

1. Line//1 is a remark, presenting this program.

2. Line//2 makes a class HelloWorld. All code should be in a class altogether for the Java runtime motor to run it. Note that the whole class is characterized inside encasing wavy supports (on line//2 and line//6).

3. Line//3 is the primary () technique, which is dependably the section point into a Java program. It additionally is characterized by wavy props (on line//3 and line//5). We should separate it:

Public: This strategy is open and in this manner accessible to anybody.

Static: This strategy can running without creating a case of the class HelloWorld.

Void: This strategy does not return anything.

(String[] args): This technique takes a String contention.

4. Line/4 expresses "Hi World" to the .

3. Save the File

Microsoft item screen shot(s) republished with authorization from Microsoft Corporation.

Save your program document as "". You should seriously mull over making a registry on your PC only for your Java programs.

It's critical that you spare the content record as "". Java is critical about filenames. The code has this announcement:

class HelloWorld{

This is a direction to call the class "HelloWorld". The filename must match this class name, consequently the name "". The augmentation ".java" tells the PC that it's a Java code record.

4. Open a Terminal Window

Microsoft item screen shot(s) republished with authorization from Microsoft Corporation.

Most projects that you keep running on your PC are windowed applications; they work inside a window that you can move around in your work area. The HelloWorld program is a case of a support program. It doesn't keep running in its own particular window; it must be going through a terminal window. A terminal window is simply one more method for running projects.

To open a terminal window, press the "Windows key" and the letter "R".

You will see the "Run Dialog Box". Sort "cmd" to open the charge window, and press " ".

A terminal window opens on your screen. Consider it a content rendition of Windows Explorer; it will give you a chance to explore various catalogs on your PC, take a gander at the documents they contain, and run programs. This is altogether done by composing orders into the window.

5. The Java Compiler

Microsoft item screen shot(s) republished with authorization from Microsoft Corporation.

Another case of a comfort program is the Java compiler called "javac." This is the program that will read the code in the record, and make an interpretation of it into a dialect your PC can get it. This procedure is called assembling. Each Java program you compose should be ordered before it can be run.

To run javac from the terminal window, you first need to tell your PC where it is. For instance, it may be in an index called "C:\Program Files\Java\jdk.6.0_06\bin". In the event that you don't have this registry, at that point complete a document look in Windows Explorer for "javac" to discover where it lives.

Once you've discovered its area, type the accompanying charge into the terminal window:

set path= *the directory where javac lives*


set path=C:\Program Files\Java\jdk.6.0_06\bin

Press Enter. The terminal window will simply come back to the order provoke. Be that as it may, the way to the compiler has now been set.

6. Change the Directory

Microsoft item screen shot(s) republished with consent from Microsoft Corporation.

Next, explore the area your document is spared.

To change the index in the terminal window, type in the charge:

cd *directory where file is saved*


cd C:\Documents and Settings\userName\My Documents\Java

You can tell in case you're in the correct registry by looking to one side of the cursor.

7. Accumulate Your Program

Microsoft item screen shot(s) republished with consent from Microsoft Corporation.

We're currently prepared to gather the program. To do as such, enter the charge:


Press Enter. The compiler will take a gander at the code contained in the record, and Java Training in Bangalore  endeavor to arrange it. In the event that it can't, it will show a progression of mistakes to enable you to settle the code.

Ideally, you ought to have no blunders. On the off chance that you do, backpedal and check the code you've composed. Ensure it coordinates the illustration code and re-spare the record.

Tip: Once your HelloWorld program has been effectively arranged, you will see another document in a similar catalog. It will be called "HelloWorld.class". This is the incorporated variant of your program.

8. Run the Program

Microsoft item screen shot(s) reproduced with authorization from Microsoft Corporation.

All that is left to do is run the program. In the terminal window, type the charge:

Java HelloWorld

When you press Enter, the program runs and you will see "Hi World!" kept in touch with the terminal window.

Well done. You've composed your first Java program!


Infocampus is one of the java Training Center in Bangalore That Offers Practical Software Training Courses with Placements for Freshers and Professionals.

100% Job Oriented Training Courses. We provide Practical Real-Time Training with Guaranteed Placements Assistance.

Best Java Training in Bangalore with Certified Experts.

Contact: 9740557058

For enquiry visit:

Like it? Share it!


About the Author

Joined: October 14th, 2015
Articles Posted: 184

More by this author