#Identify object and method
64 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @solemn crypt! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
..all of them?
you aren't creating any objects here
there's 2 objects mentioned in the code at all
and there's the method you create and the method you use, which do you want to be explained?
those are h and w, right?
no
those are variables
again, you aren't creating any objects
eh i guess you are to some extent, missed a spot
i feel like you currently are lacking the background knowledge to clarify the scope of your question well
so it seems I misunderstood the definition of object
gonna have to explicitly understand the relation between object and variable, cuz I thought they're one and the same
sadly, I can't find an explanation coupled with real living code.
i mean, yeah, they're quite separate concepts
they just try to explain them in human terms
I mean, write a code, point at stuff as x,y and z
yeah, you can't really point at most objects
that's not a good way to describe it?
I'm just worried I won't be able to practice without fully comprehending the fundemental terms and concepts
and how they're utilized
(excluding literals and constructions, we'll get to that later) terms underlined.
data isn't visible in your source code, they exist only to java (or more specifically, the jvm, the thing running java). objects in particular are stored in heap memory.
variables do exist in your source code, they're how you access your data. you give a name to java and java lets you use that name to refer to some piece of data.
variables have a type, specified as part of their declaration. the declaration is how you tell java that the variable exists, and you need to have that type to tell java what kind of data is stored in the variable.
there's 2 kinds of types, primitive types and reference types. primitive types are just raw data, like int used in your code
reference types are how objects are represented. since objects are stored in heap memory, separated off from the bulk of the process, you need some way to say where in memory the object is, so you can access its data. that's done via a reference, kinda like an address to where that object is stored.
so far so good
of course, you need some way to be able to create or specify the data to begin with, and that's done using either literals or constructors.
literals are, well, literal representations of the data you want to specify. this is used for primitive types, and also strings and arrays, which are reference types.
constructors are how you create objects, they're in the form new Type(args) or in the case of arrays, new Type[size] or new Type[]{elements}
since strings and arrays are also objects, you can also construct them
so yeah, objects exist when you run the code, you can't really point to where an object is in source code
except, as i mentioned, for literals
oooh I think I'm getting it
here you're using string literals in the printlns, those are implicit string objects
so there is no object anywhere in this block of code, only the "ingredients"
at runtime, there also exists an object that java creates, which is argv. it's stored in the args variable that you accept in main(String[] args)
note that args is not the object. it's a variable that holds the object. but oftentimes, when not talking about these fundamentals, args may be referred to as the object directly for brevity
there are the 2 string literals
but other than that, it's more like the code is the recipe that specifies the ingredients
with the objects and other primitive values being the ingredients themselves
the code specifies how to use the ingredients
using variables
more like using statements, but sure variables are a part of it
pretty much all programming languages use statements and expressions as the fundamental parts of the code
statements are the actions, the verbs, while expressions are the values, the nouns
I think that kinda explains the relationship between variables (or statements/lines of code), but I'm still trying to figure out what exactly object ... encapsulates
15, "It's a square" are expressions, they're values to be used by statements
int h = 15;, if (h == w) ..., System.out.println("It's a square"); are statements
cuz from the way you put it, it seems like object is a product
of the block of code
it's not that, no
objects, fundamentally, are used to abstract and represent "things"
they're values, but unlike primitives, they can be arbitrarily complex
and the "things" entail..?
well, anything
instances of String represent pieces of text
PrintStream (System.out) is used to represent a channel used for printing text
String[], an array of strings, is a sequence of multiple pieces of text
you mean like, the internal implementation of objects?
in memory...?
frankly, that's just not something you need to worry about
maybe I need to just continue the course and take note of the things I don't comprehend. cuz it seems here that objects are related to many concepts I've yet to be introduced to
anyway, thanks for taking the time. and sorry to be a bother
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.