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.
This is a subjective question just to get a general impression. As Java is the most popular programming language right now it is used as a benchmark.
Lets say I have to spend T amount of time/effort to learn/master Java. By what factor should I multiply T to get a time/effort needed to learn/master other language instead, say C, C++, C#, python, perl, Lisp, Haskel, PHP?
My guess is:
0.5T PHP
0.9T python
1.1T C#
2.0T C++
3.0T C
What do you think?
Personally, I'd suggest Brainfuck. It's my favourite language for beginners. Don't worry, the name is joke!
Dartmouth BASIC was designed to be easy to learn and easy to use. For what it did, it was a howling success on both counts.
MIT used Scheme (dialect of LISP) in course 6.001 for many years, and concluded that it was a lot easier to learn, at least initially, because there was essentially no syntax to trip students up.
Back in the late Steam Era, when mainframe dinosaurs still ruled the Earth, the UT Austin Computer Science Department did side-by-side tests, teaching FORTRAN to some of the freshman and PASCAL to others. Their conclusion was that PASCAL's pickier syntax was INITIALLY harder to learn, but the PASCAL students consistently spent less computer time, and less runs (batch processing, punched cards), getting their homework running, even though their homework assignments were typically harder.
C and C++ have very, very similar core languages. 90% of the code you write will be identical in all four languages, after allowing for personal taste in design and naming conventions. C doesn't really have anything above the core language, while C++ adds classes and templates. I'm not familiar with C# or Java, beyond a rudimentary feeling that they both started with C and went from there.
Ada was, in my personal experience, not difficult to learn, and the compilers were picky enough that syntactically-correct code generally worked as intended on the first try. Other people have also noticed that property of Ada.
This is so subjective that it cannot be answered. It totally depends on what you need to do with the language.
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 10 years ago.
In class the prof said one reason he likes C better than Java is that C has a preprocesor, and in particular macros. Is there any benefit to macros over declaring afinal/const variable with the desired value? I know Java doesn't have global variables so would there ever be a situation where using a variable in substitution for macros would not work?
Using a macro system in C has been a long standing tradition that often leads to incomprehensible build chains, and very project specific build configurations. I would argue that the reason that macros exist in C is to overcome the shortcomings it has as a language for when you need things that macros provide (for example, you can use interfaces in Java, which solve the problem of needing to make a "generic" instance of something).
Still, there are times when having a macro system just seems to fit a problem easier. I do know of some shops that do this -- for example -- when they need to support multiple different versions of an API. Generally you can overcome this problem in Java by proper use of interfaces and a good abstraction layer in your design. However, there are macro systems for Java out there! You can use them, if you please. You might also note that, as far as macros go, C macros aren't really anything very special.
(In my opinion your teacher was somewhat off base...)
There's no reason you can't run your Java code through a macro preprocessor; it's just not done as part of the language.
With that said, most of the reasons macros are valuable in C are matters of the C language, and most people's use of them is extremely ugly and counterproductive, though they do have many good uses too.
Anyway, I would really question the expertise of someone who compares C and Java on the basis that one has macros and the other doesn't. In the big scheme of things, that seems to be one of the most trivial differences between the languages. Highlighting it suggests to me that the person does not understand the real differences between the languages; perhaps he likes C but doesn't know how to name any of the actual features C has over Java - things like storage duration and representation of types.
Macros in C are not just global constants. They can also define functions, like
#define SHOW_DEFINE(x) printf("%s=%s\n", #x, STR(x))
This can be quite helpful during debugging. It is unfortunatly also easy to hurt yourself quite badly with Macros.
#define MULTIPLY(X,Y) X*Y
works fine for, lets say MULTIPLY(1,2) but leads to problems if one uses MULTIPLY(1-1,2-2) = 1-2*2-2 = 1-4-2 instead of the expected 0*0.
Usually, with modern tools such functions are not longer necessary and with a good design and some abstraction and the interfaces that Java provides it is in general not necessary to have macros in Java. Java is designed, afaik, to make it as hard as possible to shoot yourself.
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 often use the Stack data structure in both Java and C++. This is a standard data structure, very common in implementing many algorithms.
My question is (and the thing that drives me crazy) why does C++ use "top" as a function-name that returns the top-most element value without removing it, and Java uses "peek" as it's method name?
I know there is no standard for data structures, but hasn't computer science come far enough along that there should be a standard? Or am I just too much of a novice to know about a standard...
Do those of you that are professional programmers write your own data-structure libraries that adhere to a common interface across languages? That seems like the best thing to do, in my mind. I write code in C++, Java, Python, C, Perl, and PHP. I just don't see any other way but to write a custom interface for all of these languages. I like "peek", but is there any standard I should be aiming for?
Writing a custom interface just to make method names the same would be a colossal waste of time. What exactly would be the point? You wouldn't be able to easily copy-and-paste most code between the languages you've mentioned even with such a feature.
Personally, I don't like the name of the STL vector method push_back(). I would prefer if it were just called add(), for one thing it'd be less typing. It never occurred to me that I might change it, however. Doing so would just make my code less portable and less readable for others. Now, I suppose this could be done fairly easily with a pre-processor macro, but even that would be a waste of time in my mind.
No there can't be, won't be, and never will be a standard. Anyway, both names are valid, and if you ask me, top makes more sense. Also, as #mimicocotopus says, it's not like having the same method names would let you copy paste code from one language to another. Also, languages like C++ and Java are very distinct, and support different features. If a standard had to use the lowest common denominator, it couldn't take advantage of all of the features of the language it was implemented in.
Anyway, remember what happened last time we standardized something? Cross browser compatibility and porting C code. It gives me shudders just to think of it.
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).
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.
What are good resource to read up on for implementing numerical algorithms in pure java?
I know nothing about the interactions of the JVM & GC, and would love to learn more.
I enjoyed Object Oriented Implementation of Numerical Methods by Didier Besset. To be honest I use C++ almost exclusively but found this book interesting and fun nonetheless. It doesn't always use the best algorithm for the job, however.
I would also point you towards Matrix Computations by Golub & Van Loan. Not about Java by any means, but a mandatory text for anybody working in this area.
Pick up a copy of Numerical Recipes in C++. NR doesn't always contain the best algorithms for the problems it tackles, it's a pedagogical text not a library of optimized code. But the explanations are generally good and the range of topics is wide. By picking up the C++ version you can learn some Java while you translate the code. Also pick up a good book on the basics of floating-point arithmetic and numerical analysis.
Numerics: http://math.nist.gov/javanumerics/
GC intro: http://www.ibm.com/developerworks/java/library/j-jtp11253/
Java Number Cruncher is a good start. I don't think it deals with GC issues, though. Anyway, floating point precision issues are quite likely more relevant in numerical algorithms, usually. The book does demonstrate that doubles can actually be inferior to floats in some cases.
Apache Commons Math has some nice linear algebra libraries, among other things.
Linear algebra is the basis for lots of serious numerical work (e.g., finite difference, finite element, and boundary element formulations for problems in solid and fluid mechanics and heat transfer). AFAIK, most of that work is still done by commercial and in-house packages written in FORTRAN. Java and even C++ and C were not considered performant enough for such things back when I did them for a living. I'd be surprised if that has changed.
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'm wondering what's a good online judge for just practicing algorithms. I'm currently not very good at writing algorithms, so probably something easy (and least frustrating) would be good.
I've tried the UVA online judge, but it took me about 20 tries to get the first example question right; There was absolutely no documentation on how to read input, etc. I've read about Topcoder, but I'm not really looking to compete, merely to practice.
Take a better look at topcoder. Yes, they have competitions, but you can still easily just "play" by yourself. You are given a goal and a time limit and you choose your language, and then you code it. You can view the source code of the best coders to improve yourself.
I have used topcoder for awhile and have never been in any competition. Check it out.
You may also want to check out Project Euler. Not a judge, but there are mathematical problems and solutions available for many languages.
Have a look at SPOJ
CodingBat might give you some good practice. It responds instantly with test results.
This is a year old by now, so my answer is for future stumblers.
The ACM-ICPC Live Archive has a lot of great problems, and in a lot of different areas. (Project Euler is also great, but the problems are all number-theoretic.) And hoop-jumping is normal with these things... last I checked, Facebook Puzzles requires you to email a zip file containing the code and an Ant buildfile, and they take a long time to get back to you.
I've only sent Java code to UVa, so I'll elaborate a little on the Java particulars for anyone else who's struggling. Your class must be called Main, and its entry point must be the main method. You read from System.in. If you're on a Unix-y platform, after compiling you can use
Java Main < input.txt
to test your program.
The presentation has to be exact. For example, if they say "outputs should be separated by a blank line," that does not mean, "follow each output with a blank line." Finally, don't be afraid to check out their forums.
Reference: http://online-judge.uva.es/board/viewtopic.php?t=7429
(In their sample code, they read the input byte-by-byte. Don't do that; use Scanner instead. It's also not necessary to have the main method create an instance of the class. You can go 100% static, and often the problems are small enough that OOP doesn't buy you anything.)