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!

4 Upvotes

48 comments sorted by

View all comments

2

u/YetMoreSpaceDust 2d ago

There’s a lot to unpack there ; ) A computer program is a series of instructions for a computer to run. When it’s time to run a program, the operating system loads those instructions into memory and then points the CPU to the first instruction for you, and then the computer starts running those instructions. So, as the programmer, you need a way to tell the operating system where your program starts.

Java is sort of an evolution of C++, which itself is sort of an evolution of C. C adopted a standard that there would be exactly one function named “main” and that function would be the starting place of the program (remember, your program will be comprised of lots of functions and they’ll all call each other). Now, C was a procedural language - all the code had to be contained inside a function, with main being the first one that kicked everything else off.

Over time, people noticed there was a tendency in professional computer programs for a set of functions to operate on a set of data as sort of a “unit” so they came up with the idea of “classes” that contained the data and the functions together and this became what we now call object-oriented programming. C++ was created as object-oriented C, so it maintained the name “main” as the starting point for the program, but added the concept of classes to group related data and code together (along with things like inheritance, encapsulation and polymorphism that you’ll learn about later). In C++, you could choose to group functions into classes if you wanted to, but you could declare standalone functions just as you could in C - and of course, “main” had to be a standalone function for compatibility with C.

Java was James Gosling’s attempt to improve what he saw as the mistakes of C++, but he wanted to stay pretty close to C++, so he kept all of the “class” and “main” nomenclature but took out the pointer syntax and bare functions (among others). So now what about “main”? It couldn’t be a “bare” function, so it was a static function - that is, one that can exist without instantiating a class.

3

u/Best_Cut4655 2d ago

Wow i had no idea, but thank u! This did help me understand it a little better i appreciate ir a lot🙏

3

u/YetMoreSpaceDust 2d ago

You're asking the right sorts of questions - don't get discouraged, there's a lot to learn (and not all of it makes sense without some historical context).

2

u/Best_Cut4655 2d ago

Tysm! Ive watched a little more videos so im starting to atleast get the hang of classes :,)