HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Java / Java Basics / Java Hello World Program

Java Hello World Program

In this Java tutorial, we will learn to write our first “Hello World” program in Java.

In any programming language, a ‘Hello World‘ program is considered a simple program which outputs Hello, World! on the screen. It is often used to verify that the Java runtime environment is set up correctly and we are ready to start developing the real-world applications.

1. How to Print ‘Hello World’ in Java

Given Java code prints the hello world String in output console or prompt.

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

We can copy the above program and paste it directly in the editor. Still, I will recommend you to write it yourself. This will help in understanding the difference in Syntax mainly the lower or upper case in keywords, classes, and methods.

Do not forget to save the Java file with name HelloWorld.java. In Java, a class name and the file (in which it is written) must be the same.

When we execute the above program, we get the output in the console.

Hello, World!

2. How Java Hello World Program works?

  • Java is object oriented language. Everything in Java is encapsulated inside a Java class. In this case, the class name is HelloWorld.
  • The class contains the main() method. It is the starting point for JVM to start the execution of the program. Remember that we must provide the exact syntax of the main method in any Java program which we want to execute. Syntax must not be changed from public static void main(String[] args).
    • public means that all other class can access it.
    • static means that we can run this method without creating an instance of HelloWorld.
    • void means that this method doesn’t return any value.
    • main is the name of the method.
    • String[] is the type which is used to refer to text content in Java. The [ ] brackets indicate that it is of array type.
    • args is the name of method argument which is of type String[]. It means that the meain method can accept multiple text inputs while starting the program execution. These arguments are generally user inputs to program.
  • System.out.println is the instruction given to JVM to print the given string Hello, World! to console (default output target).

If there are few things, you are not able to understand then do not worry. We will learn these topics and keywords in other tutorials.

Happy Learning !!

Java Hello World Sourcecode

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Comments are closed on this article!

Search Tutorials

Java Basics

  • Java Introduction
  • Java Installation
  • Java Hello World
  • Java JDK, JRE and JVM
  • Java Classes and Objects
  • Java ClassPath
  • Java Operators
  • Java Data Types
  • Java Primitive Types
  • Java Variables
  • Java Comments
  • Java main() Method
  • Java Command Line Args
  • Java Wrapper Classes
  • Java Types of Statements
  • Java Block Statement
  • Java Pass-by-Value
  • Java System Properties
  • Java Static Import
  • Java hashCode() and equals()
  • Java Immutable Class
  • Java 32-bit vs 64-bit
  • Java java.exe vs javaw.exe
  • Java Generate Bytecode
  • Java Naming Conventions
  • Java Little-Endian vs Big-Endian

Java Tutorial

  • Java Introduction
  • Java Keywords
  • Java Flow Control
  • Java OOP
  • Java Inner Class
  • Java String
  • Java Enum
  • Java Collections
  • Java ArrayList
  • Java HashMap
  • Java Array
  • Java Sort
  • Java Clone
  • Java Date Time
  • Java Concurrency
  • Java Generics
  • Java Serialization
  • Java Input Output
  • Java New I/O
  • Java Exceptions
  • Java Annotations
  • Java Reflection
  • Java Garbage collection
  • Java JDBC
  • Java Security
  • Java Regex
  • Java Servlets
  • Java XML
  • Java Puzzles
  • Java Examples
  • Java Libraries
  • Java Resources
  • Java 14
  • Java 12
  • Java 11
  • Java 10
  • Java 9
  • Java 8
  • Java 7

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces