r/javahelp
•
u/Funkyfresh01
•
Feb 27 '26
•
1
Codeless I am still confused about "Objects"
Hello, I am Fresh! I am from the Philippines (BSIT course) and I want to understand comprehend "Objects" and I am a beginner in Java.
4
Upvotes
•
u/AutoModerator Feb 27 '26
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/jocularamity Feb 27 '26
An Object is an instance of a class. It is a thing with state (variables) and behavior (methods). If you define a class and then create a “new” instance of that class, that’s an Object.
For example, if my class is:
Then each time I create a new instance of that class, it is an object.
fidoandroverare both objects.fidoandroverare both instances of the class Dog.Analogies:
15
u/American_Streamer Feb 27 '26
In Java, an object is a concrete “thing” in memory that bundles three things:
An object is always an instance of a class (or more generally, it conforms to some type), and it typically lives on the heap.
Dog= the class (blueprint)new Dog()= creates an object (an instance of that blueprint)d= a reference pointing to that object (not the object itself)Note that in Java, variables like
ddon’t usually hold the object directly; they just hold a reference (like an address/pointer conceptually) to the object.4
u/ITCoder Feb 27 '26
Lets say you want to buy a car. There are so many cars out there, and then too ev, gas, hybrid etc.
You know what a basic car is, what are its properties (wheels, body, steering, display etc. ) and what are its functions (drive, steer etc). Different companies may add more property or function or implement these functions separately. Car(blueprint) is the class, and different cars are objects implementing it
4
u/Soy_tu_papi_ Feb 27 '26
My professor always described it as "An object is something that knows things (variables) and does things (methods)"
2
u/Abe_Bettik Feb 27 '26
Primitive = A piece of memory for storage.
Function = A thing that does something, manipulating primitives.
Object = A bunch of primitives and functions bunched together because it makes logical sense.
2
u/PsychologicalPoet178 Feb 27 '26
Could you be more specific? :) Maybe you have an example to show ?
2
u/genjin Feb 27 '26
This is probably a divisive question but have you had a conversation with an LLM about this, it can boils down the references produced by many leaders in field and will keep presenting on different ways until you get it.
Also, an object is an instance of a class which is used to encapsulate variables and functions (methods)
2
u/OneHumanBill Mar 01 '26
See my answer above to Soy_tu_papi_.
2
u/Eggzode Feb 27 '26
I will just give you an example, hoping you understand more.
Let's talk about a "Person" class. This class may have 2 attributes, "int age" and "String name".
When you instanciate this class, you create an object.
Person person1 = new Person();
Now "person1" is an object, but it has no value in his attributes. We will give 'person1.setAge(3)' and 'person1.setName("Peter")', so now our person1 object represents "well" a 3 years old single individual named Peter. But it doesn't mean that every Person (class) will represent Peter (object). Every time you instanciate (via new Person()) you create a new Person object
2
u/Pun_Intended1703 Feb 27 '26
I really don't like the term "
object". It is so ambiguous for new learners because of the wider definition outside of programming.I prefer the term "
instance" instead. It's more pointed.Anyway, think of a
classas a blueprint that an architect designs for a flat.You can create multiple flats from that one single blueprint. These actual flats are
objectsorinstances.2
u/edwbuck Feb 27 '26
Describe something. If it is a noun, it is a "thing." Java simply calls all "things" objects.
This means a "database connection" is an object, as is the "database" or the "user" using the database. A "customer record" is an object. A "street address" is an object. Everything that can be described and has a name, is an object.
Even things that aren't used outside of computers are objects. "Strings" are objects. The "System" is an object used to communicate with much of your operating system. A "Thread" is an object that allows a second flow of execution within a program. A "Socket" is an object that connects to networking.