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 13 years ago.
Question about Cassandra
Why the hell on earth would anybody write a database ENGINE in Java ?
I can understand why you would want to have a Java interface, but the engine...
I was under the impression that there's nothing faster than C/C++, and that a database engine shouldn't be any slower than max speed, and certainly not use garbage collection...
Can anybody explain me what possible sense that makes / why Cassandra can be faster than ordinary SQL that runs on C/C++ code ?
Edit:
Sorry for the "Why the hell on earth" part, but it really didn't make any sense to me.
I neglected to consider that a database, unlike the average garden-varitety user programs, needs to be started only once and then runs for a very long time, and probably also as the only program on the server, which self-evidently makes for an important performance difference.
I was more comparing/referencing to a 'disfunctional' (to put it mildly) Java tax program I was using at the time of writing (or rather would have liked to use).
In fact, unlike using Java for tax programs, using Java for writing a dedicated server program makes perfect sense.
What do you mean, C++? Hand coded assembly would be faster if you have a few decades to spare.
I can see a few reasons:
Security: it's easier to write secure software in Java than in C++ (remember the buffer overflows?)
Performance: it's not THAT worse. It's definitely worse at startup, but once the code is up and running, it's not a big thing. Actually, you have to remember an important point here: Java code is continually optimized by the VM, so in some circumstances, it gets faster than C++
Why the hell on earth would anybody write a database ENGINE in JAVA ?
Platform independance is a pretty big factor for servers, because you have a lot more hardware and OS heterogenity than with desktop PCs. Another is security. Not having to worry about buffer overflows means most of the worst kind of security holes are simply impossible.
I was under the impression that
there's nothing faster than C/C++, and
that a database engine shouldn't be
any slower than max speed, and
certainly not use garbage
collection...
Your impression is incorrect. C/C++ is not necessarily faster than Java, and modern garbage collectors have a big part in that because they enable object creation to be incredibly fast.
Don't forget that Java VMs make use of a just-in-time (JIT) engine that perform on-the-fly optimisations to make Java comparable to C++ in terms of speed. Bearing in mind that Java is quite a productive language (despite its naysayers) and portable, together with the JIT optimisation capability, means that Java isn't an unreasonable choice for something like this.
The performance penalty for modern Java runtimes is not that big and programming in Java is less error-prone than in c.
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.
Why does Java have much better performance compared to other interpreted languages like Python? I know this probably has something to do with the fact that it's compiled beforehand, but what about concurrency?
How is the JVM able to perform so much better with concurrent programs, whereas interpreted languages have to do deal with things like global interpreter locking etc, that really slow things down?
This is a really interesting question, but I'm not sure there's a simple way to answer it. JVMs these days use a range of highly aggressive optimizations to try to improve performance. Here are a few:
Dynamic compilation: Most good JVMs can dynamically compile the bytecode directly into machine code, which then executes at native speeds.
Polymorphic inline caching: Many JVMs use inline caching to try to improve the performance of method dispatching by remembering which functions have been called in the past.
Static typing: Since Java is statically-typed, bytecode instructions rarely have to do expensive introspection on the type of an object to determine how to perform an operation on it. Field offsets can be computed statically, and method indices in a virtual function table can be precomputed as well. Contrast this with languages like JavaScript, which don't have static typing and are much harder to interpret.
Garbage collection: The JVM garbage collector is optimized to allocate and deallocate objects efficiently. It uses a combination of mark-and-sweep and stop-and-copy techniques to make most allocations really fast and to make it easy to reclaim lots of memory quickly.
Known choke points: Rather than having a huge VM lock, some JVM implementations automatically insert extra code into each piece of compiled/interpreted code to periodically check in with the VM and determine whether they can keep running. That way, if the JVM needs to do garbage collection in only a few threads, it can do so while the other threads are running. If it needs to do a stop-the-world operation, it will only occur when the threads hit specific points, meaning that simple operations don't have to continuously check in with the VM state.
There are many, many more optimizations in place that I'm probably not aware of, but I hope that this helps you get toward an answer!
Java code has next to no optimisation during compilation.
The runtime JIT does most of the compilation.
What may be different about Java is that it relatively feature poor with minimal side effects. This makes the code easier to optimise.
whereas interpreted languages have to do deal with things like global interpreter locking etc, that really slow things down?
This is an implementation issue. Java was designed with multi-threading support from the start. I suspect python was designed for scripting and rapid development cycles, something it does much better as a result.
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'm a php developer, but recently had to write the same application twice, once in php and once in java, for a class I'm taking at school. For curiosity I did a benchmark on the two and found that the java version was 2 to 20 times slower than the php version if the database is accessed, and 1 to 10 times slower without DB access. I see two immediate possibilites:
I suck at java.
I can finally tell people to quit whining about php.
I posted my servlet code here. I don't want any nit-picky whining or minor improvements, but can someone see a horrible glaring performance issue in there? Or can anybody explain why Java feels like it has to suck?
I've always heard people say that java is faster and more scalable than php, especially my teacher, he is convinced of it, but the more requests that are made, the slower java gets. php doesn't seem to be affected by increased loads but remains constant.
In a mature Java web application the Servlet would make use of an existing JDBC connection pool. Establishing a new connection will be by far the greatest cost you pay in time.
Calling Class.forName for every attempt to get the connection will also cause an unnecessary slow down.
JVM tuning could also be a factor. In an enterprise environment the JVM memory and possibly GC configurations would be adjusted and tuned to achieve a desirable balance between responsiveness and resource utilization.
As Stephen C points out, the JVM also has a concept of a sort of "warm up".
All that said, I have no idea how PHP compares to Java and I feel both languages offer great solutions to separate non-disjoint sets of needs.
Based on not much info (where the best decisions are made), my guess is the Class.forName("com.mysql.jdbc.Driver"); in getConnection() is the big timesink.
Creating a new String in importFile when the char[] can be passed to out.println is me nitpicking.
Your test seems to reflect initial overhead moreso than steady-state performance. Try doing the non-DB tests multiple times in a loop (so that each test wold run the code multiple times) and look at the linear relationship between runtime and number of iterations. I suspect the incremental cost for java is lower than that for php
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.
over the years i have been employed in a permanent position with firms that did their development work in Windows SDK, VC++, and most recently Java; in my own eyes, I am language independent.
Should I move from Java to Delphi (assuming pay-scale remains unchanged)?
I'm concerned because, for the most part, the net presents a relatively bleak picture for this particular skill.
The TIOBE Index is an often cited source for estimating the popularity of programming languages. Java, C and C++ have been the top 3 for a very long time. As you can see, Delphi is a lot lower on the list (at position 10 at this moment). (Ofcourse you should not take the TIOBE Index as an absolute measure, but it does indicate something).
This can be an advantage as well as a disadvantage. There are probably a lot more Java and C++ jobs than there are Delphi jobs, but there are also a lot more Java and C++ programmers than Delphi programmers, so it's harder to stand out as a Java or C++ programmer among the masses. Having a specialism that not many people have, such as for example Delphi, may help you get a higher salary, though you'll have to search harder to find Delphi jobs.
Depends on what your goals are, but I believe that for regular apps the future bears name "GWT", i.e. Java. (I consider Delphi a history for quite a while, but that's JMO.)
It's definitely worth learning Delphi. A lot of software's still being written in it, stuff which people use and rely on. A lot of companies prefer to keep quiet about it, though, since it presents such a major competitive advantage over other, more popular languages.
For example, you ever work with VOIP on chat programs? In my experience, there are two basic categories: Skype, and The Other Stuff. Skype "just works", while the others tend to be very glitchy and unreliable. And it's no coincidence that Skype's written in Delphi while (AFAIK) none of the other chat programs are. That's just one example among many.
It never hurts to pick up another skill, but I haven't seen any Delphi job listings anywhere. I suspect you would be better suited picking up a new language/framework/platform with more "legs", such as WPF, JavaFX, Objective-C/Cocoa, ActionScript/Flex, or something of the like.
As a technical move, it's probably a good one -- Delphi is better thought out and more enjoyable to use. From a career perspective, however, you're probably right -- Delphi has been rather marginalized for some time now, and doesn't seem to be in the process of making a huge comeback.
I was using Delphi before I swtiched to C++ and then to Java. I don't think that moving from Java to Delphi is wise idea. Why so?
Java is widely used
It's easier to find Java job
More years of Java -> Better chance getting senior position job (java oriented)
Java is definitelly richer as for libraries
Java rocks in enterprise sphere, Delphi doesn't
It's easier to find resources for Java - from tutorials for beginners to manuals for professionals
Java runs on other operating systems by default, remember? (I know Lazarus, but can't compare port to nativeness)
From my exprience, more experienced programmers and software engineers kind of condemn Delphi programmers ...
Java is suitable for larger projects (means bigger money)
The only good reason for preferring Delphi over Java I can actually think of is making Windows GUI application. But since we have .NET and wonderful WPF, Delphi doesn't score even here.
You make your choice, but personally, I'd never switch back to Delphi (ok maybe if payment was too good to reject:))
The way you phrase your question makes me think you've got a job offer already for a Delphi developer position. If the language is the only thing stopping you, I say you should go for it.
It will add experience with another language to your resume besides being fun (learning something new). Just make sure you keep your skills in Java and C++ reasonably up to date when or if you need to move on.
Why limit yourself to one language?
A major problem with Delphi is that some people consider it an "easy" language. So there are Delphi programmers that can drag some controls to a form without any real coding knowledge. So if you are a good developer and skilled in Delphi, you won't have that much trouble finding a job.
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've had an argument with a friendly coder who was mildly damaged by Joel's Law of Leaky Abstractions. It is very hard to convince him of using any new framework/toolbox at all. I'm trying to present a point where "abstractions are fine as long as they allow low-level access to abstracted level".
Examples:
GWT - Google's superb Java-to-Javascript compiler, has JSNI - ability to write "native" Javascript if you really want to.
Hibernate - AFAIK has SQLQuery - way to write native SQL.
Java - JNI - if you miss C.
Is it sound?
Am I missing something?
Thanks
What I took from reading the leaky abstractions article wasn't that abstractions were bad, but that you should make it a point to understand what goes on under the hood, so that you can account for "unexpected" behavior, and avoid them.
What does your friend program in? Machine language? :)
Joel's point (as I understand it) is that by abstracting complexity away you are sacrificing the finer control over that underlying complexity. For anything but trivial cases you will eventually need to access that finer granularity of control at which point the abstraction breaks down.
So all abstractions are leaky (almost) by definition :
If there is complexity in a system, it must be there for a reason (or you should find a way to remove it) and so will occasionally be useful/vital.
By abstracting you are limiting the control you have over the underlying complexity.
When those 'occasionally's come along you will have to break the abstraction.
To some extent he has a point. Traditional c/unix development works to a platform that is simple enough to be able to understand more-or-less in its entirety. Modern platforms are orders of magnitude more complex, and understanding how all of the layers interact is much harder, often infeasible.
The law of leaky abstractions mainly applies when the framework does a bad job of managing the underlying complexity. Some of the ways in which a framework may be judged are its transparency (ease of understanding what's going on behind the scenes) and its ability to drop out to a custom workaround for limitations in its functionality.
When a framework does a lot of complex magic behind the scenes, diagnosing and troubleshooting become much harder, often requiring a disproportionately large amount of expertise in the underlying architecture of the framework. This means that productivity gains from the framework get absorbed in the extra effort of training and debugging the code. It also makes the framework difficult to learn and use with confidence, which is what your C programming friend is used to.
When a framework obstructs you from working around its limitations, then it becomes an impediment to development. When this happens often enough, the code base is either boxed in or becomes polluted with ever greater and messier hacks to work around the issues. This also leads to stability and debugging problems,
Examples of frameworks with these flaws abound. MFC was quite famous for failing to hide the underlying complexity of Win32. It also made extensive use of wizards that generated messy code that needed to be manually modified aftwrwards, defeating the purpose of having a code generator in the first place. Early Java GUI toolkits (AWT and early versions of Swing) have very little uptake in desktop applications because they obstructed developeers from implementing a native look-and-feel for the applications. SWT was built in no small part because of these limitations with Swing.
However, now Java has matured a bit, it could be argued that most of its early sins have been fixed in modern frameworks. J2EE is still a large, complex system, and developing a non-triviall user interface in a browser is also quite a substantial undertaking. Becoming proficient in this platform is quite a lot of work. However, it's not beyond the wit of man.
While I think its true that every abstraction is leaky, that is not necessarily a bad thing.
For example in traditional plain C (C#, Java, whatever) code you usually retrieve data from arrays by using loops, ifs etc. But that way you overspecify your solution to a problem.
The way SQL, Linq approach the same problem is more intelligent: You just say WHAT you want, the machine figures out how to do it. This way it is free of any specific ordering of commands from the traditional way and can split the work onto different cpus for example, or reorder stuff to make better use of caches etc.
So yes you give some control to the machine, but the machine has one big advantage over you: It is at the user/customer's place and that way can make on-demand decisions (like using multi-core, using advantage of MMX, whatever).
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 always hear that programmers try to pick the right tool for the job. I've never programmed in Java, so I was wondering What are its benefits? Why is it so popular? What should I use it for?
I just program recreationally. Is there anything about it that makes it particularly fun??
I think after 12 years or so, the "write once, run anywhere" mantra is almost true. Writing Java code pretty much isolates you from the platform dependent aspects of the systems on which you deploy it.
Portability
Incredible breadth of libraries
Bottom-up security
Performance
Robustness
Massive communities, the amount of help, libraries, IDE's, is huge (and thats a good thing).
For a casual programmer Java can teach a lot about object-oriented programming, and encourage good programming habits in general, without the need to worry about as many of the "messy" details (pointers, memory management) as, say, C++.
It's also a bit easier to debug "catastrophic" errors.
Java is really good at integration - there are specifications and implementations for integrating with many kinds of systems that you're likely to run into in an "enterprise" environment.
It's not really a "fun" language relative to popular high-level languages.
This seems to be getting healthy answers, but you might also want to look at "Why do people use Java?"
Java is a good language, but that is secondary to the importance of the standard library that comes with it. The jdk may not be the most elegant kit ever built, but it is extensive, powerful and reliable. Programming in Java the language is simple. Programming with appropriate reuse of the jdk is what it is all about.
Cross platform is in my opinion the most relevant benefit.
The main goal of Java was to create a programming language that could run anywhere. The target was GUI apps. This however never happen because the environment was too slow at the beginning ( now it has been improved ) but it prove true in the server side where the cost of development reduced a lot because the product development can be done in PCs and the deployment in very expensive hardware.
It brought easy of development also, because it was designed to have C++ like syntax but running on a virtual platform to avoid platform specific code. At first the penalty was the execution speed, because it was interpreted, but release after release the interpreters became more and more faster that even MS model its next generation of development after java and call it .net
Additionally You can have a read of the Java design goals here
I want to add one point: Java keeps a good compatibility to earlier versions. That means, your Java-projects are compile and run in most cases without any problem on newer versions. That seems to be a little point, but this stability in API's and language helps to build a big community around Java, including good tool-support.
Others already mentioned other important points:
good portability
lot's of libraries for nearly anything
easy debugging and easy to catch problems
There are only two reasons to use Java:
The Java Virtual Machine (Hotspot).
The huge amount of available libraries and tools.
There are other languages that run on the JVM and make better use of Java libraries than Java does, however.
After using Java for some time, I've come to the conclusion that it's fun to write in, limited in some very irritating ways, and it's performance is good though it seems that many programs are crippled by poor design.
I'm not sure if the latter is a function of Java, or an effect of Java.
In either case, in addition to all of the above stated benefits it's very useful for doing "net" related things. Treating resources with a simplified interface regardless of "where" the particular resource is, etc...
It is by no means a universal hammer.
oop provides like encypsilation ,inheritance,polymorphism not available in traditional programing .oop is closer to real life presentation of the programming
1. Relation ships can be representation using inheritance
2. Programme developement become easy due to increased modularity