r/javahelp • • Sep 10 '20

The program im using says this has an illegal static declaration, how do i fix this? It seems alright to me

public class Helloworld {

public static void (String[] args) {

System.out.println("Hello, world");

}

}

0 Upvotes

20 comments sorted by

2

u/kasim_of_all_trades Sep 10 '20

Are you having a laugh ?

1

u/Lillial Sep 10 '20

I just started a coding class im sorry :(

1

u/Daedalus9000 Java Developer Sep 11 '20

If you haven’t figured it out you’re missing the name (“main”) of your method.

1

u/Lillial Sep 11 '20

What do you mean?

1

u/Cache_of_kittens Sep 11 '20

Where did you get the code from to write this program?

1

u/Lillial Sep 11 '20

Ah I got it from my school textbook

1

u/Cache_of_kittens Sep 11 '20

Check it out again cos you are missing part of it. Namely the name of the method.

1

u/Lillial Sep 11 '20

What is a method name? How do I add it?

1

u/Cache_of_kittens Sep 11 '20

Have you looked through the book where you copied it from?

1

u/kAlvaro Sep 11 '20

You haven't named it. How would you invoke that System.out.println("Hello, world"); bit from other parts of your program?

1

u/Lillial Sep 11 '20

im not sure, I thought that the System.out.println was the Method name

1

u/kAlvaro Sep 12 '20

Yes, that's a method name, but it is this one, not yours. Yours doesn't have any name. If you type System.out.println("Hello, world") again anywhere else in your code you aren't calling your Helloworld class at all, you're calling a different piece of code that happens to be identical.

1

u/kasim_of_all_trades Sep 12 '20

Sorry buddy, didn't mean to be nasty to u.

I had similar problems when i started learning Java, which was more than a decade ago. I would recommend searching a bit before asking questions, as it helped me a lot to learn. Then again, that is just my opinion.

The entry point for your Java programmes is usually a method called "main". That is what you are missing. The statement goes like:

public static void main (String[] args){ }

public means that this method can be accessed from anywhere.

static means that it can be called without instantiating the class's object

void means it will not return anything when it finishes

main is the method name

Hope it helps and that i haven't broken any forum rules.

Happy coding.

1

u/tcbenkhard Sep 10 '20

Look up method signatures. You missed something in the method you created.

1

u/kasim_of_all_trades Sep 10 '20

I am not OP mate. No use telling me that. I can see where the problem is, hence my original comment.

1

u/tcbenkhard Sep 10 '20

Sorry that was meant to be a comment, not a reply to your comment.

1

u/kasim_of_all_trades Sep 10 '20

No probs budd.

2

u/TheBlueSalamander Sep 11 '20

My name's in your name

1

u/kasim_of_all_trades Sep 12 '20

It must be kasim, then.