In regular Object oriented programming for example in JavaScript It's is Prototype based way meaning it uses objects that inherit directly from other objects.
Java does things differently. Unlike other object oriented languages Java is class based not prototype based meaning everything you write in Java lives inside of a class.
What does that mean?
Class
A class is like a blueprint you use before you build a house, You will build a house using this blueprint later on
and the house is what we define as an object
What does a class know
Here is where we introduce something inside the class called a field. A field going back to our previous analogy is like describing the house or object for example color of the house number of rooms things of the sort
Constructors
When you need people to start working on the house before you get in you can tell them or not once you give them the plan (class) and information about the house (fields) they'll get to work even without telling them anything
The same thing happens with constructors when you create an object a constructor runs automatically.
The constructor is to get everything ready even before the start. Instead of going piece by piece it does everything once at the beginning
Methods
The methods inside a class are the ones that give your class behavior. They act like functions defined inside of a scope and you can only access those function by referencing the scope they are in. in our analogy a method is like a field that performs tasks with the data for example a method that calculates the area of the house sits in
These are just some of the few concepts i learned in Java i try using analogies and associate them to real life so i can remember them later on..
class dismissed
Top comments (0)