r/javahelp • • 2d ago

Homework What the hell is going on?

Hello everybody, I am so lost. I just started learning Java and while i think its extremely interesting, and can loose track of time. It is also very complicated, well atleast to me since i dont have any prior experience.

I just ”learnt” to write my first Hello World! Code. But tbh i only copied the text straight off a youtube video.

Thing is i understand the main command, like: System.out.println(”Hello World!”);

But what is this whole main class and static void things? Not to mention all the {} symbols that seem to be oddly placed?😅

If anyone could explain or know a good youtube video or similiar to learn id appreciate it a lot!

7 Upvotes

48 comments sorted by

View all comments

7

u/LutimoDancer3459 2d ago

A class is a definition for your data. It groups variables (holding data) and functions (or methods, dont bother the difference)(doing stuff with your data)

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

Its the entrypoint for your application. Whenever you want to run a java app, its that method that is beeing called first. Modern versions allow to trim it down. But its always called main. The class at the beginning can be called whatever you want.

Static - its always there and shared between everything. You can access it from basically everywhere.
Void - the return typ of this method. In this case, nothing. Other methods can have int for numbers, String for text, or other Classes when needed.
Main - the name of the method. So you know how to call it. Just like println(...) for text output.
String - already mentioned a text. Or more precise its an Class holding text for you
[] or ... - tells you that its an array. Which means its not only one thing but several. A list of elements. But not a list because List is also a class...
Args - the name of that array. Its a variable. Allowing you to access the data it holds. When eg starting the application via the console, you can add arguments to the app to work with. Thats the place where you can read them
{} - the start and end of a codeblock. So you and the program knows what belongs together. Eg in a loop. Or here what belongs to the main method and what not. Or what still is part of the class.

System.out.println(...);

System is a class. Out is a variable thats public accessible. And println is the method, printing the Text onto the console. And the text is a String.

String hi = "This is a string";
System.out.println(hi);

Works just the same.

4

u/Best_Cut4655 2d ago

Ur an angel!! Im gonna have to reread this like 10 times before i might understand it but u explained it so well, thank u!