How to Write First Java Program

How to setup my computer for Java programming

Step 01

Install JDK on your computer. You can download Java from here.

  • Configure Environment variables for java. Then you can compile and run java application from anywhere in your computer.
  • On windows10 you can configure environment variables for java as follows.

  • In Environment Variables under User variables click on New
  • Enter JAVA_HOME as variable name
  • Enter path to the JDK as variable value.Ex:

  • Locate the PATH variable
  • Append the PATH to the JDK/bin folder as the PATH Value. Ex: C:\Program Files\Java\jdk1.8.0_241\bin
  • Repeat same steps for the System Varibles.
  • Click OK to apply the settings.
  • To check enviornment variable setup open command prompt and type javac then hit enter if output as follows then path configuration is success.

  • Now you can compile and run java program from anywhere in your computer. 

Step 02

Install IDE for java codding. This can be NotePad, VisualStudioCode, Eclipse, Intelij or any other IDE.
If you are a beginner my sugession is to use nomal text editor like NotePad. If we use IDE there are much more user friendly options for Java coding as well as compiling and run but at the beginning if we used those the we will miss the theory and basics behind those.

Step 03

  • Open notepad and type following java codes.
class FishDemo {

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

  • Save file as FishDemo.java in your computer.
  • Open CMD from file saved location.
  • Type javac <<filename.java>> hit enter. Ex: javac FishDemo.java (This command compile the java code and create FishDemo.class file in same location)
  • Type java <<Class name>> and hit enter. Ex : java FishDemo (This command execute the .class file and print output)







Comments

Popular posts from this blog

History of java