Sunday, 5 January 2020

First Java Program


First Java Program

To create a simple java program, we needs to create a class that contains one method(the main method). 
And to develop java programs we needs some mandatory components so let's understand the requirement first.


The requirements for Java program

For executing any java program, we needs below mandatory components or steps:
  • Install the JDK
    • If you don't have installed it, download the JDK and install it.
    • Click here to download the JDK
  • Set path of the jdk/bin directory.
    • Click here to know how to set the Java path.
    • If we will not set the jdk path then while compiling the program we will get error like "javac is not recognized as an internal or external command".
  • Write the java program
  • Compile and run the java program
Lets create our first Java program
  
Step 1: Open Notepad and copy the below code:
   
     class Hello{
        public static void main(String args[]){
          System.out.println("Hello Java");
        }  
     }
Step 2: Save this file as Hello.java.
Step 3: Open command prompt.
Step 4: Go to the directory where the Hello.java has been saved.
Step 5: Compile the code. Type "javac Hello.java" in command prompt and enter.
Step 6: Execute the code. Type "Java Hello" in command prompt and enter.
                Output: Hello Java

No comments:

Post a Comment