r/learnprogramming • • 20d ago

Suggestions regarding programming

I'm 18. I'm currently learning Java and I feel I'm unable to understand stuff in it, especially object oriented programming. The practice feels like I'm falling behind.

18 Upvotes

39 comments sorted by

View all comments

1

u/Traditional_Vast9419 20d ago

A Class is hard to understand before learning structs in C. Basically, before OOP, everyone used composition to design their applications with C structs. Using each struct as the first argument of their relevant functions became such a common design choice that Java just combined structs, and their relevant functions, into classes with methods. This connection allows for inheritance (as opposed to composition): another class to inherit the encapsulated methods of any other class to make large substructures with less code.

Basically, it's really complicated, especially if you don't know C. Hopefully my explanation was a little helpful, but don't sweat if it made no sense. Just keep at it and it will eventually click. I'm, personally, not a fan of OOP because composition is, overall, far simpler, and substructures can be envoked by an enum and switch statement. It's still a cool skill.

1

u/kpg_on_ao3 20d ago edited 20d ago

I think classes are easier than C structs bc languages with classes usually don't require you to manage memory, pointers, etc.

It's certainly easier to handle Java-style than C structs, which is why Java for a while was the language of choice for Intro to Programming classes, and several professors believed C should be the language because it was harder and thus would weed out dumb students from CS departments.

I lived through this. I did C and C++ at my local community college as a high schooler, but then my state's biggest research university switched to Java, so AP Computer Science switched to Java as the language for the exam.

The switch was because Java was easier.

C structs are objects anyway. But C isn't object oriented because the language isn't built around structs (i.e., inheritance, etc.).

1

u/Traditional_Vast9419 20d ago

In Java, the garbage collector is a separate mechanism from a Class, and structs have no inheritance.