#not defined string = null?

43 messages · Page 1 of 1 (latest)

next sierra
#

in java if i define a String name = " "
its value will be automatiicaly assigned as null
yes or no?

idle plinthBOT
#

This post has been reserved for your question.

Hey @next sierra! 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.

gentle musk
next sierra
#

if int num;

num = null here?

vivid gazelle
royal garden
#

all the primitives default to an equivalent of 0
boolean - false
char - '\0'
byte, short, int, long - 0
float, double - 0.0

royal garden
vivid gazelle
royal garden
#

but the

so it's not null too
isn't exactly correct

vivid gazelle
#

yeah, but still you can't do if (name == null)

royal garden
#

yeah because that's accessing it...

vivid gazelle
#

so there is no matter of what it's inner state

royal garden
#

it's... null though?

vivid gazelle
#

null or not

royal garden
#

that's just how it is

royal garden
vivid gazelle
#

can you give me practical example of usage not initialized (but inner null sate) of an object?

royal garden
#

no, because it's expressly not meant to be used

#

im not arguing that it's initialized to null or whatever

#

but saying it definitely isn't null is wrong

vivid gazelle
#

can you use it? can you do if (anObject == null)? no. so no point of saying it's null or not. it's not initialised.

royal garden
#

so no point of saying it's null or not.
so then why did you explicitly say "not null" if it doesn't matter?

vivid gazelle
#

because it has not initialised state

royal garden
#

which is distinct and separate from the value

vivid gazelle
#

neither null or not null

royal garden
#

no not how it works

vivid gazelle
#

did TC ask about JMM?

royal garden
#

the "not definitely initialized" thing is a compiler thing, it doesn't deal with values
null is a value

vivid gazelle
#

I guess he asked about how it bahaves in practice

royal garden
vivid gazelle
#

Im not asking

royal garden
#

who the hell is TC

vivid gazelle
#

topic creator

royal garden
#

i mean this isn't really a topic so that doesn't really work but ok

royal garden
#

it is uninitialized yes, but the underlying value would be null; it's just not accessible/readable

obtuse oar
#

Actually, local variables that haven't been initialized don't exist beside the compiler knowing you want a variable

#

They're not null nor anything, they just aren't

#

Once you initialize them, the compiler knows you want a variable and will organize to have it on the stack, where, on the stack and once pushed, it will have a value

#

Before that, it's nothing