Home arrow static arrow Java Programming [Archive] - java compilation and several other questions
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - java compilation and several other questions
This topic has 6 replies on 1 page.

Posts:28
Registered: 8/2/04
java compilation and several other questions  
Aug 2, 2004 12:21 AM



 
I have several questions:

1. Consider two java programs, one use package by import packages. Another is just put all classes and files in one folder. What are the differences in terms of the compilation process, compilation time, execution speed, class file size, and memory usage at runtime?

2. Is it possible that one class ClassB extends an abstract superclass ClassA without implement some of its abstract method, instead, we let ClassB's subclass ClassC implement the abstract method?

3. I read some big java program. In the program .java files in a same package distributed in different folders. How can this happen? eg. several files are in package mypackage.subpackage. Then i saw .java files in pathA\mypackage\subpackage\, and also some in pathB\mypackage\subpackage\
How can the JVM deal with this kind of situation?

4. In Java, what are the differences between "public static void main(String[] args)" and "public static void main(String args[])"? How about in C/C++?

Thanks

Regards
Andrew
 

Posts:12,831
Registered: 2/22/00
Re: java compilation and several other questions  
Aug 2, 2004 1:14 AM (reply 1 of 6)



 
1) If there are any differences in those issues, they pale in comparison to the code management issues of not using packages to organize your code. Developer time is important. That's why we're using Java and not assembler.

2) Yes, but if you don't believe me, try writing a test. You could have done that already.

3) The JVM just looks at the classpath, and grabs the first class it finds on the classpath for a given classname. But you're talking about source files anyway which isn't the same thing. The compiler can easily read files in any given directory (assuming you're using it right) and put them in the appropriate target directory, possibly overwriting other class files. It's just a matter of reading and writing files. But at this point I'm not sure if we're talking about the same thing.

4) No difference, although I think the former is cleaner. In C and C++ both of those may or may not be valid code. They really are different languages.
 

Posts:28
Registered: 8/2/04
Re: java compilation and several other questions  
Aug 2, 2004 2:29 AM (reply 2 of 6)



 
Thank you for your fast response.
I have also tested the question 2. You are right!
For the first question, i am sorry i didn't get you. using package save development time or not? depends?
By the way, i have another question.

Can java distingushs two methods by their return type? I wrote a small block of codes to test it. Java complains at compile time. Then regarding method overriding, we should modify something. Method overriding can only realized by providing different parameter lists to the method. Difference of return type is not crucial at all.

Am i right? If yes, why so many books talked about method overriding and mentioned using return type to distinguish two different methods?
 

Posts:12,831
Registered: 2/22/00
Re: java compilation and several other questions  
Aug 2, 2004 4:41 AM (reply 3 of 6)



 
Writing quick little tests is a great way to learn the intricacies of a language, or to prototype solutions. It's a good practice.

For the first question, i am sorry i didn't get you.
using package save development time or not? depends?

Using packages when you have more than 10 or so classes will save development time by letting the developer quickly navigate the code.
Organizing them into packages helps keep everything sane, manageable, etc.

Also, more importantly, using packages means that you can use package-based access modifiers, which means that you'll be writing more solid, modular code.

Can java distingushs two methods by their return type?

IIRC, that's not allowed. Overloaded methods must have the same return type.

Method overriding can only realized by providing different
parameter lists to the method.

I think you mean method overloading. Overriding is when you create a new method with the same name and parameter lists as a method in a superclass.

I'm not sure I understand the rest of the question.
 

Posts:21,718
Registered: 98-02-20
Re: java compilation and several other questions  
Aug 2, 2004 4:47 AM (reply 4 of 6)



 
4. In Java, what are the differences between "public
static void main(String[] args)" and "public static
void main(String args[])"? How about in C/C++?

No difference in either, AFAIK. It's a matter of taste in C++. I believe the first one is preferred in Java. That's the way I always write it. The square brackets should follow the type because then it makes clear that this is an array object. But my compiler will accept either one.

%
 

Posts:28
Registered: 8/2/04
Re: java compilation and several other questions  
Aug 2, 2004 8:53 PM (reply 5 of 6)



 
Thank you two for the explanations.
I feel this forum is a good place to learn java programming. I am also motivated to do more experiment. Maybe i should start new thread for other questions instead of pending a long thread. :-).

Regards
Andrew
 

Posts:28
Registered: 8/2/04
Re: java compilation and several other questions  
Aug 2, 2004 10:04 PM (reply 6 of 6)



 
paulcw, you are right. I misused the word "overriding". I mean "overloading" here actually. I checked from Internet regarding the return type issue, together with the some small experiment. I am sure difference in return type is never a condition for method overloading. Thank you for your explanations!
 
This topic has 6 replies on 1 page.