First Java Program using Notepad

You can write Java program using any IDE like Netbeans, Eclipse etc or you can directly write Java program using Notepad and can compile using CMD (command prompt)

text_x_java
 

Let’s write the First Java Program using Notepad

Step 1. Create a text document with name Hello.java

Step 2. open the created file and write the following code

 

Hello.java

 

Now open the CMD

Go to the path where your Hello.java is kept then give the file name to compile it

javac

 

You can see the command javac Hello.java

Here by this command we are calling java compiler to compile Hello.java file

Now press enter and this creates a new file with name Hello.class

To run the file type java Hello i.e. java <Class Name>

run

Note: You have to set the path first to run the java program if your program is any where except bin folder.

How to set Path

The following post describe how to set the path in windows to run a java program outside the java bin directory.

 

Step 1. Copy the path of your java bin folder

like in our case the path is “C:\Program Files (x86)\Java\jdk1.6.0_21\bin”

 

Step 2. Right click on my computer and open Properties

 

Step 3. Click on advance system settings

 

Step 4. A system Properties window gets opened, here in Advanced tab click on Environment Variables

Now you can see “Path” in System variable.

 

Path1

 

 

Step 5. Click on edit and give the path of bin folder, then click ok

Path2

 

step 6. Its done

First Java Program using Netbeans

Here is a post for beginners, First Java Program using Netbeans

Follow the below steps to create Java program using Netbeans

Step 1. Open Netbeans

Step 2. File > NewProject

Step 3. You can make different kind of project. Here we are creating Java Application

Java Application

 

Name to Project

— Hello.java—

 

OUTPUT:

first_program_output