Will Java compiled in windows work in Linux?
Linux users often run java programs with gcj instead of java. Check that you use a correct executable.
How do I write Java code in Windows and compile and run in Linux
You should use Eclipse for Development IDE and add dependent jars as relative not full directory link. You can compile on Windows and run on Linux. It does not matter.
Is the Java compiler the same that is on Linux/Windows?
One of the central ideas of Java is write once, run anywhere - in other words, you only have to write and compile the code once, and then it will run on any platform that has a JVM installed (with the correct version). So, you do not need to recompile your code at all for the Mac or for any other operating system.
Java compiles to bytecode instead of native machine code. The Java virtual machine interprets and executes that bytecode, and translates it to native machine code using a just-in-time compiler to make it run fast.
It doesn't matter that your program uses Swing - that by itself doesn't mean that it wouldn't work on a Mac.
The only reason why it wouldn't work is if you've used hard-coded operating system specific things in your code, like hardcoding Windows paths such as C:\Program Files
etc. - those things ofcourse don't exist on Mac OS X or other operating systems than Windows.
Java, Mac OS, Windows and Linux
After doing some digging for the methods giving you problems, it's clear you're not running the same JDK on every platform. Specifically, your Windows and Linux boxes are running JDK 1.7, and your Mac OS X box is running JDK 1.6 or older. See this question for using JDK 1.7 on Mac.
The fact remains that you don't need to compile your application on every platform. Java is a "compile once, run everywhere" language. The bytecode produced by the compiler works for every platform, regardless of which platform compiled it, so long as you didn't introduce any system dependencies in the code yourself.
In other words, Java itself is platform-agnostic as long as your code is platform-agnostic. Your problem is just a JDK version error, so upgrading your Mac's version of the JDK to 1.7 will fix this.
Note that you can't run binaries compiled with a 1.7 source target in Java 6 or lower. You can change the source target to 1.6 on compile time, but this will preclude you from using the Java 7 API (such as the getSelectedValuesList
method).
Why do you have to write separate Programs for Windows & Linux
Technically you are wrong.
Java does not run on Linux. It also does not run on Windows. It does not run on Mac either, nor any other Unix like operating system. For that matter, it does not run on any operating system.
It runs directly on the machine. It only works on one type of machine - the Java Virtual Machine. Fortunately, the Java Virtual Machine has been virtualized onto Linux, Windows, Mac, etc.
Is Java cross platform?
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.
Related Topics
Caputre Opengl Window in X11 with Fast Framerate - Possible
How to Fetch The Logical Name of a Nic Card Given The Ip Address Associated with It
How Does Os Chooses The Next Process to Be Run in Cpu
Building /Lib/Modules/$(Uname -R)/Build While Compiling a Kernel
Linux - Mapping User Space Memory in Kernel Code
How to Rename a Bunch of Files to Eliminate Quote Marks
Pte Structure in The Linux Kernel
Incorrect Rendering in Anaconda + Spyder (Wrong Colours in Text)
Curl Http Post File Upload Using Curl -Data in Linux Command Line
How to Highlight The Differences Between Subsequent Lines in a File
How to Use/Learn Video4Linux2 (On Screen Display) Output APIs
How to Add a Custom System Call on X86 Ubuntu Linux
How to Connect to Sftp Using Linux Command from Perl
How to Install Packages in Tcl
Socket Send Concurrency Guarantees
The Only Overhead Incurred by Fork Is Page Table Duplication and Process Id Creation