Firstly:

public test(args) {
    System.out.println(args);
}

You need a type to go with a parameter - Java is a strongly typed language and thus you always need to specify a type. As to what the type is here, System.out.println() can actually take anything, so you could set the type to String, Object or whatever you like (since Object has a toString() method and it has lots of overloads to deal with all the primitives.) Bear in mind this is unusual though, most of the methods you come across will just take something of a specific type!

Since you're only calling test from the main method here, and you're passing a string to it, you may as well set the type of args to String.

The second problem with this is that there's no return type specified. You always need to specify a return type, in this case nothing is returned so the type is void. If you don't do this then the compiler has no way of knowing whether what you wrote was meant to be a method or a constructor.

The third problem is that test is an instance method but you're calling it statically. test() needs to be static as well, otherwise it belongs to instances of Main and not the Main class. Why does this matter? Well, there could potentially be thousands of instances of Main, so what instance should the method run on? The compiler has no way of knowing.

Next:

public static void main(String[] args) {
    test('Hello World');
}

You're passing a string here, which needs to be in double quotes. Java treats quotes differently to PHP, single quotes are used for single character literals and double quotes are used for strings. So you can never enclose a string in single quotes like this, it has to be double.

Putting it all together:

public class Main {

    public static void test(String args) { //Add return type and parameter type, make test static
        System.out.println(args);
    }

