Hello World in Java



  • This is the first program to learn Java language. You know that Java is purely OOPS base language. That means in Java Language all work in the classes.



  • To copy the code and paste it to your Notepad and save the file with the class name which contain the main method.
          For Example:- In my class demo public static void main method is the main method to of my class demo.
  •  Now I explain the program
  1. Firstly we create a class with class name. For creating a class we use class keyword. make sure the class keyword is small letters then provide a class name according to you.
  2. After that in the class we create a main method.
  3. In Java we create a main method like that in the above pic public static void main(String args[]){}
  4. In this main method work similarly main method work in C++.
  5. And to show the output on the console we write System.out.println();
  6. This System.out.println() command is similar cout in the C++ .
  7. We write any thing into the parenthesis brackets with double quotes.
  • How to execute a program
  • Firstly make sure in your computer Java JDK (Java Development Kit) and JRE (Java Runtime Environment ) install.
  • After that open the command prompt. Click Start->type cmd-> then press Enter.
  • In the cmd prompt then go to that folder in which your file is save with java extension. usind cd command. e.g. cd desktop press Enter.
  • Then compile the program with javac command.
  • If you get an error to resolve it to click here
  • This command compile the program and generate the class file automatically.   
  •  And now the run program with java command like that:-
  • I hope you really enjoy it. HAPPY CODING

Comments

AddThis