Creating a Simple Program in java
In this section, we'll create a simple "Hello World" program of java. Let's follow the following steps:
Step 1 : Open your code editor window. Do what you like, such as Notepad, Notepad ++, NetBeans and etc. And then you have created a new file or click on the New File button on the toolbar.
Step 2 : Type the code given below in your code editor, and then save it with ".Java" extension. It is very important to save the written Java program as .java (eg : MyProgram.java).
➤ Example : MyProgram.java;
class MyProgram {
public static void main(String args[]) {
System.out.println("Hello Java !");
}
}
Step 2 : Open a command prompt window and go to the directory where you saved the java program, We assume that you have created a file on the desktop.
Step 3 : To move to the desktop, type the command below and press enter.
cd desktop
Step 4 : Type 'javac MyProgram.java' and press enter to compile your code.
javac MyProgram.java
Note : If there are no errors in your code, the command prompt will take you to the next line.
Step 5 : Now finally, type 'java MyProgram' and press enter to run your program.
java MyProgram
Now, you will be able to see the result printed on the window.
Comments