Sunday, July 12, 2009

Using java with C++?

Okay I am was just wondering if it would be possible to use java as the front end and C++ as the back end. Like use java for the GUI aspects of the application while using C++ to do any type of intense coding that may need to be done. Its a odd idea, but I only really am asking this cuz it seems to be you can develop GUI's faster in java then in C++... sooo yah, is it possible?

Using java with C++?
Its not an odd idea. Its a good idea.


Java provides JNI (Java Native Interface) for this sort of thing.


Check out:


http://java.sun.com/j2se/1.5.0/docs/guid...
Reply:give me break why wud you program GUI in java ... when it has been thrown away by all programmers ?





If you wanna earn your living forget core java focus on advance java concepts like jsp, servlets, EJB.
Reply:The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.





The most important benefit of the JNI is that it imposes no restrictions on the implementation of the underlying Java VM. Therefore, Java VM vendors can add support for the JNI without affecting other parts of the VM. Programmers can write one version of a native application or library and expect it to work with all Java VMs supporting the JNI.





This chapter covers the following topics:





Java Native Interface Overview


Background


Objectives


Java Native Interface Approach


Programming to the JNI


Changes in JDK 1.1.2


Java Native Interface Overview


While you can write applications entirely in Java, there are situations where Java alone does not meet the needs of your application. Programmers use the JNI to write Java native methods to handle those situations when an application cannot be written entirely in Java.





The following examples illustrate when you need to use Java native methods:





The standard Java class library does not support the platform-dependent features needed by the application.


You already have a library written in another language, and wish to make it accessible to Java code through the JNI.


You want to implement a small portion of time-critical code in a lower-level language such as assembly.


By programming through the JNI, you can use native methods to:





Create, inspect, and update Java objects (including arrays and strings).


Call Java methods.


Catch and throw exceptions.


Load classes and obtain class information.


Perform runtime type checking.


You can also use the JNI with the Invocation API to enable an arbitrary native application to embed the Java VM. This allows programmers to easily make their existing applications Java-enabled without having to link with the VM source code.


No comments:

Post a Comment