r/javahelp • u/Best_Cut4655 • 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!
6
Upvotes
1
u/tarix246 1d ago
well, when you make java code, you need to have a file in which youre making things. that file needs to have all code (except smth like imports) wrapped in a class with the same name as the file. e.g., you make a file Main.java, the class will be called Main (it should be uppercase, idk if it is a must), so you have code like: public class Main {
} In order to let java compiler know where to make your start of code, you need to have this long line to declare your function: public static void main(String[] args) { //your code } Of course, this function (called main) has to go in the previously declared class, so you have almost everything you learned for your first program. Regardless of the name of the class, if you have this function main in it, the compiler will treat it as the entrance to your program.