Need some hints (two questions)
Hello everybody. I am a beginner at Java programming and I am trying to learn things in deep details. I can see that this forum is very helpful. At first, I had some problems to post, but after I read some rules my mind changed and I didn't just post them, in fact I solved them by using the advises given in some of the articles. But I have two questions, that I can't really find its answers. (My teachers say that they will explain them in next semester. Frankly I don't know the reasons (perhaps they might think of us incapable of understanding everything at once)). I would be grateful if I could get some help with the following two questions:
1. When we start a program, the "class is copied into primary storage and becomes an executing object". I don't find this quite understanding, in fact it's quite complex in my mind, so can anybody help me to find/understand the precise explanation?
2. Is there a difference (perhaps in later use of the program) between writing this piece of code:
GregorianCalendar c = new GregorianCalendar();
System.out.println(c.getTime());
and
System.out.println(new GregorianCalendar().getTime());
Re: Need some hints (two questions)
I'm not really sure what your first question is. Do you mean when you start the program, or when a class is loaded, or when it's instantiated? Those are some good google keywords for you.
As for your second question, what happened when you tried? The only difference is that you're storing the Calendar in a variable, so you have access to it after you instantiate it.
Re: Need some hints (two questions)
Thank you for replying.
Quote:
Originally Posted by
obel1x
1. When we start a program, ...
When we start the program, I said it at the very beginning of the question. Let me know if it's still not comprehensive enough. About the second one, I tried both but I didn't use any reference after so it worked fine. But now I understand. You're right, I got your point, thanks for the explanation.
Re: Need some hints (two questions)
Quote:
Originally Posted by
obel1x
Thank you for replying.
When we start the program, I said it at the very beginning of the question. Let me know if it's still not comprehensive enough. About the second one, I tried both but I didn't use any reference after so it worked fine. But now I understand. You're right, I got your point, thanks for the explanation.
I read your question. My point was that your assumption didn't make a ton of sense to me. But really, why do you think you need to know this? It should have no impact on your programs whatsoever.
Re: Need some hints (two questions)
Which assumption? Well, as I said I am just curious how things work in details, something like what happens with cells, bits, classes, objects etc. I want to know every time I write some code, what is really happening in computer ..
Re: Need some hints (two questions)
Quote:
I want to know every time I write some code, what is really happening in computer .
To understand that you need to learn assembly language, learn how the linker program works and how the loader works and how the OS gets involved when you start executing a program.
None of which is really needed for java programming.
Re: Need some hints (two questions)
Quote:
Originally Posted by
obel1x
Which assumption? Well, as I said I am just curious how things work in details, something like what happens with cells, bits, classes, objects etc. I want to know every time I write some code, what is really happening in computer ..
The assumption that when a program is started, the "class is copied into primary storage and becomes an executing object". Where are you getting that? What exactly is meant by "when a program is started"? There are multiple stages to program startup.
But yeah, these kinds of implementation details usually do not matter- and in fact, different environments might do different things, so it's best not to worry too much about them.
Re: Need some hints (two questions)
Quote:
Originally Posted by
Norm
To understand that you need to learn assembly language, learn how the linker program works and how the loader works and how the OS gets involved when you start executing a program.
None of which is really needed for java programming.
Obviously what you're saying is true. Of course it's not needed, but I think it's good to know .. however it's just my curiosity that matters here :)
Re: Need some hints (two questions)
Quote:
Originally Posted by
obel1x
Obviously what you're saying is true. Of course it's not needed, but I think it's good to know .. however it's just my curiosity that matters here :)
If you're really that curious, the JLS is your friend: Execution