As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am reading OOPS concepts and got stuck on Abstraction. I am not able to fully understand the concept. As I am feeling that it doesn't belongs to OOPS only. It was also used in C. But how
java abstraction different from C language abstraction. I know it is not a good question
for this forum but i am not able to get the perfect answer.
abstraction means to hide or to separate the complex details of one part of code to other part. say, you have to use a method that does complex calculation, and gives some result. So instead of writing your method inline, its better to write it in a method that just expose the signature (params and return type). in that way your caller (of method) remains unaware of complex code behind the method.
in general, when you use library function in c/c++ or APIs in java, it is also an abstraction.
So indeed, abstraction is not only OOP, but a general concept can be applied anywhere (even beyond the programming).
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
In Java theoretically you can throw only Throwables.
This is allowed by the language and checked during class-loading. But if you disable class checking
java -Xverify:none -cp . BadClassThatCompiles
then you can run a class that throws any class (not derived from Throwable) (Example)
Why?
Why is it designed this way .. meaning a virtual machine that allows throwing objects and a verifier that has to filter out wrong code. As if some code could be wrong. It's not the code, it's the design!
Why?
Why is it designed this way .. meaning a virtual machine that allows throwing objects and a verifier that has to filter out wrong code. As if some code could be wrong. It's not the code, it's the design!
Why?
Simply because the design works from almost all perspectives.
Well what would the alternative be?
I guess you would have to have a special kind of "things" that were NOT instances of classes that were designed for the sole purpose of being thrown.
That would require:
a new syntax for defining these exception non-objects
a whole new set of typing rules to handle these non-objects (for instance they cannot be assignment compatible Object ...)
and so on.
At the end of the day, the Java language would be more complex, and harder to use for the programmer. And to what end? To slightly simplify the task of the verifier?
Sorry, but if you take it to its logical conclusion, this idea is a non-starter.
And frankly, who cares if you can break the JVM by disabling the verifier. Its like complaining that you can shoot yourself if you juggle loaded pistols.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am experiencing the pain of developing an API based on (Selenium2) Webdriver and here is my dilemma.
I have basically 4 packages:
com.example.qa.pageobject
com.exmaple.qa.setup
com.example.qa.test
com.example.qa.utils
In com.example.qa.test, i have test classes that "USE" classes from other packages.
I am ending up in the following test method.
#Test
public void testScenario16786() {
Login login = new Login();
login.setUp();
AddSingleDomain asd = new AddSingleDomain();
asd.addSingleDomain();
AddARecord ar = new AddARecord();
ar.AddARecordTest();
}
Now, this seems to be a very bad example of developing in Java, which almost seems procedural. Is there any other way of doing it ? Are there some RULES that i need to be aware of while designing an API, which will be used by others ? i am sure that this is somewhat of a classical problem and has been solved before, i just want to know what are the many ways of resolving this, like:
One resolution, could be to use Factory Pattern, and based on a key, a specific class is instantiated, which is good but is there a more elegant way ?
Your test class is necessarily procedural - a repeatable set of steps, that's fine.
The commonly recommended approach is to use the Page Object pattern and selenium also provides a PageFactory object to help you (see end of the page):
page objects
You might find the presentation "How to Design a Good API & Why it Matters" by Joshua Bloch to be helpful.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I heard one of my colleagues saying that Java handles recursion more efficiently than c or C++, I was just curious what why is it able to do so? I mean what is "under the hood" process that makes this happen.
All efforts appreciated.
The usual issue around recursion (not 100% sure this is what your colleague was referring to) is whether 'it' (the compiler, the JIT, the runtime, whatever) can (and does) implement 'tail call optimization'. The goal is that instead of having the code make 'real' calls (introducing a new frame onto the call stack) that recurse (either into the same function or through the same 'cycle' of functions), you can get the same effect without doing so.
The wikipedia page is pretty decent on describing it.
http://en.wikipedia.org/wiki/Tail_call
If it's correct it's because the JIT compilation is able to optimize a recursion better than the C compiler. http://en.wikipedia.org/wiki/Just-in-time_compilation
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
There are a number of Java programming practices that I commonly see in use that can be optimized to provide significant speedups.
Example: For lot's of + operations on Strings, use StringBuilder instead.
What are some simple, useful optimizations one can make to potentially improve your program's performance by a significant amount?
EDIT: I'm not looking for trivial premature optimizations. This is not my intention in asking this question. Instead I would like to learn common constructs/mistakes that do constitute a significant performance hit.
Spend at least an order of magnitude more time thinking hard about the most efficient algorithms and data structures for the problem as you do thinking about how to micro-optimize specific operators, control-flow constructs, etc.
See (1)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
I know that is Collections.sort() method in Java but I think quicksort is worth to remember and try.
My work target is general Java: web, database access, integration, not game developer, scientific application or another one that depends on advanced algorithms.
Which algorithms should I learn to pass without stress Java developer interview?
Fizz Buzz
I usually don't care, if a developer knows the basic algorithms by heart. I do care, if he is capabale of understanding requirements and translating them in correct, testable and understandable pieces of code.
Ah, and I do care if he knows how to implement the most common design patterns. And he should know when and how to use collections, threads and - String#split - it's amazing how many "developers" don't know how to read and process a simple csv file.
Although I fully agree with Joachim comment, I would go for : collection selection. This is not an algorithm per se, but rather a good view of which collection is good for which purpose :
sorted content with constant lookup time ? TreeSet !
mapped data with memorization of insertion order ? LinkedHashMap !
using that, and some knowledge of design patterns behind collections, you will far too often reply to algorithms questions using the knuth answer (or the subtle variation : as long as Sun developpers implemented it correctly, I only have to choose wisely).