I want to integrate java compiler in my application but I don't have any idea how will I do that.
I want that user could compile and run code on my application.
If anyone can help me then please tell me from where I should start.
Starting Java 1.6, the standard JDK ships with an API to the compiler. Meaning, you can easily write a Java program that will compile other programs.
http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html
EDIT as per Aaron's comment: an application using the compiler API must be run using the full JDK. The JRE doesn't include the compiler API implementation.
A second alternative is to embed the Eclipse Java compiler into your code. The advantage of this is that your application doesn't need a SDK to run - just add this single JAR.
Details are documented here: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm
Note: Adding a compiler to an application creates an enormous security risk. It basically means anyone can start doing anything with your application. Things that spring to mind are:
Attacking other computers, people and sites
Looking at all the data on the computer on which the application is running
Analyzing the network the computer is in and attacking any other computer in the same network
Installing Trojans or viruses on the computer
I've been trying to use 0MQ in my Windows dev environment with Java but I'm having a very difficult experience. It appears there are many issues with PATHs being inconsistent and the Visual Studio command prompt uses a different version of Java than the command prompt where I run my application. The inconsistencies don't stop there, and I feel like I'm not approaching this correctly.
So instead of trying to patch this process, has anyone successfully used ZeroMQ on Windows 7 64-bit and what steps and software stack did you use so that you can run a Java application locally?
Thanks for the help!
I've used zmq with F# on Win7/64bit; it's very easy to make it work there.
As for the Java side of things, I found this documentation: http://www.zeromq.org/bindings:java
and
https://github.com/zeromq/jzmq which is the official binding.
I have studied Java Web Start and found it complex and clumsy for my purposes. In addition, my app needs to access the PC resources, which causes more hoops to be jumped through with Java Web Start. To add to the difficulties I need to access a 32-bit native library (libvlc) so I need to insure that my app runs under 32-bit Java. Is there an easy way to deploy my app without resorting to Java Web Start? Needless to say, I want everything to be contained in a single .exe file.
I would start by searching the Internet for keywords such as "java 2 exe" and "jar to exe", etc. Doing so yields many freely available software packages that convert Java programs into Windows executables, for example:
JexePack - http://www.duckware.com/jexepack/index.html
JarToExe - http://www.regexlab.com/en/jar2exe/
JSmooth - http://jsmooth.sourceforge.net/
And the list goes on. Perhaps one of them meets your needs?
I am answering my own question to help people understand how to do this, which has taken me some number of days to figure out.
My initial problem was that my app would run on some versions of Windows but on others it was having problems finding the libvlc native library. I finally figured out that my app must run with 32-bit Java in order to use the 32-bit native library. Thus, the problem then became how to insure that the user started my app with 32-bit Java.
I read about Jar2Exe (http://www.regexlab.com/en/jar2exe/) in another post and decided to check it out. It is a great little program that is very configurable so I figured that it must be able to handle my 32-bit Java problem. In fact, it does so without even needing to do any configuration. The resulting .exe file contains my app along with all the required jar files and starts up with the 32-bit Java. I am very pleased with this program and plan to buy a license, which is very cheap.
Hope this saves time for other people who are trying to solve a similar problem.
I want to develop a cross platform application.
Is Java cross platform? I mean, can I develop a Java application in Windows and use it in Mac OS X and Linux?
If yes, how?
I find application written in Java, has two setup file one for Windows and other for Mac. This confuses me.
Any illustration or suggestion will be highly appreciated.
Is Java a cross platform?
Java is cross platform in the sense that a compiled Java program runs on all platforms for which there exists a JVM. (This holds for all major operating systems, including Windows, Mac OS and Linux.)
I mean I can develop Java application in windows and use it in mac and Linux?
Yes, this is possible.
This (and the security aspect) is one of the main advantages of running the programs in a virtual machine.
If yes how?
Write your application in Java (In .java files)
Compile your application using Eclipse or javac (into .class files)
(Optionally) Bundle your .class files in an executable (.jar file)
The very same .jar file can be distributed and executed on Windows systems, Mac systems, etc.
I find application written in Java, has two setup file one for windows and other for mac. This confuses me.
This is because some applications rely on platform-specific features. They are then bundled with different platform-specific libraries.
Unless you're developing an application that itself relies on platform-specific features, (such as for instance low-level system calls), you should be able to do just fine with ordinary Java.
Important comment by #Peter Lawrey:
It can be while the application is platform independent, the setup program is not. e.g. IntelliJ has three platform specific installers which are not written in Java, but have a zip which you can just unzip on any platform and it will work.
You can run Java applications on every device that has a JVM. If it does not, you're out of luck.
The comment from Oded is important. C and C++ have compilers on lots of devices.
Java byte code won't need to be recompiled when you switch platforms.
C and C++ will require that the developer recompile the application before distributing it to the target system, but once that's done clients will be able to run without an issue.
The problem of platform-specific customizations and settings has to be dealt with no matter which language you choose. The more your application depends on platform-specific features, the less portable it will be.
UPDATE:
Let's revisit the original words in the question:
I want to develop a cross platform application.
Here's the objective - a direct quote. No details about web, mobile, or desktop app.
Is Java cross platform? I mean, can I
develop a Java application in Windows
and use it in Mac OS X and Linux?
Define "cross platform". Sounds like the bias here is "byte code portability". C/C++ can't do that, but "source code portability" is certainly possible as long as you stick to ANSI C/C++ and refrain from using vendor extensions.
Java's claim to fame from the beginning has always been byte code portability. That's what the JVM gets you. That does not mean your whole application will be portable, because you might not have managed other dependencies well.
If I substitute "C/C++" for "Java in that bloc, then cross platform means something different. I cannot pick up a .exe or .so compiled for one platform and expect to run it on another, but if I create an .exe or .so for each platform and make them available it's certainly possible to make the same source code runnable on multiple platforms.
If yes, how?
If you have packaged your Java app as a JAR, you can put that on any platform you like.
If you have multiple C/C++ .exes for the platforms you're interested in, you can certainly run it when you need to.
There is an important caveat with regard to Java portability. "Business logic" (non-UI stuff) is quite portable, but there are at least a half-dozen different (and incompatible) user interface paradigms for Java, so, eg, Java code written to run on an Android (even ignoring Android's incompatible JVM) won't run on a Nokia phone, and code for either one will not run on a desktop PC.
But there's no other language that does better, to my knowledge.
Yes, Java written and compiled on one OS can run on another OS. There are JVMs available for many modern operating systems.
Java apps are packaged as .jar files. These can run on any operating system that implements the correct Java Runtime Environment for the application, provided the user has installed that JRE (JREs are provided to users for free).
The precise procedure for running the app is different for each operating system.
The Java Development Kit provides libraries that allow system functions (e.g. file operations, user interfaces) to be invoked that ought to work on any OS. However the precise behavior may vary (in a similar way to how a website can look different in different browsers). Also, Java apps may have a 'look and feel' that does not precisely match the look and feel of applications designed specifically for that OS.
It depends what you mean by "cross-platform". Java code can be compiled to byte-code binary class or jar files on any OS supporting the JDK and run on any platform supported the JRE. However, most compiled languages can be compiled on any platform provided the designers has catered for it. Java is more easily portable than, say, C++, but that doesn't mean C++ code won't be able to compile on any platform.
In other words - don't choose your language on this single feature alone. Choosing the best language for your application would be a better way of going about it. Perhaps a scripting language would be best for you. Maybe post another question asking what language to use to solve your specific problem.
I wrote a little game in Java with sound.
I've used standard library (AudioInputStream and Clip classes).
The program works very good with Windows XP, BUT I haven't got the sounds with Windows Seven or Linux Ubuntu.
Java 6 was installed for all those OS, and I've compiled the program with the standard compiler JAVAC.
So Java is not so "cross platform".
JAVA is not really cross-platform because is just a design, some JAVA implementations can be cross-platform but it really depends on the JAVA implementer.
SUN/Oracle makes the JAVA standard implementation for Windows, MAC and Linux and if you build programs with their JDK you should run the programs with their JRE, if you try to run it with other JRE there might be compatibility issues.
This can be seen more in the mobile, some phone makers won't make a full implementation of JAVA because hardware limitations or because they want to control the device's software, they carry the JAVA logo but you must use their own JDK and those programs could not run outside of their JVM implementation.
Another issue with JAVA is that some functionality could be deprecated and what ran in some specific version of the JRE could not run in newer versions or run in a different way.
The big problem is when we are talking about mobile apps. For desktops OS, java can run perfectly, but for mobile devices, developers can, practically, only create for Android. There are tools like Totalcross that helps java developers to create apps to iOS and Android. The focus is maintain the WORA assumption to every platform, even mobile.
Basically the subject says it all: We have a couple of components running on Java 5, they're talking to each other via RMI. Should we expect any problems, if we move some of them to Java6? By moving I mean compiling them with -source/target 1.6 and running on a java6 vm.
Nope, you shouldn't expect any problems with that. But anyway take a look to the Release notes for RMI in java 6
Good luck!
We have successfully pulled in Java 5 serialized objects into Java 6 objects so there should be no limitation on the serialization front.
You should also be able to switch between 32bit and 64bit Java as well without issues.