Create a program that is usable on Windows

Asked

Viewed 97 times

-1

I am a programming student, still in the first year of my course. So far I have studied Java, C, Haskell and Script Shell. I’m quite functional in Java and C.

I can write code, compile and exceed in a terminal Linux, but let’s imagine that I want to create an application that runs on Windows. I write my code - in Java, for example - creating a simple calculator.

Once you have the code, how do I create an application that can be run on Windows, a so-called "program"?

If it’s too complex a process for my skill level, just say so, please.

Thanks in advance to those who try to help me :)

  • 2

    Just double-click the . jar?

2 answers

3

Programs created in the Java language run on the Java Virtual machine, so they are not stand-alone, they depend on the user having Javavm installed, it is impossible to run a program written in Java without this.

Compiling a program in C, C++, etc, will be compiled based on the compiler used, there is no way to run on Windows something that has been compiled for Linux, just as there is no way to run something that has been compiled for Mac OS X V10.1 rotate in the Mac OS X V10.13, due to the architecture used by both operating systems.

Compiling on Windows usually has compatibility between Windows family systems, but depends a lot on the compiler that uses the Apis used to write the code.

So to summarize, if it is Java will run on several systems since you have Javavm installed, if it is C you will have to compile in architecture by architecture you want to run the program.

Linux is generally not compatible between different Linux distros, so some applications are usually distributed in sources and you have to compile with GCC (or other compiler that the distro and/or repositories have), of course there are no guarantees of functioning, it will depend on who wrote the code.

  • In fact, I’ve seen some programs in Java that are stand-alone when using the following trick: They have a unique entire JVM embedded within them. This approach is quite unusual and I would only recommend for very specific cases, but there is yes.

  • 1

    @Victorstafuses all programs that promise to make their program Node.js, Python and Java make use of this. The point is that Javavm has to be architecture-compatible, so this cannot be considered, because a javavm for windows will not work under linux and probably the executable generator copies the Javavm from the machine where it was generated, unless there is a very good program that creates a stand-alone with the javavms for the most popular systems, which will probably make a simple program weigh horrors.

2


Based on a very simple example: create a calculator. Once you have the code, how do I create an application that can be run on Windows, a so-called "program"?

Assuming you are in Windows and your calculator classes are located in a folder src, being the class com.example.Calculadora the main class, you can do this to compile your program into a file calculadora.jar (assuming your JDK is correctly installed):

cd src
dir /s /B *.java > ../sources.txt
cd ..
javac -encoding utf8 -d bin @sources.txt
jar -cfe calculadora.jar com.example.Calculadora -C bin .

If you want to compile in Unix/linux, even if you then go (or not) to use the JAR produced in windows, you can do so (changing only the second line):

cd src
find -name "*.java" > ../sources.txt
cd ..
javac -encoding utf8 -d bin @sources.txt
jar -cfe calculadora.jar com.example.Calculadora -C bin .

To run it in an environment (Unix/linux or windows) where there is a correctly installed compatible JVM, you can double click the file calculadora.jar or else do it:

java -jar calculadora.jar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.