Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Static Variable
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Hendré Louw  
View profile  
 More options Feb 9 2012, 4:31 am
From: Hendré Louw <hen...@lot24media.co.za>
Date: Thu, 9 Feb 2012 11:31:23 +0200
Local: Thurs, Feb 9 2012 4:31 am
Subject: Static Variable

After defining a object as a static variable can I change one of the
object's variables?

eg.

public static Person p = new Person();

later

p.setName("Hendre");


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Len Weincier  
View profile  
 More options Feb 9 2012, 4:37 am
From: Len Weincier <l...@guruhut.com>
Date: Thu, 9 Feb 2012 11:37:32 +0200
Local: Thurs, Feb 9 2012 4:37 am
Subject: Re: [CTJUG Forum] Static Variable

Hi

Yes you can.

The more complete example is :

class SomeClass {

        public static Person p = new Person();

}

Then somewhere else you can say :

        SomeClass.p.setName("Hendre");

hth
Len

On 09 Feb 2012, at 11:31 AM, Hendré Louw wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Etienne Pretorius  
View profile  
 More options Feb 9 2012, 4:37 am
From: Etienne Pretorius <icewolfhun...@gmail.com>
Date: Thu, 9 Feb 2012 11:37:36 +0200
Local: Thurs, Feb 9 2012 4:37 am
Subject: Re: [CTJUG Forum] Static Variable

Hello Hendre,

You should be able to change the values inside the class - provided the 'p' variable is within static scope. You are applying your access modifiers only on the reference and not to the class.

Kind Regards,
Etienne

On 09 Feb 2012, at 11:31 AM, Hendré Louw wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ewald Horn  
View profile  
 More options Feb 9 2012, 4:39 am
From: Ewald Horn <ewaldh...@gmail.com>
Date: Thu, 9 Feb 2012 11:39:40 +0200
Local: Thurs, Feb 9 2012 4:39 am
Subject: Re: [CTJUG Forum] Static Variable

Hi.

Yes, the static is not the same as in C++ - it simply means that the SAME
variable will be shared across instances of the class.

It can still be modified, just like a normal instance variable.

Best regards,
Ewald

On 9 February 2012 11:31, Hendré Louw <hen...@lot24media.co.za> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Gilowey (Santam)  
View profile  
 More options Feb 9 2012, 4:43 am
From: "Paul Gilowey (Santam)" <Paul.Gilo...@santam.co.za>
Date: Thu, 9 Feb 2012 09:43:55 +0000
Local: Thurs, Feb 9 2012 4:43 am
Subject: RE: [CTJUG Forum] Static Variable

Hey Hendre,

