DEV Community

Alon Klein
Alon Klein

Posted on

Introduction to Java!

"JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code."


Welcome to Java.

In this tutorial, you will learn to write "Hello World" program in Java.

A "Hello, World!" is a simple program that outputs Hello, World! on the screen. Since it's a very simple program, it's often used to introduce a new programming language to a newbie.

// Your First Program
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}
Enter fullscreen mode Exit fullscreen mode

Output

Hello, World!
Enter fullscreen mode Exit fullscreen mode

So how it is works?

  • //Your First Program

In Java, any line starting with // is a comment.
Comments are intended for users reading the code to understand the intent and functionality of the program. It is completely ignored by the Java compiler.

  • public class HelloWorld{...}

In Java, every application begins with a class definition. It is depends on your file name, for example your file name will be Hello.java so the class has to be called "Hello".

public class Hello {
    // Class Definition
}
Enter fullscreen mode Exit fullscreen mode
  • public static void main(String[] args) {...}

This is the main method. Every application in Java must contain the main method. The Java compiler starts executing the code from the main method.

public static void main(String[] args) {
    // Main Method
}
Enter fullscreen mode Exit fullscreen mode
  • System.out.println("Hello, World!");

The code above is a print statement. It prints the text Hello, World! to standard output (your screen).

Top comments (0)