Importing classes. What is more efficient? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Is it more efficent for the compiler to import specific sub classes or more vague super classes?
Classes that I'm Importing

import statements don't require any runtime execution so there is no difference in efficiency. All that these imports do is establish a shorthand so that when you say 'File' the compiler knows you really mean java.io.File.

The import statement is pure syntactic sugar for the compiler. There is no difference in the resulting bytecode, thus no difference in runtime efficiency.
Instead, you should focus on what makes your code clearer to read - and in most cases (in my experience) more specific types are better (as oppose to wildcards.)

Related

Difference between class declaration [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
What's the difference between declaring a class inside of another class and declaring a class in a separate file?.
Literally, nested classes were added to Java for two reasons:
1. Source code clarity.
2. Name-conflict reduction.
Java actually didn't need to support doing this, but they were totally doing programmers a "solid" because I'm sure they know how messy code can get when you're in the moment of it all.
To answer your question, explicitly: The difference is that there really IS NOT a difference, it just makes code easier to read and you end up with less name-conflict mistakes.

why do virtual machine check the field type? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
As an example, take a getstatic bytecode opcode.
JVM perfoms a check whether the reference field is static(or may be instance?)
Isn't it redundant step? Because, compiler ensures the field is static.
PS perhaps, the point is bytecode could be altered during the run time.
Isn't it redundant step? Because, compiler ensures the field is static.
If someone creates the bytecodes by hand (or using a bytecode modification library), then those compiler checks don't happen. That's why we need to verify the bytecodes ... at load time.

can anyone tell me why java doesnt support multiple inheritances........? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i tried to create a calc class which will have methords of mathematical operators which are not in java already..........
now after i created it ....if i wat to use this class functions i will have to make it a super class for my new program but .....if i want my new program to have multiple attributes of diffrent classes .........and simultaneously use calc functions........but i cant..............
why java doesnt have multiple inheritances.......what are its advantages and disadvantages?
tnx in advanced...
Java doesn't support multiple inheritance because of the "diamond problem" and other problems that arise from "increased complexity and ambiguity" as is explained in the wikipedia page on the matter
The creators of Java had a design goal of simplicity. That is why operator overloading with the added complexity of the "copy constructor" was also left out. That is why there is automatic memory management etc etc
most modern languages chose to discard this concept for the same reason.

Long function names in fortran/c/python and speed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This question is not at all related to this one When is a function name too long?
Can execution speed suffer because you have a function with a long name that is going to be repeatedly called from numerous places thousands of times? Do optimization flags take care of this in compiled languages so that there is no problem? Then what about interpreted languages like python?
In (typical, static) compiled languages it doesn't matter at all, and has nothing to do with "optimization flags".
In such languages, the function names are strictly something used at compile-time to identify things. They are replaced with actual addresses (or offsets) in the final machine code. No name look-up occurs when you call a function in C.

How does Casting limit Algorithm Reuse in java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
We are learning about both of these things in Java class right now. I believe I understand the basic aspects of both, but not sure about how Casting ends up limiting Algorithm Reuse. Our teacher said we need to know this for the test next week. Can anyone explain this?
If you cast you are limiting your algorithm to only work with one Class (or it's children). If you were instead to use an Interface you would be able to accept a greater variety of Objects that themselves implement that Interface. Much more flexible.
Here is a related SO question: Explaining Interfaces to Students
When you use casting in your code, you must know the exact type that you cast to (during the code write phase). Hence your code can't be reused in the future with different types. Always remember to program to interface instead of to specific type.

Categories

Resources