#Identify object and method

64 messages · Page 1 of 1 (latest)

solemn crypt
#

can you please identify the object and method in this example here? trying to have a proper understanding of the code I write

drifting aspenBOT
#

This post has been reserved for your question.

Hey @solemn crypt! Please use /close or the Close Post button 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.

keen radish
#

..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?

solemn crypt
keen radish
#

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

solemn crypt
#

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.

keen radish
#

i mean, yeah, they're quite separate concepts

solemn crypt
#

they just try to explain them in human terms

keen radish
#

there's no good way to explain them in code.

#

well, except for 1 case i can imagine.

solemn crypt
#

I mean, write a code, point at stuff as x,y and z

keen radish
#

yeah, you can't really point at most objects

solemn crypt
#

that's not a good way to describe it?

keen radish
#

it would be if you could point to the objects

#

but you can't

solemn crypt
#

I'm just worried I won't be able to practice without fully comprehending the fundemental terms and concepts

#

and how they're utilized

keen radish
#

(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.

solemn crypt
#

so far so good

keen radish
#

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

solemn crypt
#

oooh I think I'm getting it

keen radish
solemn crypt
#

so there is no object anywhere in this block of code, only the "ingredients"

keen radish
#

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

keen radish
#

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

solemn crypt
keen radish
#

more like using statements, but sure variables are a part of it

solemn crypt
#

right

#

so...

keen radish
#

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

solemn crypt
#

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

keen radish
#

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

solemn crypt
#

cuz from the way you put it, it seems like object is a product

#

of the block of code

keen radish
#

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

solemn crypt
#

and the "things" entail..?

keen radish
#

well, anything

solemn crypt
#

I mean the "make-up" of things

#

the "parts" of things

#

what a "thing" is made of

keen radish
#

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

keen radish
#

in memory...?

#

frankly, that's just not something you need to worry about

solemn crypt
#

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

drifting aspenBOT