🌐
GeeksforGeeks
geeksforgeeks.org › java › java-hello-world-program
Java Hello World Program - GeeksforGeeks
System: Built-in class from java.lang package. out: Static member (PrintStream object) of System. println(): Method that prints to console and moves to the next line.
Published   May 12, 2026
🌐
Reddit
reddit.com › r/learnprogramming › describe hello world program in java
r/learnprogramming on Reddit: Describe hello world program in java
August 1, 2024 -

So I'm a newbie developer (1 yr exp), trying to get an understanding of core java. I've been coding for my company for a year now, but writing business logic doesn't seem to be helping much when it comes to improving my understanding of core java. Thought of doing an exercise of taking the simplest programs and going into detail about everything written in it.

Here's a simple hello world program in java:

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

Can I get as many details about what's happening in this file as possible? Like really go into the details here. Explain what each keyword does, why the print statement doesn't require an import, etc.

Top answer
1 of 2
4
If you've already been programming for a year, I guess I'll skip the really basic stuff. This defines a class called HelloWorld. Everything defined in Java has to live within a class. This source file, when compiled, will become a file called HelloWorld.class. There can be directives that exist outside a class (e.g. package and import). These are directives to the compiler. They influence how the compiler behaves while compiling that one file, but they do not "define" anything new, so they don't get placed inside the class. This class has a single method, main. The method has two modifiers: public - the method is available to callers that exist outside this class. static - the method can be called without first creating an instance of the class. The signature of a main method has to look like this. It has to be public and static, it has to return void, and it has to take a String array as a parameter. If you tweak that signature and then try to run the class, it won't work. The JVM won't be able to find a valid main method. System is a class in java.lang . But the package java.lang is automatically imported. That's why you don't need to write java.lang.System.out.println nor do you need an explicit import of java.lang. This is the only package that works this way. System has a static final field called out with type PrintStream . It's rare to expose fields in this way, but I suspect this was done for performance reasons. Like a static method, a static field can be accessed without creating an instance of the class. Because the field is final, its value cannot be swapped to reference a different PrintStream. And println is just a regular instance method on PrintStream. Dunno if that is what you wanted.
2 of 2
1
I don't do Java, but it looks close enough to C++ ... class HelloWorld is creating a new class, and the { and } at the beginning and end is the block. In that class, "public" is creating a public function called main() which returns a void, meaning it doesn't return anything when that function exits. Any public function can be called from outside of the class, whereas if it were private it would only be called from inside the class. String []args is probably defining an array of strings for the args that are being provided to the program from the command line, such as if you ran "program 1 2 3" then it would have three array elements, "1", "2", and "3". In C you'd also have an "int argc" before that which would tell you how many array elements there were. Again you have { and } which are telling you that its a block of code that all goes under main() Then you have what is essentially a printf( ) (in C) that outputs the string "Hello world", I assume to the screen. I don't know what a Java "import" is, .. but the reason that function doesn't require a type is probably because it is similar to C++ where the method is defined for multiple types and the Java interpreter knows which one to call based on whatever the type of the arg is. A java import that you mentioned might also be the C equivalent #include, which, if it is missing, I would assume that Java automatically imports the System class/object and doesn't make you declare it, but that's just a guess based on what you wrote. I don't know Java, so I don't know what "static" means in this context, because I don't think it means the same thing in Java that it means in C++
Discussions

How to use of print("HelloWorld") instead of System.out. ...
I read about import static which helps me to write direct print.. but why is it not advisable to use import static..as a first time learner I am finding it difficult why not to use import static ? ... There's nothing wrong with using import static. As BorisTheSpider points out in a comment, though, wildcard static imports (like import static java... More on stackoverflow.com
🌐 stackoverflow.com
Learning Java in 2024?

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or

  2. Temporarily refraining from using Reddit

  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

More on reddit.com
🌐 r/learnprogramming
76
55
January 28, 2024
[Java] How do I go from "Hello, world" to actual projects?
I've heard that very question numerous times... It makes me question what is being taught in those classes (only half serious here, don't lynch me ;) There are two vital things to keep in mind when it comes to writing programs: Knowledge. This one's the part where classes work really well. Giving you the hard skills needed to write code. Structure. This is the part I believe you're struggling with. So let me break it down. Word of caution though. I'm a game developer so my mileage may vary in terms of what production or manufacturing based programmers need. So how do you go from "hello, world" to actual projects? You need to remember that most programs are written to solve problems. So you're already on the right track. Say you want to program an "Asteroids" type of game. The first thing you'll need to do is break it apart into the smallest solve-able problems. To stick with your example of the triangle calculation: You want the enemies to be destroyed upon touching the players ship. So what do you need to do for that? Well for starters you'll need to figure out the exact distance between the player ship and the enemy. How do we do that? Pythagoras theorem. E.g. take the coords of the player and enemy. Which will give you two points A and B and then use Pythagoras to solve for C which will give you the distance between player and enemy. If that distance is below a value of X then destroy the player. Every programs is essentially a collection of smaller problems that are being solved by your code. So the next step for you would be: Find a bigger problem, break it down into bite size chunks and kill one problem after another until the bigger problem is solved. Btw. sorry for the text wall... :P More on reddit.com
🌐 r/learnprogramming
50
150
May 5, 2013
Why does this print "Hello World"?

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full - best also formatted as code block

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

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

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

