[program-java] Re: Java: Precedence... solution

Jim:

Well that really depends upon what your project actually is.... For example my 
current nightmare has over 80 classes, aprox 42,000 lines of code but only a 
call from the main to verify system parameters and then a call to a log in 
class. Yet another STRUTS web based app has no main class, rather JSP, action 
classes etc.

Jim

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
Sent: September 20, 2010 13:53
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

Hi,
I have a question related to this and larger projects. Is it usually the case 
that with a larger project that the only thing that gets done in main is to 
kick off the application and then the rest of the stuff is in a bunch of other 
source files, or is it common to have a big class in the file with the main 
method?

Thanks.

Jim

Jim Homme,
Usability Services,
Phone: 412-544-1810. Skype: jim.homme
Internal recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Monday, September 20, 2010 1:19 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: Java: Precedence... solution

"public static void main(String args[]) {"

Jim, this is your default constructor method, that is public facing. It's 
static to allow only one instance to be created for a given session. The String 
args is for passing where applicable string parameters.

If you were creating a gui desktop application, you would set your Eclipse IDE 
to use this as your main class and affectively it would become your single 
entry point into this application.

Jim
-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
Sent: September 20, 2010 11:42
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

Hi,
I talk about the word global because before I tried to program in Java, not 
counting JAWS, as far as I can remember, I haven't written an application that 
has been in multiple files. And I've never written an object oriented 
application before I started learning Java. So global could be thought of as 
being in the same source file. So when we started this discussion, I was still 
thinking of global in the context of a variable that could be seen in the file 
that held the code for the class, but only seen outside the class if it were 
static or public.

At this point in my learning, the book hasn't told me why I'm writing public 
static void main(String args[]) yet. I'm just trying to keep an open mind and 
accept the new knowledge and only comparing it loosely to what I'm used to 
thinking of. So far, it might be working.

Coding Fingers Crossed,

Jim

Jim Homme,
Usability Services,
Phone: 412-544-1810. Skype: jim.homme
Internal recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: Monday, September 20, 2010 11:33 AM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

Instance variables is their name.

Take care,
Sina

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Monday, September 20, 2010 8:00 AM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: Java: Precedence... solution

Hi:

I used the term global for those beginners on the list that are transitioning 
to the OO world. If every one knew the correct terminology I would claddly 
refer to them as class vars but Friday's discussion sort of makes me believe 
that there are those who need to come to terms with these terms.... No pun 
intended.

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Jeffrey Fidler
Sent: September 18, 2010 11:54
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

Hello, all.  Hopefully I'm thinking clearly again and not like the last couple 
of posts!  What I am wondering is this: is it a good idea to think of variables 
as being 'global' when they are instance variables?  Wouldn't it be better to 
think of class variables in this way if we are going to think of things as 
global?  Also, isn't it a good idea to try not to think of things as global 
when we are doing OO programming as the idea is to decouple or very loosely 
couple components?

In more concrete terms, if we must think of variables as being global, doesn't 
the closest thing approximate to a static class
variable:

public class MyClass {
public static int myVar;
// we have access to this variable in all objects that instantiate this class, 
// it is declared and initialized once by the JVM for all objects that 
instantiate MyClass // its value is consistent across all objects that 
instantiate the MyClass class }

and, this new variable I add (myInstanceVar) is merely just an instance 
variable particular to every instantiation of the class but not global in the 
way we think of global scope as application scope in other languages:

public class MyClass
{
public static int myVar;
protected int myInstanceVar;
// we have access to this myInstanceVar variable throughout subsequent scopes 
within each object that is instantiated from the MyClass class // each object 
instantiation of the MyClass class gets its own memory reserved for this 
variable // consequently, each object instantiation can have its own value 
stored in the variable for use within the object at all scopes }

So, the public static myVar variable is the closest approximation to a global 
variable we get with Java, if I have understood things correctly.

Please let me know in any case if I have my head around this stuff.  I was 
thrown into programming Java at work and am a student of the language whenever 
I get the time.  I would have preferred to have been a student of the language 
before writing production code, but the real world too often intervenes!

Thanks in advance!

- Jeff

----- Original Message -----
From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <program-java@xxxxxxxxxxxxx>
Sent: Friday, September 17, 2010 4:13 PM
Subject: [program-java] Re: Java: Precedence... solution


It's declared in a higher scope.

Take care,
Sina

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
Sent: Friday, September 17, 2010 2:54 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

Hi,
What makes x global?

Thanks.

Jim

Jim Homme,
Usability Services,
Phone: 412-544-1810. Skype: jim.homme
Internal recipients,  Read my accessibility blog. Discuss accessibility here. 
Accessibility Wiki: Breaking news and accessibility advice


-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, September 17, 2010 2:52 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: Java: Precedence... solution

That's what I was trying to point out that the global x had the focus so to 
speak. Yes, I was counting on my fingers and since I had one bit off by a shark 
a few years back I live in base 9.

Jim

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Sina Bahram
Sent: September 17, 2010 14:12
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Java: Precedence... solution

No, because there's no int specification in the for loop ... That x is the 
global x.

Also, it gets incremented to 10, not 9.

Take care,
Sina
________________________________

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, September 17, 2010 2:07 PM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Java: Precedence... solution


Hey now:

I've finally resolved the issue I was having with variables being reused 
multiple times in the same class...

For the sake of brevity:

Public class MyClass {

Private int x = 1;

Public MyClass() {
myMethod();
}

Private void myMethod() {
For (x =0; x<10; x++) {
}
}
}

...obviously x gets finally incremented to 9 and since it's global then it 
throws off any reuse of the variable.

James M. Corbett

Programmer / Analyst |
Canada Revenue Agency | Agence du revenue du Canada
875 Heron Rd.
Ottawa, On.
K1A0L5

James.Corbett@xxxxxxxxxxxxx
Telephone | Téléphone: (613) 941-1338
Facsimile | Télécopieur: (613) 941-2261

Government of Canada | Gouvernement du Canada





This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed.  If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it.  If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
 The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.











Other related posts: