First Program in Java

In this tutorial, we will learn about how to install JAVA on your system as well as how to run your first program in Java IDE


To initialize Java, we need to follow a few steps to make sure that we execute the code accurately. Firstly, we will be making sure whether Java is present on your system or not, secondly, we will proceed with installing a user-friendly Java IDE to execute our code.

Recommended Books



Installing Java

To execute the program in Java, we can:

  1.  Install the Java development kit, you can do so by going to oracle.com.
  2. Next you have to set the path of your Java development kit directory.
  3. If you want to compile Java online, then you can go to jdoodle.com which is a working online Java compiler.
  4. You can download and install IntelliJ and operate JAVA on your system directly. You can follow the steps here
  5. Create a Java Program
  6. Compile and Run the Java Program.

Creating Hello World Program in Java

In order to start a program in Java, we must begin with a class name, let’s create a file ‘New’ with an extension of .java known as New.java n type a “hello world” message inside it. The hello world program will look like the following code:

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

Output:

Hello World

Understanding the Parameters of Java Code:

Let’s break down the above code and understand the keywords:

  • class: This keyword is used to declare a class in Java. It is important to note that your file name should match the class name that you declare.
  • public: Public keyword is an visibility modifier, which decides visibility. If it’s not set to public, then the code will have limited accessibility.
  • static: Static is also keyword in Java, the main reason of using static method is that we don’t have to create an object. The main method itself is executed by the Java Virtual Machine plus it saves memory as well.
  • void: Like the keyword void this method does not return anything.
  • main: Main keyword is used to define the initial point of the program.
  • String[] args: Keyword is used for command line argument.
  • System.out.println(): This command is used to print statement in Java. System is a class that outputs or print the println() method. Whatever you want to print, make sure that you mention the words in double quotations inside the the parentheses of this method.