Java Hello World Program | Java First Program

In the previous tutorial, We learned What is Java, features of java, and the 3 components of Java(i.e. JVM, JRE, and JDK). In this tutorial, We will learn Java Hello World Program, how to compile and run a java program. To write your first program, you will need:

1. The Java Development SE Kit(JDK, latest version JDK13):
You can download JDK 13 for the Windows version(Here). Once you downloaded JDK, you need to install the JDK on your system. For installing the JDK on your System, you need to perform the following tasks:

i) Start the JDK 13 installer by double-clicking the installer's icon or file name in the download location.
ii) Follow the instructions provided by the installation wizard.
iii) After the installation is complete, delete the downloaded file to recover the disk space.

2. A text editor:
You can use either notepad or notepad++ as a text editor. You can also use an IDE such as NetBeans or eclipse for writing your program. 
These two items are all you will need to write your Java First Program.

How to create your Java Hello World Program?

To create your first Java Program, you will need:
  • Create a source file: A source file contains the code, which is written in Java Programming language. That code can be understand by you and other programmers. You can use a text editor to create a source file or edit the source file. While creating the source file, you remember the name of the class should match with the name of the file.

  • Compiling the source file: The Java Programming language compiler(javac) takes your source file and translates its text into instructions that the Java Virtual Machine(JVM) can understand. The javac compiler creates a file called dot class file(Example.class) that contains the bytecode of the program.

  • Run the program: The Java application launcher tool(java) uses the Java Virtual Machine to run your Java First Program.

Creating Java Hello World program:

Let's create the Java Hello World first program.

class HelloWorld{
public static void main(String args[]){
System.out.println("This is first hello world java program");

Output: This program gives the following output
Java Hello World Program

Explanation of the first Java Hello World Program.

class: The class is a keyword in java that is used to declare a class.
Read: class and objects with example.

public: The public keyword is an access modifier, which allows the visibility of the class members. When the class members are declared by the public, then we can access the members inside as well as outside the class.

static: static is a keyword in Java. We can make a static variable and static method in Java with the help of a static keyword. The main advantage of the static method is we can call the method without creating an instance of a class. JVM calls the main method without creating an instance of a class, therefore it is must to make the main method is static.

void: The keyword void simply tells the compiler that the main() doesn't returns any value.

main(): The main() method represents the starting point of the program. The main() method is called when the Java applications begin.

String args[]: String in Java is a class that is used to store Strings, and args is a reference variable that refers to an array of String type. It is used for the command line arguments.

System.out.println(): It is used to print the statement. Here System is a class, out is an object of PrintStream class, and println() is the method of PrintStream class.

Java Hello World Program | Java First Program Java Hello World Program | Java First Program Reviewed by Prashant Srivastava on December 11, 2019 Rating: 5

No comments:

Powered by Blogger.