Take care that you really need the variable to be static (see Ewald's reply).
Thread safety can be an issue in a multi-threaded environment.

Regards
Paul.

From: ctjug-forum@googlegroups.com [mailto:ctjug-forum@googlegroups.com] On Behalf Of Etienne Pretorius
Sent: 09 February 2012 11:38 AM
To: ctjug-forum@googlegroups.com
Subject: Re: [CTJUG Forum] Static Variable

Hello Hendre,

You should be able to change the values inside the class - provided the 'p' variable is within static scope. You are applying your access modifiers only on the reference and not to the class.

Kind Regards,
Etienne

On 09 Feb 2012, at 11:31 AM, Hendré Louw wrote:

After defining a object as a static variable can I change one of the object's variables?

eg.

public static Person p = new Person();

later

p.setName("Hendre");

--
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to CTJUG-Forum@googlegroups.com<mailto:CTJUG-Forum@googlegroups.com>
To unsubscribe from this group, send email to CTJUG-Forum-unsubscribe@googlegroups.com<mailto:CTJUG-Forum-unsubscribe@goo glegroups.com>
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za<http://www.ctjug.org.za/>
For jobs see http://jobs.gamatam.com/

--
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to CTJUG-Forum@googlegroups.com<mailto:CTJUG-Forum@googlegroups.com>
To unsubscribe from this group, send email to CTJUG-Forum-unsubscribe@googlegroups.com<mailto:CTJUG-Forum-unsubscribe@goo glegroups.com>
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
For jobs see http://jobs.gamatam.com/

SANTAM Bpk / Ltd
Reg. No. 1918/001680/06

Directors: VP Khanyile (Chairman), IM Kirk (Chief Executive), B Campbell, MD Dunn, MP Fandeso, BTPKM Gamedze, MLD Marole, JP Moller, YG Muthien, Dr J van Zyl, Y Ramiah, MJ Reyneke (Executive)

Company Secretary: M Allie

Please note: This email and its content are subject to the disclaimer
as displayed at the following link http://www.santam.co.za/disclaimer.htm.
Should you not have Web access, send a mail to disclai...@santam.co.za
and a copy will be emailed to you.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hendré Louw  
View profile  
 More options Feb 9 2012, 4:44 am
From: Hendré Louw <hen...@lot24media.co.za>
Date: Thu, 9 Feb 2012 11:44:25 +0200
Local: Thurs, Feb 9 2012 4:44 am
Subject: Re: [CTJUG Forum] Static Variable

Thank you this answers my question.

On Thu, Feb 9, 2012 at 11:37 AM, Etienne Pretorius
<icewolfhun...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Moandji Ezana  
View profile  
 More options Feb 9 2012, 6:50 am
From: Moandji Ezana <mwa...@gmail.com>
Date: Thu, 9 Feb 2012 13:50:45 +0200
Local: Thurs, Feb 9 2012 6:50 am
Subject: Re: [CTJUG Forum] Static Variable

Also note that in this case:

class SomeClass {
 public static Person p = new Person();

}

You can also do:

SomeClass.p = null;

You might consider making p final. However, globally shared mutable state
is generally a bad idea. For concurrency reaons, as Paul mentioned, but
also by creating hidden dependencies between classes, which can, for
example, make testing harder.

Moandji


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hendré Louw  
View profile  
 More options Feb 9 2012, 7:07 am
From: Hendré Louw <hen...@lot24media.co.za>
Date: Thu, 9 Feb 2012 14:07:13 +0200
Local: Thurs, Feb 9 2012 7:07 am
Subject: Re: [CTJUG Forum] Static Variable

Can i also say

SomeClass.p = new Person();


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Len Weincier  
View profile  
 More options Feb 9 2012, 7:23 am
From: Len Weincier <l...@guruhut.com>
Date: Thu, 9 Feb 2012 14:23:34 +0200
Local: Thurs, Feb 9 2012 7:23 am
Subject: Re: [CTJUG Forum] Static Variable

On 09 Feb 2012, at 2:07 PM, Hendré Louw wrote:

> Can i also say

> SomeClass.p = new Person();

Yes

Len


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Munaf Sheikh  
View profile  
 More options Feb 9 2012, 7:25 am
From: Munaf Sheikh <munaf.she...@gmail.com>
Date: Thu, 9 Feb 2012 14:25:54 +0200
Local: Thurs, Feb 9 2012 7:25 am
Subject: Re: [CTJUG Forum] Static Variable

Can i also say

> SomeClass.p = new Person();

yes. you can do anything you want to it. anything.

<http://jobs.gamatam.com/>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hendré Louw  
View profile  
 More options Feb 9 2012, 7:33 am
From: Hendré Louw <hen...@lot24media.co.za>
Date: Thu, 9 Feb 2012 14:33:56 +0200
Local: Thurs, Feb 9 2012 7:33 am
Subject: Re: [CTJUG Forum] Static Variable

When I add final to the statement can I call p.setName("Hendre");

public static final Person p = new Person();


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Etienne Pretorius  
View profile  
 More options Feb 9 2012, 7:36 am
From: Etienne Pretorius <icewolfhun...@gmail.com>
Date: Thu, 9 Feb 2012 14:36:00 +0200
Subject: Re: [CTJUG Forum] Static Variable

On 09 Feb 2012, at 2:33 PM, Hendré Louw wrote:

> When I add final to the statement can I call p.setName("Hendre");

Yes, because you are not making the instance final - you are making the reference variable final.

Kind Regards,
Etienne Pretorius


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hendré Louw  
View profile  
 More options Feb 9 2012, 7:44 am
From: Hendré Louw <hen...@lot24media.co.za>
Date: Thu, 9 Feb 2012 14:44:40 +0200
Local: Thurs, Feb 9 2012 7:44 am
Subject: Re: [CTJUG Forum] Static Variable

Fantastic! static and final works on the reference and not the instance.

How do this relate to primitive types?

Can i do the following

public static int TEMP_VALUE = -1;

then later do the following

TEMP_VALUE = 2;

or in the case of final

public final static int TEMP_VALUE = -1;

then later do the following

TEMP_VALUE = 2;

On Thu, Feb 9, 2012 at 2:36 PM, Etienne Pretorius
<icewolfhun...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Munaf Sheikh  
View profile  
 More options Feb 9 2012, 7:47 am
From: Munaf Sheikh <munaf.she...@gmail.com>
Date: Thu, 9 Feb 2012 14:47:43 +0200
Local: Thurs, Feb 9 2012 7:47 am
Subject: Re: [CTJUG Forum] Static Variable

static; yes,
Final: no  (compiler will complain)

On 9 February 2012 14:44, Hendré Louw <hen...@lot24media.co.za> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Etienne Pretorius  
View profile  
 More options Feb 9 2012, 7:48 am
From: Etienne Pretorius <icewolfhun...@gmail.com>
Date: Thu, 9 Feb 2012 14:48:56 +0200
Local: Thurs, Feb 9 2012 7:48 am
Subject: Re: [CTJUG Forum] Static Variable

On 09 Feb 2012, at 2:44 PM, Hendré Louw wrote:

> Fantastic! static and final works on the reference and not the instance.

> How do this relate to primitive types?

> Can i do the following

> public static int TEMP_VALUE = -1;

Since these a non-objects, they will act the same as the reference in the previous examples.

Static = Class variable
Final = non-mutable;

Kind Regards,
Etienne Pretorius


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »