Friday 7 September 2018

First Program and Execution Environment SetUp




Now, It's Time to write our first Java Programs ...

Question - Write a Program to display "Hello World!" in the console?
Answer -

Class FirstJavaProgram
{
      public static void main (String [] args)
     {
               System.out.println("Hello World!");
      } // main
} // class

[ Don't worry - I will explain the above program later (in next post) ]


But before that, We have to set our environment to run our code (Program).
There are two ways to do that...

1 - Using Notepad
2 - Using IDE (Integrated Development Environment)



# Using NotePad




A. Temporary
  1. Open cmd
  2. Write on cmd javac If java is not installed, "javac is not recognized as internal or external command, operable program or batch file".
  3. write on cmd set path=C:\Program Files\Java\jdk1.8.0_121\bin
  4. write on cmd javac you will find path is set

B. Permanent ( Recommended )
  1. Go to "my computer" properties
  2. Click on "Advanced system settings"
  3. Click on "Environment variables"
  4. Click on new tab of user variable
  5. write path in the variable name
  6. copy the path of bin folder
  7. paste path of bin folder in the variable value with Semicolon.
  8. click OK button
  9. the permanent path is set now.

[Video - How to set the path for Java Program]

Steps to run a program:-

1 - Open notepad (another text editor like Notepad++

2 - Copy paste above program (code) 

3 - Save your file as FirstJavaProgram.java on the desktop. (Note-save same name as class name and file name) 

4 - To make sure your file name is FirstJavaProgram.java, (not in FirstJavaProgram.java.txt), first choose "Save as file type:" All files, then type in the file name Hr.java. 

5 - Run Command Prompt.

C:\Users\somesh> cd Desktop

C:\Users\somesh\Desktop> javac FirstJavaProgram.java

C:\Users\somesh\Desktop> java FirstJavaProgram

You should see the program output: Hello World!  




[ Video - To run a program using Notepad ]


# Using IDE

Less time and effort: The entire purpose of an IDE is to make developing faster and
easier. Its tools and features are supposed to help you organize resources, prevent
mistakes, and provide shortcuts.

[ Note - Download anyone either Eclipse or Netbeans ( Free and Recommended ) ]


More Information For IDE & Download Links - Click here (Redirect to Different Website)




[Video - How to run above program in Eclipse IDE]







No comments:

Post a Comment