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 been a java developer for a couple years and have heard that you can do some pretty useful and powerful things with JNI. I don't know if I just haven't needed to use it or if it isn't terribly relevant to me; but I have not had to touch it at all.
I am wondering what the usefulness of this aspect of Java is. Examples would be great.
It is very useful. I can see 2 primary reasons to use JNI (there are likely more).
Performance. If you have a piece of code in which the Java Runtime for whatever reason can't cut it performance wise. You can implement that function in native code and call it from Java. This allows you to hand tune the implementation if you really need to. This is likely the least common reason though, Java usually performs just fine.
Access to OS Specific APIs. This one is a biggie. I've had a case where I needed to do something in Java but also needed access to something that Java simply could not provide. In my case it was UNIX domain sockets. Since (as you can tell by the name) they are UNIX specific, there is no standard Java way to use them. So I made a class that acted like a wrapper around them in C and accessed it with JNI. viola, problem solved.
I have written an extensive JNI layer for the iSeries to access DB2, user queues, data queues and a few other OS/400 specifics. Much of our system on the iSeries would have been impossible without JNI. So, yes, JNI has it's place, and when you need it, you really need it.
It's relatively difficult (next to pure Java), but powerful and not horrible.
Also, whenever I am looking at some JNI code, I also consider using JNA.
I can think of a few uses off the top of my head:
integration with existing low-level
(C/C++) APIs that do not have a Java
counterpart
integrating with aspects
of the system that are not exposed
through available Java APIs (direct
hardware access, etc.)
Some might say it can be useful for creating highly-optimized sections of code however with modern JVMs you're getting pretty fast and the complications of using JNI would probably outweigh any performance benefit you might see.
There are a few uses for binding to FFMPeg for C-decoding of (damn near any) video/audio format.
There's also JNA, which makes it like you are using the library itself. This is "easier" from the standpoint that it passes everything to the Java developer to manage, and harder in the sense that you have to figure out the structure mapping and do a lot of grunt work to get all the pointers, etc, to pass correctly.
We had an requirement to wrap a new UI around a legacy C application running on Suse Linux. JNI was the perfect tool for the Job.
In general I think JNI is a contradiction to the Java notion of Write Once, Run Anywhere. However there are use cases where JNI can be useful.
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.
Is it plausible(and/or practiced) to build a large piece of software, for example Altera Quartus II, using multiple programming languages? Meaning, the menus for the software are coded in c++ and maybe the core functional interface that the user interacts with most is built using java. Is this even possible? If so, what are the drawbacks/benefits of doing so with large pieces of software?
It is possible and practiced, however it is advisable that the core of your application is build in a mid-level programming language like c++ for performance, while the front end part and any utilities and interfaces to the core can be built using some other language like javascript.
Take a look at the Mozilla browser which is an example of c++ core with javascript UI.
Your question is about whether it is possible: the answer is it is. However I will try to extend a little bit by saying that your challenge in building an application with c++ and java would be the communication between the two parts of your application. You would need some kind of an intermediate like xml in order to do that.
It is possible to build applications from multiple languages, for instance, you could have your front end coded in C++, the back end written in Java and you use JNI for communication.
Although such an application allows you to exploit the features of each language, it requires developers to have expertise in multiple areas or have multiple developers, each of which can increase the cost of the solution being delivered.
Also, nowadays most compilers tend to optimize the code during compilation, so developers do not try and find micro optimizations which allows them to tweak every aspect of their code, unless they are writing something along the lines of AutoCad or Photoshop, each of which require a relatively high amount of system resources.
Another problem with solutions having multiple languages would be how to make them communicate together (sockets, shared memory segments, pipes, etc) so that would be another layer of complexity.
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 will be making a cross-platform, graphical mathematical modeling application, for example, a user can drop a bunch of nodes on a canvas, specify some mathematical relationships between them, and run a simulation. I'm also interested in seeing in this being a web app.
I have had some programming experience in Java, MATLAB, Python, but I have never made a large application, thus I know very little about software architecture, and how multiple languages work together.
I am trying to figure out the best IDE, language(s), etc., to work in. The previous work done by my group has a lot of C/C++ libraries to draw from for back-end work, like simulation. I was told by my boss that Java is an "island" for development, meaning the Java app has difficulty using libraries from other languages and making its own libraries usable to other languages.
Is this true? Can someone shed some light on this topic?
Also, then what tools should I be using? I am ready to learn anything, but I'm trying to go for what would be the most productive route. Learning and then programming everything in C/C++ does not seem like a very productive route to me currently.
Things I've looked at so far include WindowBuilder/GWT Designer (this seems like a way to make both desktop and web apps), Mono/GTK+/MonoDevelop, and Delphi
Please feel free to be as verbose as you can, thanks!
I fear this post may get closed as off-topic. But it seems a little too specific to toss, IMHO.
Java interoperates with a lot of non-Java projects, products, etc. However, a major feature of it is portability, so you'll find that folks go out of their way to stay within the JVM environment. In that sense it's an "island".
I suggest you think about exactly what you want to interoperate with and get specific - see whether the hooks are there or not.
For your back-end C/C++ libraries, you'll need to implement JNI interfaces. I'd describe this as having a small but moderately steep learning curve - not a lot to learn, but it takes a little thought - especially if the amount of data passed back and forth is so large that performance is an issue.
You may find that you don't have what you need with GWT for the graphical aspects of what you're doing.
I'd think hard about how much you need the web aspect. If you do, consider skipping a desktop-only solution (and maybe Java/GWT) altogether, and just going to the web. This is especially viable if you don't need to support older browsers.
I'm not going to touch the "what tools" question - it's too broad.
Considering Jython, Groovy, Clojure, and a whole host of other language adaptations for Java, I would firmly suggest that your boss does not know what he is talking about. Java also has the ability to execute native code if necessary, so it is not terribly difficult to incorporate other, non-JVM toolkits. But even if he were right and there was no cross-linguistic work with Java, the language has been around long enough, and it is verbose enough, that you can generally find libraries which will supply the inter-operability you're looking for.
Without knowing more about your specifics it will be hard to give a precise answer, but the general rule is that the language you know is better than the language you don't, so unless your language goes completely against the idioms required, use it. Eg. if you have in-house expertise in C/C++, those languages are perfectly adequate for building applications. JavaScript significantly less so.
You do not want bugs which are caused by faulty assumptions about the language. Those are nearly impossible to track, especially since you won't know where to look.
Well, if cross platform is an issue, I would suggest developing in Java, it makes everything very easy in that regard. As far as loading C/C++ libraries, I don't have much experience with it, but I would recommend taking a look at something like Java Native Access.
As far as tools go, they are wide and varied. I personally use Netbeans or Eclipse, but untimely that sort of choice comes down to what plugins you may need and what you personally prefer.
All in all, I would say program out a little stub of the application in different environments and different languages and see what you like. You really need to know the details of the application to make an informed decision, and it varies in most cases. Best of luck!
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 am just revisiting C++ and I'm already missing all the java libraries like hibernate and JAXB.
So why are there not a lot of open source libraries as there are in java?
Well, there are, but maybe not the same. That's maybe because C++ programmers have different needs from Java programmers. And sometimes similar libraries exist, but are named differently. There are plenty of XML parsers for C++ too, but of course they are not called Java Architecture for XML Binding.
There are lots of C++ open source libraries. Even only boost in enough, to be proud of being C++ programmer.
There is quite a lot of opensource C++ libraries.
Two examples that you mentioned, have a generic names - one is called ORM - object-relational mapping (of which hibernate is a decent Java example), and the other one is just an XML binder.
C++ tools I use for that purpose:
QxORM (http://www.qxorm.com), based on QtSQL, Boost and works marvellous
boost::serialize for XML serialization
As others have mentioned there are loads of libraries for C++ to do lots of different things but philosophically C (and to a lesser extent c++) are different to Java. The difference is that C (and C++) are a platform enabler. They enable you to program a platform without having to resort to low level assembly but at the same time they give you virtually full access to the said platform. This platform may be some low-level embedded device that does not have a filesystem or even a screen. This will require a very different set of APIs than a normal desktop machine.
It is for this reason that K&R C had NO libraries ISO C has minimal libraries; and it is only relatively recently that projects like Boost are trying to standardize some of the C++ libraries. And even so, some of these "standard" libraries may not be suitable for certain platforms (like kernel development)
Java, however IS the platform. It was written based on the concept of write once run everywhere. This was done by SUN to ensure that Windows x86 did not become the only platform out there. One could write software on Windows x86 and then run it on a SUN SPARC. This required total abstraction from the underlying which in itself requires extensive API support. So even basic J2SE has extensive library support and extensive specifications on how the platform should behave.
So see C and C++ as a platform enabler and Java as a platform.
boost is the equivalent of the java libraries, with lots of different things in it. I don't like the usability of C++ libraries quite as much sometimes, but then, they are way more efficient and you don't get code bloat like you do in java (just running a program a few lines long means loading that 20Mb rt.jar).
Oddly, apache has the leading XML parser, and it has it in both java and C++
The disadvantage of C++ is that there is no single, consistent feel to the libraries like in Java. The disadvantage of Java is jar bloat (admittedly fixable with GenJar if you want to do it manually).
I would say that it's Java that is missing the code. Where is the OpenGL kind of libraries? They exist (JOGL), but they don't stay current with OpenGL, and since you have to get them yourself, that means you can't deploy without requiring the end user to get them as well.
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.
Which language is faster for web, Java or PHP?
It is a difficult one to answer as in theory Java should be faster:
it's precompiled, any trivial algorithim will run faster in Java than PHP and there has been a vast amount of work done to optimise Java from improving the code, standard libraries, to JIT compilers, etc.
PHP is loaded and interpreted every time if you're not using the Zend optimiser, objects are intialised on every execution, even the most trivial string varaible is actually a complex object with many methods to support.
The problem is that in practice PHP sites seem to run faster using fewer resources.
I think this is because PHP developers take a more straightforward approach to design and don't get lost trying to implement exotic design patterns and implementing endless pointless abstractions.
Speed doesn't matter
in most cases.
Processing is cheap. Code in what you're comfortable with. Writing proper code goes much further for speed then choosing a language. Solid coding conventions and design plan will also help more.
Best answer I could find
"stuff to consider:
Java web applications are compiled
to bytecode. Even JSPs, which are
compiled at runtime. This is an
advantage over most uses of PHP,
where the Zend Optimizer is not in
use.
Data can be cached in a live servlet
instance - no direct/easy way of
doing this in PHP to my knowledge
(there is only ever a single
instance of a servlet/JSP in memory)
If anybody knows how to cache data in PHP without resorting to ugly
hacks, please enlighten me!
Java applications tend to be
n-tiered, which generally results in
a more maintainable application at a
slight performance penalty. This
probably sounds trollish, but
honestly: even within Java itself
direct use of JDBC will always be
faster than going through three
layers of objects to the database.
But is an n-tiered Java application able to hit the database sooner than an uncompiled, hacked-up monolithic PHP script? I don't think there's an answer to that question.
All that said, I'm working on an n-tiered MVC framework for php 5 (it's called Pure (http://www.sf.net/projects/php-pure)), so my PHP applications are generally n-tiered too. I'll worry about speed when and if it becomes an issue. For now, it's definitely not an issue."
courtesy of krumms
Speed aside, I believe the performance of Java is better than PHP. But developing a project in PHP is faster.
Can't answer this question with one or the other unless you define what you want to measure the speed of.
Some things are much faster in PHP (in a native function for example), other things are much faster in Java.
The intent of each language is substantially different from the other, so if you're debating over which to use for a particular task, you should generally based the decision on that task (and how well suited each language is to it) rather than performance.
For raw performance of code written in the language (as opposed to simply calling code in the standard library), Java will probably run faster than PHP as an extremely general rule. If that matters, chances are that PHP just isn't very well suited to the task at hand.
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 looking for a java gui testing tool in which tests can be created by recording my gui actions (buttons pressed, windows closed, etc.)
A scripting mechanism for writing tests is not required.
It could be free or commercial, but cheap and great is better than expensive and great.
My application is a rich-client app written in Java SE 6.
Yoav
If it's a Swing app you could take a look at Marathon.
I concur with Kettelerij, Marathon's the way to go.
It's easy to integrate into external systems like Subversion & CruiseControl, becasue all the scripts are human readable (Jython) and not locked into some proprietary format that requires an export (like most of the commercial tools).
It is able to record scripts in your choice of Jython or JRuby, which are essentially python and ruby that give you access to Java API. Very easy to understand.
For advanced testers, you are able to identify which GUI component you want to select using not just their names, but instead a a unique subset of their properties, for example
click('{Text: OK Enabled: true}')
... finds a component whose getText() is "OK" and isEnabled() is "true". This makes the scripts highly dynamic and easier to maintain.
I used Jemmy some years ago. Now I'm mostly doing webapps, so my experience in this field may be somewhat old. :-)
A scripting mechanism for writing
tests is not required.
Yes, it is. Pure capture/replay simply does not work in practice, you always have to edit the resulting scripts. And you often end up spending so much time doing that in an inadequate environment that you save no time over a pure scripting solution tailored for efficient script writing.
I have been impressed with Quick Test Pro. It is pay software from HP, but it has been able to get at some software that most tools can't work with. It has some data features so that tests can be run multiple times with varying data inputs. It is scriptable through VB so most Tester/Developer people will be able to work with it. I have been using it lately to execute tests on many machines for use in performance testing.
Try QEngine will do the record and play back. Has scripting options also
jameleon is very useful for testing web based applications. It combines a number of frameworks providing great flexability to your approach contained in a single launch framework.
There is no capture for jameleon I think you may be confusing this with selenium capture and record. Jameleon is a pure scripting framework.
You also have IBM's Rational Functional Tester:
http://www-01.ibm.com/software/awdtools/tester/functional/
I used an older version to test .NET forms applications (it also works with java apps, windows native apps, web pages). It failed a lot of times, and the integration with .NET was not so great. I don't quite recommend it for that purpose.
However, it is known to work a better with Java apps (RFT itself is made in java, and Java apps were the original target I think), specially in its most recent versions.
It's a very expensive application though. Personally I wouldn't use it again, unless I didn't have another choice.