More on reddit.com
🌐 r/learnjava
5
26
November 2, 2022
People also ask

Why use a class and the main method in a “Java Hello World" program?
Java requires code to be written within classes. The main method is the program's entry point, conventionally declared as public static void main(String[] args). It allows the program to start execution.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › java-hello-world
Java Hello World: Your First Step in Programming
Can I use any text editor for “Java Hello World" programs?
Yes, any text editor can be used, but it's advisable to use one with code highlighting and auto-completion features for ease and accuracy. Editors like Visual Studio Code or IntelliJ IDEA are popular choices for Java development.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › java-hello-world
Java Hello World: Your First Step in Programming
What are related courses and blogs provided by The Knowledge Academy?
The Knowledge Academy offers various Java Courses, including Java Programming Course, JavaScript for Beginners and Java Engineer Training. These courses cater to different skill levels, providing comprehensive insights into Java Methodologies. Our Programming & DevOps Blogs cover a range of topics related to Java, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Java Programming skills, The Knowledge Academy's diverse courses and informative blogs have you covered.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › java-hello-world
Java Hello World: Your First Step in Programming
🌐
DataCamp
datacamp.com › doc › java › first-java-program-hello-world
First Java Program: Hello World
To create a "Hello, World!" program, ... Write the Code: Type the following code into your text editor: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }...
🌐
Programiz
programiz.com › java-programming › hello-world
Java Hello World - Your First Java Program
Let's explore how Java "Hello, World!" program works. Note: You can use our online Java compiler to run Java programs. // Your First Program class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
🌐
W3Schools
w3schools.com › java › java_output.asp
Java Output Values / Print Text
You learned from the previous chapter ... methods as you want. Note that it will add a new line for each method: System.out.println("Hello World!"); System.out.println("I am learning Java."); System.out.println("It is ...
🌐
Princeton CS
introcs.cs.princeton.edu › java › 11hello
1.1 Your First Java Program: Hello World
Understanding a Java program. The key line with System.out.println() prints the text "Hello, World" in the terminal window.
Find elsewhere
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › java-hello-world
Java Hello World: Your First Step in Programming
April 10, 2026 - In the case of a "Java Hello World" program, your code will look like this: ... This code defines a Java class named HelloWorld with a function that prints "Hello, World!" to the console.
🌐
freeCodeCamp
freecodecamp.org › news › hello-world-in-java-example-program
Hello World in Java – Example Program
June 7, 2022 - ... In order to keep this article simple, we won't discuss other keywords found above like public, static, and void. We use the System.out.println() statement to print information to the console.
🌐
Igmguru
igmguru.com › blog › first-java-program-hello-world
Java Hello World Program
3 days ago - Write your first Java hello world program with this step-by-step guide. In this article, you will get to learn how to create and run Java code.
🌐
C# Corner
c-sharpcorner.com › article › printing-hello-world-in-java-different-techniques-and-examples
Printing "Hello, World!" in Java: Different Techniques and Examples
December 20, 2024 - Main Method: The entry point of any Java application is the main method. Print Statement: This is where we use System.out.println() to display output. Here’s the most straightforward way to print "Hello, World!" in Java.
🌐
W3Schools
w3schools.com › java
Java Tutorial
You can edit Java code and view the result in your browser. public class Main { public static void main(String[] args) { System.out.println("Hello World"); } } Try it Yourself » · Many chapters in this tutorial end with an exercise where you ...
🌐
Medium
medium.com › @cillateme › beginners-guide-to-writing-your-first-java-program-exploring-the-hello-world-example-427ab0791e92
“Beginner’s Guide to Writing Your First Java Program: Exploring the ‘Hello, World!’ Example” | by Rajkumar Adhikari | Medium
March 3, 2024 - public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } ... A class called HelloWorld is declared on this line. A class in Java is an object’s blueprint.
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java's 'Hello World': Print Statement & Example - Lesson | Study.com
October 29, 2019 - So for example, the following Java program appearing here will not compile because there is no 'main' following 'void:' public class Main { public static void(String[] args) { System.out.println("Hello, World!"); } }
🌐
Lenovo
lenovo.com › home
Hello World: Your First Step into Programming | Lenovo US
Open a terminal, navigate to the ... Absolutely, Ruby makes it easy to write a "Hello World" program. Simply open a text editor or IDE and type: puts "Hello, World!" This command prints "Hello, World!" to the console....
🌐
Tutorialspoint
tutorialspoint.com › java › java_hello_world.htm
Java - Hello World Program
Now, type 'java MyFirstJavaProgram' to run your program. You will be able to see "Hello World" printed on the screen.
🌐
JetBrains
jetbrains.com › help › idea › creating-and-running-your-first-java-application.html
Create your first Java application | IntelliJ IDEA Documentation
From the completion list that opens, select the println method and press Enter. Type ". The second quotation mark is inserted automatically, and the caret is placed between the quotation marks. Type Hello World.
🌐
Oracle
docs.oracle.com › javase › tutorial › getStarted › application › index.html
Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started)
*/ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } } Comments are ignored by the compiler but are useful to other programmers. The Java programming language supports three kinds of comments:
🌐
Happy Coding
happycoding.io › tutorials › java › hello-world
Hello World - Happy Coding
February 22, 2017 - Now that you have a .class file, you can tell Java to run that file. From the command prompt, type java HelloWorld and press enter. Notice that you don’t include the .class part!