    public static void main(String[] args) {
        test("Hello World"); //Change single quotes to double quotes
    }
}
Answer from Michael Berry on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-hello-world-program
Java Hello World Program - GeeksforGeeks
public class HelloWorld { // Your program begins with a call to main() public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello, World"); } }
Published   May 12, 2026
🌐
Oracle
docs.oracle.com › javase › tutorial › getStarted › application › index.html
Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started)
/** * The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string.
Discussions

methods - java beginner "Hello World" - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
java - what is wrong with this code public class Hello { public static void main() { System.out.println("Doesn't execute"); - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Describe hello world program in java
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. More on reddit.com
🌐 r/learnprogramming
7
0
August 1, 2024
The death of the public static void main(String[] args) meme
I mean…the ridicule doesn’t really bother us does it? Sure Java is verbose but that’s why it’s a pleasure to work with. It’s readable and it spells out exactly what it’s doing. More on reddit.com
🌐 r/java
63
93
February 27, 2024
🌐
Programiz
programiz.com › java-programming › hello-world
Java Hello World - Your First Java Program
// Your First Program class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
🌐
Codédex
codedex.io › codédex › java › 02. hello world
Codédex | 02. Hello World
public class HelloWorld { public static void main(String[] args) { System.out.println("text goes here"); } }
🌐
ProTech
protechtraining.com › bookshelf › java_fundamentals_tutorial › hello_world
Java Fundamentals Tutorial: Hello World - ProTech Training
/** * My first class * @author student * @version 1.0 */ public class HelloWorld { /** * Main method that runs when the program is started. * @param args command-line arguments */ public static void main (String[] args) { /* This is how you can print to STDOUT */ System.out.println("Hello World"); // don't forget the semi-colon /* System.out.println("I was also going to say..."); System.out.println("but I changed my mind"); */ } }
🌐
Learn Java
learnjavaonline.org › en › Hello,_World!
Hello, World! - Learn Java - Free Interactive Java Tutorial
public class Main { public static void main(String[] args) { System.out.println("This will be printed"); } }
🌐
DataCamp
datacamp.com › doc › java › first-java-program-hello-world
First Java Program: Hello World
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
🌐
Medium
medium.com › towardsdev › understanding-public-static-void-main-string-args-in-java-5d5666d4f1eb
Understanding public static void main(String[] args) in Java | by Nakul Mitra | Towards Dev
February 17, 2025 - class Main { public static int main(String[] args) { System.out.println("Hello World!"); return 0; } } ... The JVM specifically looks for a method named main as the starting point.
Find elsewhere
🌐
JetBrains
blog.jetbrains.com › idea › 2024 › 02 › helloworld-and-main-meet-minimalistic
Java 24: ‘HelloWorld’ and ‘main()’ meet minimalistic | The IntelliJ IDEA Blog
February 25, 2025 - Before Java 21, you would need ... World’ to the console, as follows: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }...
Top answer
1 of 13
15

Firstly:

public test(args) {
    System.out.println(args);
}

You need a type to go with a parameter - Java is a strongly typed language and thus you always need to specify a type. As to what the type is here, System.out.println() can actually take anything, so you could set the type to String, Object or whatever you like (since Object has a toString() method and it has lots of overloads to deal with all the primitives.) Bear in mind this is unusual though, most of the methods you come across will just take something of a specific type!

Since you're only calling test from the main method here, and you're passing a string to it, you may as well set the type of args to String.

The second problem with this is that there's no return type specified. You always need to specify a return type, in this case nothing is returned so the type is void. If you don't do this then the compiler has no way of knowing whether what you wrote was meant to be a method or a constructor.

The third problem is that test is an instance method but you're calling it statically. test() needs to be static as well, otherwise it belongs to instances of Main and not the Main class. Why does this matter? Well, there could potentially be thousands of instances of Main, so what instance should the method run on? The compiler has no way of knowing.

Next:

public static void main(String[] args) {
    test('Hello World');
}

You're passing a string here, which needs to be in double quotes. Java treats quotes differently to PHP, single quotes are used for single character literals and double quotes are used for strings. So you can never enclose a string in single quotes like this, it has to be double.

Putting it all together:

public class Main {

    public static void test(String args) { //Add return type and parameter type, make test static
        System.out.println(args);
    }

    public static void main(String[] args) {
        test("Hello World"); //Change single quotes to double quotes
    }
}
2 of 13
2

In Java, Strings are always using double-quotes, never single-quotes. That's reserved for char types.

test("Hello World");

Also, your test function doesn't have a return type (not even void), and it's a method while main is static, so you'd need to instantiate Main or make test static as well. You also need to specify the type for each argument.

Try this:

public static void test(String args) {
    System.out.println(args);
}
🌐
Sololearn
sololearn.com › en › Discuss › 1019267 › public-class-hello-world-public-static-void-main-string-args-system-out-println-hello-world
public class Hello World { public static void main(String [ ] args ) } { System.out.println ("Hello World"); | Sololearn: Learn to code for FREE!
January 21, 2018 - so many errors 1)there must be ... of class bracket //corrected code 👇 public class Hello_World { public static void main(String [ ] args ){ System.out.println ("Hello World"); } } ... public class HelloWorld{ public static ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › public-static-void-main-string-args-java-main-method
Understanding public static void main(String[] args) in Java | DigitalOcean
June 26, 2025 - It acts as a channel to pass information into your application from the outside world at the moment of execution. It is an array of String objects. When you run your program from a terminal, any text you type after the class name will be passed into your program and stored in this array.
🌐
freeCodeCamp
freecodecamp.org › news › hello-world-in-java-example-program
Hello World in Java – Example Program
June 7, 2022 - class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); // Hello World!
🌐
Mikail-khan
blog.mikail-khan.com › post › java-hello-world
Java Hello World - Blog - Mikail Khan
February 22, 2021 - class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
🌐
Brainly
brainly.in › computer science › secondary school
public class Main { public static void main(String[] args) { System.out.println("Hello World"); } } - Brainly.in
February 1, 2025 - The public keyword allows the method ... pass command-line arguments. 3. System.out.println("Hello World");: This prints the text "Hello World" to the console....
🌐
Medium
medium.com › javarevisited › the-secret-journey-of-hello-world-from-class-to-console-26c5fb6e45f8
The Secret Journey of “Hello, World!” - from .class to console. | by TinyTechThreads𓍯𓂃 | Javarevisited | Medium
February 18, 2025 - Compiled from "HelloWorld.java" public class HelloWorld { public static void main(java.lang.String[]); Code: 0: getstatic #7 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #13 // String Hello, World! 5: invokevirtual #19 // Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return }
🌐
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++
🌐
Sololearn
sololearn.com › en › Discuss › 1019267 › public-class-hello-world-public-static-void-mainstring-args-systemoutprintln-hello-world
public class Hello World { public static void main(String ...
January 21, 2018 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Scala Documentation
docs.scala-lang.org › overviews › scala-book › hello-world-1.html
Hello, World | Scala Book | Scala Documentation
public class Hello { public static void main(String[] args) { System.out.println("Hello, world"); } }